Hi:
This is how I get info from the server. The server sends it in "struct risp" format
void MainWindow::getSysStat() {
/* create the system info strusture that will hold information about the server */
sysInfo = (struct risp *)malloc(sizeof(struct risp));
//sysInfo->running_kernel = (char *)malloc(sizeof(char) * LONGEST_KERNEL_NAME);
//sysInfo->fsStat->name = (char *)malloc(sizeof(char) * LONGEST_NAME);
//sysInfo->fsStat->devName = (char *)malloc(sizeof(char) * LONGEST_NAME);
/* wait until the socket gets connected */
if(socket->waitForConnected(-1)) {
/* wait until data gets available */
if(socket->waitForReadyRead(-1)) {
/* read from the socket */
char *dataRead = (char *)malloc(sizeof(char)*sizeof(struct risp));
if((socket->read(dataRead, sizeof(struct risp))) == -1)
qDebug() << "Error reading data from server";
/* cast the data to match the risp structure */
sysInfo = (struct risp *)dataRead;
//qDebug() << "total cpu is: " << sysInfo->total_cpu;
}
}
}
void MainWindow::getSysStat() {
/* create the system info strusture that will hold information about the server */
sysInfo = (struct risp *)malloc(sizeof(struct risp));
//sysInfo->running_kernel = (char *)malloc(sizeof(char) * LONGEST_KERNEL_NAME);
//sysInfo->fsStat->name = (char *)malloc(sizeof(char) * LONGEST_NAME);
//sysInfo->fsStat->devName = (char *)malloc(sizeof(char) * LONGEST_NAME);
/* wait until the socket gets connected */
if(socket->waitForConnected(-1)) {
/* wait until data gets available */
if(socket->waitForReadyRead(-1)) {
/* read from the socket */
char *dataRead = (char *)malloc(sizeof(char)*sizeof(struct risp));
if((socket->read(dataRead, sizeof(struct risp))) == -1)
qDebug() << "Error reading data from server";
/* cast the data to match the risp structure */
sysInfo = (struct risp *)dataRead;
//qDebug() << "total cpu is: " << sysInfo->total_cpu;
}
}
}
To copy to clipboard, switch view to plain text mode
Here is struct risp:
struct risp {
/* cpu info */
unsigned long cpu_usage; /* /proc/ */
unsigned long total_cpu; /* /proc/cpuinfo */
//char proc_name[LONGEST_PROC_NAME]; /* /proc/ */
//char *cpu_processes[NUMBER_OF_PROCESSES]; /* /proc/ */
/* ram info */
unsigned int ram_usage; /* /proc/meminfo */
unsigned int total_ram; /* /proc/meminfo */
//char *ram_processes[NUMBER_OF_PROCESSES]; /* /proc/ */
/* swap info */
unsigned int swap_usage; /* /proc/meminfo */
unsigned int total_swap; /* /proc/swaps */
/* filesystems */
struct fsMountList *fsStat;
unsigned short int numFs;
/* kernel info */
char *running_kernel; /* /proc/ */
float uptime; /* /proc/uptime -> the first number is the uptime in seconds */
unsigned short int num_users; /* /proc */
unsigned short int num_processes;
unsigned short int num_running_processes; /* /proc/stat -> procs_running */
char arips_included; /* 0/1 */
};
struct risp {
/* cpu info */
unsigned long cpu_usage; /* /proc/ */
unsigned long total_cpu; /* /proc/cpuinfo */
//char proc_name[LONGEST_PROC_NAME]; /* /proc/ */
//char *cpu_processes[NUMBER_OF_PROCESSES]; /* /proc/ */
/* ram info */
unsigned int ram_usage; /* /proc/meminfo */
unsigned int total_ram; /* /proc/meminfo */
//char *ram_processes[NUMBER_OF_PROCESSES]; /* /proc/ */
/* swap info */
unsigned int swap_usage; /* /proc/meminfo */
unsigned int total_swap; /* /proc/swaps */
/* filesystems */
struct fsMountList *fsStat;
unsigned short int numFs;
/* kernel info */
char *running_kernel; /* /proc/ */
float uptime; /* /proc/uptime -> the first number is the uptime in seconds */
unsigned short int num_users; /* /proc */
unsigned short int num_processes;
unsigned short int num_running_processes; /* /proc/stat -> procs_running */
char arips_included; /* 0/1 */
};
To copy to clipboard, switch view to plain text mode
The problem is this:
qDebug("Kernel: %s", sysInfo->running_kernel);
qDebug("Kernel: %s", sysInfo->running_kernel);
To copy to clipboard, switch view to plain text mode
it displays noting like ti should: it should display: "2.5.25"
So does anybody see what's the problem ?
Bookmarks