Compare commits
No commits in common. "a633e533a0f3b0a1fdceb10f1f7e30200209850c" and "123e2a77c81b0e3fcdc4e3b55bd35e3277e6ab23" have entirely different histories.
a633e533a0
...
123e2a77c8
@ -1,10 +1,14 @@
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.24)
|
||||
|
||||
SET(CMAKE_BUILD_TYPE Debug)
|
||||
SET(CMAKE_C_STANDARD 23)
|
||||
SET(CMAKE_C_STANDARD_REQUIRED TRUE)
|
||||
|
||||
PROJECT(synf-core)
|
||||
|
||||
ADD_EXECUTABLE(main source/main.c source/lib.c)
|
||||
ADD_EXECUTABLE(main
|
||||
|
||||
source/main.c
|
||||
source/lib.c
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(main PRIVATE source/lib/osx source/lib/linux)
|
||||
|
||||
201
source/lib.c
201
source/lib.c
@ -1,10 +1,4 @@
|
||||
/*
|
||||
*
|
||||
* Author: nasr
|
||||
* Year: 2025-2026
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lib.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
@ -12,40 +6,46 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include "types.h"
|
||||
#include "lib.h"
|
||||
|
||||
#define MAXC 1024
|
||||
#define MAXC_CHAR 256
|
||||
#define CONVERT_BYTES_TO_GIGABYTES 107374182
|
||||
#define D 1073741824
|
||||
|
||||
/*
|
||||
* prototype function declarations
|
||||
* cpu, ram, disk, device
|
||||
*
|
||||
*/
|
||||
|
||||
void cpu_name();
|
||||
void cpu_threads();
|
||||
void cpu_temperature();
|
||||
void cpu_frequency();
|
||||
|
||||
void get_total();
|
||||
void get_usage();
|
||||
|
||||
void mem_size();
|
||||
void av_mem_size();
|
||||
|
||||
void device_up_time();
|
||||
void device_os_version();
|
||||
void device_hostname();
|
||||
void device_model();
|
||||
|
||||
void init_device();
|
||||
|
||||
|
||||
#ifdef __gnu_linux__
|
||||
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
void init_device() {
|
||||
|
||||
void cpu_name() {
|
||||
device_s _device;
|
||||
|
||||
_device.&name = device_model();
|
||||
_device.&hostname =
|
||||
|
||||
}
|
||||
|
||||
void cpu_name(){
|
||||
int buffer_size = 256;
|
||||
char cpu_name[buffer_size];
|
||||
|
||||
@ -70,7 +70,7 @@ void cpu_name() {
|
||||
}
|
||||
}
|
||||
|
||||
u_cpu->name = cpu_name;
|
||||
_cpu.name = cpu_name;
|
||||
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ void cpu_frequency() {
|
||||
FILE *fp = fopen("/proc/cpuinfo", "r");
|
||||
if (!fp) {
|
||||
printf("can't open /proc/cpuinfo");
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (fgets(buffer, MAXC_CHAR, fp)) {
|
||||
@ -95,43 +95,57 @@ void cpu_frequency() {
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
u_cpu->frequency = buffer;
|
||||
return buffer;
|
||||
}
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void mem_size() {
|
||||
unsigned long get_total(){
|
||||
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
u_ram->total = total_ram;
|
||||
return total_ram;
|
||||
|
||||
}
|
||||
|
||||
void mem_size(){
|
||||
|
||||
void mem_av_size() {
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
return total_ram;
|
||||
|
||||
}
|
||||
|
||||
void av_mem_size()
|
||||
{
|
||||
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;
|
||||
|
||||
u_ram->available = free_ram;
|
||||
return total_ram - free_ram;
|
||||
}
|
||||
|
||||
|
||||
void cpu_temperature() {
|
||||
|
||||
int delay = 0;
|
||||
void cpu_temperature()
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
sleep(delay);
|
||||
@ -151,41 +165,27 @@ void cpu_temperature() {
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long get_usage()
|
||||
{
|
||||
struct sysinfo info;
|
||||
|
||||
void device_up_time() {
|
||||
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;
|
||||
}
|
||||
|
||||
unsigned long device_up_time(){
|
||||
struct sysinfo info;
|
||||
if (sysinfo(&info) == -1)
|
||||
perror("sysinfo");
|
||||
|
||||
u_device->uptime = info.uptime;
|
||||
}
|
||||
|
||||
|
||||
void device_model() {
|
||||
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void cpu_threads() {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void get_total() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
void get_usage() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
void device_os_version() {
|
||||
|
||||
|
||||
return info.uptime;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -196,52 +196,51 @@ void device_os_version() {
|
||||
|
||||
void cpu_name() {
|
||||
|
||||
char *name = NULL;
|
||||
char *name;
|
||||
size_t len = 0;
|
||||
|
||||
if (sysctlbyname("machdep.cpu.brand_string", NULL, &len, NULL, 0) < 0){
|
||||
|
||||
perror("error in assigning the size for the cpu name variable\n");
|
||||
return;
|
||||
}
|
||||
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 (name == NULL) {
|
||||
perror("malloc failed");
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
u_cpu->name = name;
|
||||
_cpu.name = name;
|
||||
return;
|
||||
}
|
||||
|
||||
void cpu_threads() {
|
||||
|
||||
int count;
|
||||
size_t len = sizeof(count);
|
||||
if (sysctlbyname("machdep.cpu.thread_count", &count, &len, NULL, 0) < 0){
|
||||
if (sysctlbyname("machdep.cpu.thread_count", &count, &len, NULL, 0) < 0)
|
||||
perror("error in retrieving the cpu threads count\n");
|
||||
return;
|
||||
|
||||
_cpu.threads = count;
|
||||
return;
|
||||
}
|
||||
|
||||
void cpu_frequency(){
|
||||
uint64_t freq = 0;
|
||||
size_t size = sizeof(freq);
|
||||
|
||||
if (sysctlbyname("hw.cpufrequency", &freq, &size, NULL, 0) < 0)
|
||||
{
|
||||
perror("sysctl");
|
||||
}
|
||||
|
||||
u_cpu->threads = count;
|
||||
return;
|
||||
}
|
||||
|
||||
void cpu_frequency() {
|
||||
// assigning a value of 0, value not available on macos
|
||||
u_cpu->frequency = 0;
|
||||
|
||||
}
|
||||
|
||||
void cpu_temperature() {
|
||||
// assigning a value of 0, value not available on macos
|
||||
u_cpu->temperature = 0;
|
||||
void cpu_temperature(cpu_s cpu)
|
||||
{
|
||||
cpu.temperature = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
void mem_size() {
|
||||
@ -250,7 +249,7 @@ void mem_size() {
|
||||
if (sysctlbyname("hw.memsize", &size, &len, NULL, 0) < 0)
|
||||
perror("error in retrieving the memory size");
|
||||
|
||||
u_ram->total = size / D;
|
||||
_ram.total = size / D;
|
||||
}
|
||||
|
||||
void mem_av_size() {
|
||||
@ -259,16 +258,7 @@ void mem_av_size() {
|
||||
if (sysctlbyname("hw.memsize_usable", &size, &len, NULL, 0) < 0)
|
||||
perror("error in retrieving the available memory size");
|
||||
|
||||
u_ram->available = size / D;
|
||||
}
|
||||
|
||||
void get_total() {
|
||||
|
||||
}
|
||||
|
||||
void get_usage() {
|
||||
|
||||
|
||||
_ram.available = size / D;
|
||||
}
|
||||
|
||||
void device_hostname(){
|
||||
@ -287,7 +277,7 @@ void device_hostname(){
|
||||
return ;
|
||||
}
|
||||
|
||||
u_device->name = name;
|
||||
_device.name = name;
|
||||
return ;
|
||||
}
|
||||
|
||||
@ -319,13 +309,14 @@ void device_model(){
|
||||
return;
|
||||
}
|
||||
|
||||
u_device->name = model_name;
|
||||
_device.name = model_name;
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void device_os_version() {
|
||||
|
||||
char *os_version = NULL;
|
||||
char *os_version;
|
||||
size_t size = 0;
|
||||
|
||||
if (sysctlbyname("kern.ostype", NULL, &size, NULL, 0) < 0)
|
||||
@ -339,7 +330,21 @@ void device_os_version() {
|
||||
return ;
|
||||
}
|
||||
|
||||
u_device->os_version = os_version;
|
||||
_device.os_version = os_version;
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void init_device() {
|
||||
|
||||
device_s _device;
|
||||
|
||||
_device.name = device_model();
|
||||
_device.hostname =
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
17
source/lib.h
17
source/lib.h
@ -1,16 +1,16 @@
|
||||
#ifndef LIB_H
|
||||
#define LIB_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
void cpu_name();
|
||||
void cpu_name(cpu_s cpu);
|
||||
void cpu_threads();
|
||||
void cpu_temperature();
|
||||
void cpu_frequency();
|
||||
|
||||
void get_total();
|
||||
void get_usage();
|
||||
void disk_size();
|
||||
void size();
|
||||
|
||||
void av_size();
|
||||
void ram_info();
|
||||
@ -18,10 +18,9 @@ void ram_info();
|
||||
void mem_size();
|
||||
void mem_av_size();
|
||||
|
||||
void device_os_version();
|
||||
void device_model();
|
||||
void device_up_time();
|
||||
void device_model();
|
||||
|
||||
void get_device_info();
|
||||
void get_os_version();
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
115
source/main.c
115
source/main.c
@ -1,68 +1,85 @@
|
||||
#include <pthread.h>
|
||||
#include <curl/curl.h>
|
||||
#include <cjson/cJSON.h>
|
||||
#include "lib.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "types.h"
|
||||
#include "lib.h"
|
||||
|
||||
cpu_s *u_cpu;
|
||||
ram_s *u_ram;
|
||||
disk_s *u_disk;
|
||||
device_s *u_device;
|
||||
void *gather_cpu_information();
|
||||
void *gather_ram_information();
|
||||
void *gather_disk_information();
|
||||
void *gather_device_information();
|
||||
void get_c_version();
|
||||
|
||||
void init() {
|
||||
/*
|
||||
cJSON convert_to_json() {
|
||||
|
||||
u_cpu = malloc( sizeof(cpu_s) );
|
||||
u_ram = malloc(sizeof(ram_s));
|
||||
u_disk = malloc(sizeof(disk_s));
|
||||
u_device = malloc(sizeof(device_s));
|
||||
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);
|
||||
|
||||
cpu_name();
|
||||
cpu_frequency();
|
||||
cpu_threads();
|
||||
cpu_temperature();
|
||||
return *root;
|
||||
}
|
||||
|
||||
mem_size();
|
||||
mem_av_size();
|
||||
void handler(char *url) {
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
get_total();
|
||||
get_usage();
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = curl_easy_init();
|
||||
|
||||
if (curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
|
||||
// TO DO
|
||||
// parse the object to a json and pass that as an argument to post it
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
if (res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
||||
curl_easy_strerror(res));
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
void get_c_version()
|
||||
{
|
||||
|
||||
#if __STDC_VERSION__
|
||||
printf("C standard version: %ld\n", __STDC_VERSION__);
|
||||
#else
|
||||
printf("C standard not defined\n");
|
||||
#endif
|
||||
|
||||
device_os_version();
|
||||
device_model();
|
||||
device_up_time();
|
||||
device_model();
|
||||
|
||||
}
|
||||
|
||||
void end() {
|
||||
#ifdef __APPLE__
|
||||
|
||||
free(u_cpu);
|
||||
free(u_ram);
|
||||
free(u_disk);
|
||||
free(u_device);
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
init();
|
||||
|
||||
printf("temperature: %d\nfrequency: %s\nname: %s\nthreads: %d\n", u_cpu->temperature, u_cpu->frequency, u_cpu->name, u_cpu->threads);
|
||||
printf("total: %ld\navailable: %ld\n", u_ram->total, u_ram->available);
|
||||
printf("device name:%s\ndevice hostname:%s\nos version: %s\nuptime: %d\n", u_device->name, u_device->hostname, u_device->os_version, u_device->uptime);
|
||||
|
||||
while(1) {
|
||||
|
||||
char *input = malloc(sizeof(char *));
|
||||
|
||||
if(scanf("%s\n", input)) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
end();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __gnu_linux
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -4,20 +4,20 @@
|
||||
typedef struct {
|
||||
|
||||
char* name;
|
||||
char* frequency;
|
||||
int frequency;
|
||||
int temperature;
|
||||
int threads;
|
||||
|
||||
} cpu_s;
|
||||
|
||||
typedef struct {
|
||||
long int total;
|
||||
long int available;
|
||||
unsigned long total;
|
||||
unsigned long available;
|
||||
} ram_s;
|
||||
|
||||
typedef struct {
|
||||
long size;
|
||||
char *name;
|
||||
long long size;
|
||||
short name;
|
||||
} disk_s;
|
||||
|
||||
typedef struct {
|
||||
@ -26,15 +26,12 @@ typedef struct {
|
||||
char *hostname;
|
||||
char *os_version;
|
||||
int uptime;
|
||||
cpu_s cpu;
|
||||
ram_s ram;
|
||||
disk_s disk;
|
||||
|
||||
|
||||
} device_s;
|
||||
|
||||
|
||||
extern cpu_s *u_cpu ;
|
||||
extern ram_s *u_ram ;
|
||||
extern disk_s *u_disk ;
|
||||
extern device_s *u_device ;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user