diff --git a/source/linux/device.c b/source/linux/device.c deleted file mode 100644 index e69de29..0000000 diff --git a/source/linux/disk.c b/source/linux/disk.c deleted file mode 100644 index 9093717..0000000 --- a/source/linux/disk.c +++ /dev/null @@ -1,4 +0,0 @@ -#include -#include - - diff --git a/source/linux/info.c b/source/linux/info.c deleted file mode 100644 index e69de29..0000000 diff --git a/source/linux/cpu.c b/source/linux/lib.c similarity index 72% rename from source/linux/cpu.c rename to source/linux/lib.c index c20ffe1..9c1e3ab 100644 --- a/source/linux/cpu.c +++ b/source/linux/lib.c @@ -112,4 +112,62 @@ void *cpu_i(void *a){ return(NULL); } +#endif +#ifdef __gnu_linux__ + +#include +#include +#include +#include +#include +#include + + +typedef struct +{ + unsigned long mem_size; +} ram; + +unsigned long get_total(void); +unsigned long get_usage(void); +void *ram_i(void *a); + + +unsigned long get_total(void){ + + struct sysinfo info; + + if (sysinfo(&info) != 0) { + perror("sysinfo"); + return 1; + } + + long total_ram = info.totalram * info.mem_unit; + return total_ram; + +} + +unsigned long get_usage(void) +{ + struct sysinfo info; + + if (sysinfo(&info) != 0) { + perror("sysinfo"); + return 1; + } + + long total_ram = info.totalram * info.mem_unit; + long free_ram = info.freeram * info.mem_unit; + + return total_ram - free_ram; + } + +void *ram_i(void *a){ + + printf("thread is working"); + return NULL; +} + + + #endif diff --git a/source/linux/ram.c b/source/linux/ram.c deleted file mode 100644 index 76bb4a1..0000000 --- a/source/linux/ram.c +++ /dev/null @@ -1,58 +0,0 @@ -#ifdef __gnu_linux__ - -#include -#include -#include -#include -#include -#include - - -typedef struct -{ - unsigned long mem_size; -} ram; - -unsigned long get_total(void); -unsigned long get_usage(void); -void *ram_i(void *a); - - -unsigned long get_total(void){ - - struct sysinfo info; - - if (sysinfo(&info) != 0) { - perror("sysinfo"); - return 1; - } - - long total_ram = info.totalram * info.mem_unit; - return total_ram; - -} - -unsigned long get_usage(void) -{ - struct sysinfo info; - - if (sysinfo(&info) != 0) { - perror("sysinfo"); - return 1; - } - - long total_ram = info.totalram * info.mem_unit; - long free_ram = info.freeram * info.mem_unit; - - return total_ram - free_ram; - } - -void *ram_i(void *a){ - - printf("thread is working"); - return NULL; -} - - - -#endif diff --git a/source/osx/cpu.c b/source/osx/cpu.c deleted file mode 100644 index bf61c38..0000000 --- a/source/osx/cpu.c +++ /dev/null @@ -1,59 +0,0 @@ -#ifdef __APPLE__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "cpu.h" - -void* cpu_name(); -void* cpu_thread_count(); - -cpu_s cpu; - -void* cpu_name(){ - - char *name; - size_t len = 0; - - if (sysctlbyname("machdep.cpu.brand_string", NULL, &len, NULL, 0) < 0) - perror("errorn in assigning the size for the cpu name variable\n"); - - name = malloc(len); - - if(sysctlbyname("machdep.cpu.brand_string", name, &len, NULL, 0) < 0){ - perror("error in assigning the value to the cpu name variable\n"); - - free(name); - return NULL; - } - - cpu.name = name; - return NULL; -} - -void* cpu_threads(){ - - int count; - size_t len = sizeof(count); - if (sysctlbyname("machdep.cpu.thread_count", &count, &len, NULL, 0) < 0) - perror("error in retrieving the cpu threads count\n"); - - cpu.threads = count; - return NULL; -} - -void* cpu_info(){ - cpu_threads(); - cpu_name(); - - printf("cpu name: %s\ncpu threads: %d\n", cpu.name, cpu.threads); - return NULL; -} - -#endif diff --git a/source/osx/device.c b/source/osx/device.c deleted file mode 100644 index 5a94b01..0000000 --- a/source/osx/device.c +++ /dev/null @@ -1,89 +0,0 @@ -#ifdef __APPLE__ - -#include -#include -#include -#include -#include - -device_s device_info; - -void* device_name(){ - - char *name; - size_t size = 0; - - if (sysctlbyname("kern.hostname", NULL, &size, NULL, 0) < 0) - perror("failed retrieving the hostname: \n"); - - name = malloc(size); - - if(sysctlbyname("kern.hostname", name, &size, NULL, 0) < 0){ - perror("failed retrieving the hostname: \n"); - free(name); - return NULL; - } - - device_info.name = name; - return NULL; -} - - -void* device_model(){ - - char *model_name; - size_t size = 0; - - if (sysctlbyname("hw.model", NULL, &size, NULL, 0) < 0) - perror("failed retrieving the hostname: \n"); - - model_name = malloc(size); - - if(sysctlbyname("hw.model", model_name, &size, NULL, 0) < 0){ - perror("failed retrieving the hostname: \n"); - free(model_name); - return NULL; - } - - device_info.model = model_name; - return NULL; - -} - -void* device_up_time(){ - - - - return NULL; -} - -void* device_os_version(){ - - char *os_version; - size_t size = 0; - - if (sysctlbyname("kern.ostype", NULL, &size, NULL, 0) < 0) - perror("failed retrieving the hostname: \n"); - - os_version = malloc(size); - - if(sysctlbyname("kern.ostype", os_version, &size, NULL, 0) < 0){ - perror("failed retrieving the os version: \n"); - free(os_version); - return NULL; - } - - device_info.model = os_version; - return NULL; - - -} - -void* get_device_info(){ - device_name(); - device_model(); - printf("device name: %s\ndevice model: %s\n", device_info.name, device_info.model); - return NULL; -} - -#endif diff --git a/source/osx/disk.c b/source/osx/disk.c deleted file mode 100644 index 12ab056..0000000 --- a/source/osx/disk.c +++ /dev/null @@ -1,30 +0,0 @@ -#ifdef __APPLE__ - -#include -#include -#include -#include "disk.h" - - -void* disk_size(); - -disk_s disk_info; - -void* disk_size(){ - - struct statfs disk; - - statfs("/", &disk); - - disk_info.size = disk.f_bfree; - return NULL; -} - -void* get_disk_info(){ - - printf("free disk space: %llu\n", disk_info.size); - - return NULL; -} - -#endif diff --git a/source/osx/info.c b/source/osx/info.c deleted file mode 100644 index b6d3ad6..0000000 --- a/source/osx/info.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include "modules/cpu.h" -#include "modules/ram.h" -#include "modules/disk.h" -#include "modules/device.h" -#include - -typedef struct { - - cpu_s* cpu; - ram_s* ram; - disk_s* disk; - device_s* device; - -} info; - - -cJSON convert_to_json(info info){ - - cJSON *root = cJSON_CreateObject(); - cJSON_AddStringToObject(root, "cpu", info.cpu->name); - cJSON_AddNumberToObject(root, "ram", info.ram->total); - cJSON_AddStringToObject(root, "disk", info.disk->name); - cJSON_AddStringToObject(root, "device", info.device->name); - - return *root; -} diff --git a/source/osx/lib.c b/source/osx/lib.c new file mode 100644 index 0000000..d083a04 --- /dev/null +++ b/source/osx/lib.c @@ -0,0 +1,238 @@ + +#ifdef __APPLE__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "cpu.h" + +void* cpu_name(); +void* cpu_thread_count(); + +cpu_s cpu; + +void* cpu_name(){ + + char *name; + size_t len = 0; + + if (sysctlbyname("machdep.cpu.brand_string", NULL, &len, NULL, 0) < 0) + perror("errorn in assigning the size for the cpu name variable\n"); + + name = malloc(len); + + if(sysctlbyname("machdep.cpu.brand_string", name, &len, NULL, 0) < 0){ + perror("error in assigning the value to the cpu name variable\n"); + + free(name); + return NULL; + } + + cpu.name = name; + return NULL; +} + +void* cpu_threads(){ + + int count; + size_t len = sizeof(count); + if (sysctlbyname("machdep.cpu.thread_count", &count, &len, NULL, 0) < 0) + perror("error in retrieving the cpu threads count\n"); + + cpu.threads = count; + return NULL; +} + +void* cpu_info(){ + cpu_threads(); + cpu_name(); + + printf("cpu name: %s\ncpu threads: %d\n", cpu.name, cpu.threads); + return NULL; +} + +#endif + +#ifdef __APPLE__ + +#include +#include +#include +#include +#include + +device_s device_info; + +void* device_name(){ + + char *name; + size_t size = 0; + + if (sysctlbyname("kern.hostname", NULL, &size, NULL, 0) < 0) + perror("failed retrieving the hostname: \n"); + + name = malloc(size); + + if(sysctlbyname("kern.hostname", name, &size, NULL, 0) < 0){ + perror("failed retrieving the hostname: \n"); + free(name); + return NULL; + } + + device_info.name = name; + return NULL; +} + + +void* device_model(){ + + char *model_name; + size_t size = 0; + + if (sysctlbyname("hw.model", NULL, &size, NULL, 0) < 0) + perror("failed retrieving the hostname: \n"); + + model_name = malloc(size); + + if(sysctlbyname("hw.model", model_name, &size, NULL, 0) < 0){ + perror("failed retrieving the hostname: \n"); + free(model_name); + return NULL; + } + + device_info.model = model_name; + return NULL; + +} + +void* device_up_time(){ + + + + return NULL; +} + +void* device_os_version(){ + + char *os_version; + size_t size = 0; + + if (sysctlbyname("kern.ostype", NULL, &size, NULL, 0) < 0) + perror("failed retrieving the hostname: \n"); + + os_version = malloc(size); + + if(sysctlbyname("kern.ostype", os_version, &size, NULL, 0) < 0){ + perror("failed retrieving the os version: \n"); + free(os_version); + return NULL; + } + + device_info.model = os_version; + return NULL; + + +} + +void* get_device_info(){ + device_name(); + device_model(); + printf("device name: %s\ndevice model: %s\n", device_info.name, device_info.model); + return NULL; +} + +#endif + + +#include +#include "modules/cpu.h" +#include "modules/ram.h" +#include "modules/disk.h" +#include "modules/device.h" +#include + +typedef struct { + + cpu_s* cpu; + ram_s* ram; + disk_s* disk; + device_s* device; + +} info; + + +cJSON convert_to_json(info info){ + + cJSON *root = cJSON_CreateObject(); + cJSON_AddStringToObject(root, "cpu", info.cpu->name); + cJSON_AddNumberToObject(root, "ram", info.ram->total); + cJSON_AddStringToObject(root, "disk", info.disk->name); + cJSON_AddStringToObject(root, "device", info.device->name); + + return *root; +} + + +#ifdef __APPLE__ + +#include +#include +#include "ram.h" +#include +#include +#include +#include + +void size(); +void av_size(); +void* ram_i(); + + +ram_s data; + +#define D 1073741824 + + +void size() { + int64_t size; + size_t len = sizeof(size); + if (sysctlbyname("hw.memsize", &size, &len, NULL, 0) < 0) + perror("error in retrieving the memory size"); + + data.total = size / D; + return NULL; +} + +void av_size() { + int64_t size; + size_t len = sizeof(size); + if (sysctlbyname("hw.memsize_usable", &size, &len, NULL, 0) < 0) + perror("error in retrieving the available memory size"); + + data.available = size / D; + return NULL; +} + +void ram_info() { + size(); + av_size(); + + printf("available ram: %LF\n", data.available); + printf("total ram: %LF\n", data.total); + + return NULL; +} + +void* ram_i(){ + + printf("thread is working"); + return NULL; +} + +#endif diff --git a/source/osx/ram.c b/source/osx/ram.c deleted file mode 100644 index 70caae1..0000000 --- a/source/osx/ram.c +++ /dev/null @@ -1,57 +0,0 @@ -#ifdef __APPLE__ - -#include -#include -#include "ram.h" -#include -#include -#include -#include - -void size(); -void av_size(); -void* ram_i(); - - -ram_s data; - -#define D 1073741824 - - -void size() { - int64_t size; - size_t len = sizeof(size); - if (sysctlbyname("hw.memsize", &size, &len, NULL, 0) < 0) - perror("error in retrieving the memory size"); - - data.total = size / D; - return NULL; -} - -void av_size() { - int64_t size; - size_t len = sizeof(size); - if (sysctlbyname("hw.memsize_usable", &size, &len, NULL, 0) < 0) - perror("error in retrieving the available memory size"); - - data.available = size / D; - return NULL; -} - -void ram_info() { - size(); - av_size(); - - printf("available ram: %LF\n", data.available); - printf("total ram: %LF\n", data.total); - - return NULL; -} - -void* ram_i(){ - - printf("thread is working"); - return NULL; -} - -#endif