[refactor] created a new types header, seperated the structs from the lib.c
This commit is contained in:
parent
0ffd6627ed
commit
e0a44b9c2b
32
source/lib.c
32
source/lib.c
@ -6,37 +6,13 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
#define MAXC 1024
|
#define MAXC 1024
|
||||||
#define MAXC_CHAR 256
|
#define MAXC_CHAR 256
|
||||||
#define CONVERT_BYTES_TO_GIGABYTES 107374182
|
#define CONVERT_BYTES_TO_GIGABYTES 107374182
|
||||||
#define D 1073741824
|
#define D 1073741824
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
|
|
||||||
int frequency;
|
|
||||||
int temperature;
|
|
||||||
char* name;
|
|
||||||
int threads;
|
|
||||||
|
|
||||||
} cpu_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
unsigned long total;
|
|
||||||
unsigned long available;
|
|
||||||
} ram_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
long long size;
|
|
||||||
short name;
|
|
||||||
} disk_s;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char* name;
|
|
||||||
char* hostname;
|
|
||||||
char* os_version;
|
|
||||||
} device_s;
|
|
||||||
|
|
||||||
void cpu_name();
|
void cpu_name();
|
||||||
void cpu_threads();
|
void cpu_threads();
|
||||||
void cpu_temperature();
|
void cpu_temperature();
|
||||||
@ -254,6 +230,12 @@ void cpu_frequency(){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cpu_temperature(cpu_s cpu)
|
||||||
|
{
|
||||||
|
cpu.temperature = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void mem_size() {
|
void mem_size() {
|
||||||
int64_t size;
|
int64_t size;
|
||||||
size_t len = sizeof(size);
|
size_t len = sizeof(size);
|
||||||
|
|||||||
16
source/lib.h
16
source/lib.h
@ -3,19 +3,23 @@
|
|||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|
||||||
void get_device_info();
|
|
||||||
void disk_size();
|
|
||||||
void size();
|
|
||||||
void av_size();
|
|
||||||
void ram_info();
|
|
||||||
void cpu_frequency();
|
|
||||||
void cpu_name();
|
void cpu_name();
|
||||||
void cpu_threads();
|
void cpu_threads();
|
||||||
void cpu_temperature();
|
void cpu_temperature();
|
||||||
void cpu_frequency();
|
void cpu_frequency();
|
||||||
|
|
||||||
|
void disk_size();
|
||||||
|
void size();
|
||||||
|
|
||||||
|
void av_size();
|
||||||
|
void ram_info();
|
||||||
|
|
||||||
void mem_size();
|
void mem_size();
|
||||||
void mem_av_size();
|
void mem_av_size();
|
||||||
|
|
||||||
|
void get_device_info();
|
||||||
|
void get_os_version();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -9,9 +9,10 @@ void *gather_cpu_information();
|
|||||||
void *gather_ram_information();
|
void *gather_ram_information();
|
||||||
void *gather_disk_information();
|
void *gather_disk_information();
|
||||||
void *gather_device_information();
|
void *gather_device_information();
|
||||||
|
void get_c_version();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
cJSON convert_to_json() {
|
cJSON convert_to_json() {
|
||||||
|
|
||||||
cJSON *root = cJSON_CreateObject();
|
cJSON *root = cJSON_CreateObject();
|
||||||
cJSON_AddStringToObject(root, "cpu", info.cpu->name);
|
cJSON_AddStringToObject(root, "cpu", info.cpu->name);
|
||||||
@ -20,9 +21,9 @@ cJSON convert_to_json() {
|
|||||||
cJSON_AddStringToObject(root, "device", info.device->name);
|
cJSON_AddStringToObject(root, "device", info.device->name);
|
||||||
|
|
||||||
return *root;
|
return *root;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler(char *url) {
|
void handler(char *url) {
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
|
|
||||||
@ -33,28 +34,25 @@ void handler(char *url) {
|
|||||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||||
|
|
||||||
// TO DO
|
// TO DO
|
||||||
// parse the object to a json and pass that as an argument to post it
|
// parse the object to a json and pass that as an argument to post it
|
||||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
|
||||||
|
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
if (res != CURLE_OK)
|
if (res != CURLE_OK)
|
||||||
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
||||||
curl_easy_strerror(res));
|
curl_easy_strerror(res));
|
||||||
|
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
}
|
}
|
||||||
curl_global_cleanup();
|
curl_global_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void get_c_version()
|
||||||
|
{
|
||||||
#ifdef __APPLE__
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
|
||||||
|
|
||||||
#if __STDC_VERSION__
|
#if __STDC_VERSION__
|
||||||
printf("C standard version: %ld\n", __STDC_VERSION__);
|
printf("C standard version: %ld\n", __STDC_VERSION__);
|
||||||
@ -62,7 +60,12 @@ int main(int argc, char** argv) {
|
|||||||
printf("C standard not defined\n");
|
printf("C standard not defined\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// handler("api.nsrddyn.com");
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -75,6 +78,7 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
29
source/types.h
Normal file
29
source/types.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef TYPES_H
|
||||||
|
#define TYPES_H
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
|
||||||
|
char* name;
|
||||||
|
int frequency;
|
||||||
|
int temperature;
|
||||||
|
int threads;
|
||||||
|
|
||||||
|
} cpu_s;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned long total;
|
||||||
|
unsigned long available;
|
||||||
|
} ram_s;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
long long size;
|
||||||
|
short name;
|
||||||
|
} disk_s;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char* name;
|
||||||
|
char* hostname;
|
||||||
|
char* os_version;
|
||||||
|
} device_s;
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user