Make C++ compiler friendly and handle all eight counters in one process.

r1171 | dcl | 2006-10-24 15:44:25 +1000 (Tue, 24 Oct 2006) | 2 lines
This commit is contained in:
Douglas Clowes
2006-10-24 15:44:25 +10:00
parent 74ad3d225f
commit 2ab57e1eb2
13 changed files with 294 additions and 191 deletions

View File

@@ -159,10 +159,11 @@ static void add_counter(BUFFER* buffer, char* title, char* name, uint64 value)
*/
void put_form(int n)
{
dprintf(0, "put_form\n");
dbg_printf(0, "put_form\n");
BUFFER html;
BUFFER buffer;
PARAMETERS* pp = &counter.params;
COUNTER* cp = (COUNTER*) sock_device(n);
PARAMETERS* pp = &cp->params;
char *bp;
buffer.length = 0;
bp = &buffer.body[buffer.length];
@@ -237,7 +238,7 @@ void put_form(int n)
sock_send(n, &html);
}
static void show_text(BUFFER* buffer, char* title, char* value)
static void show_text(BUFFER* buffer, const char* title, const char* value)
{
char* bp = &buffer->body[buffer->length];
snprintf(bp, sizeof(buffer->body) - buffer->length,
@@ -313,17 +314,17 @@ static void show_time(BUFFER* buffer,
*/
void put_page(int n)
{
dprintf(0, "put_page\n");
dbg_printf(0, "put_page\n");
BUFFER html;
BUFFER buffer;
COUNTER* cp = &counter;
PARAMETERS* pp = &counter.params;
COUNTER* cp = (COUNTER*) sock_device(n);
PARAMETERS* pp = &cp->params;
SAMPLE* sp;
char *bp;
int refresh;
#if 1
{
refresh = cntr_time_to_next_report(cp) + 1;
refresh = (int) cntr_time_to_next_report(cp) + 1;
}
#else
make_report(cp);
@@ -431,54 +432,55 @@ void put_page(int n)
*/
void process_form(int n, BUFFER* bp)
{
dprintf(0, "process_form\n");
dbg_printf(0, "process_form\n");
int i, j;
int state;
char name[80];
char value[80];
char hex_str[3];
unsigned int hex_val;
char* cp;
char* tp;
COUNTER* cp = (COUNTER*) sock_device(n);
state = 0;
j = 0;
for (i = 0; i < bp->length; ++i)
{
cp = &bp->body[i];
tp = &bp->body[i];
if (state == 0)
{
if (*cp == '=')
if (*tp == '=')
{
name[j++] = '\0';
j = 0;
state = 1;
}
else if (j < 80 - 1)
name[j++] = tolower(*cp);
name[j++] = tolower(*tp);
}
else if (state == 1)
{
if (*cp == '&')
if (*tp == '&')
{
value[j++] = '\0';
j = 0;
state = 9;
}
else if (*cp == '%')
else if (*tp == '%')
{
hex_str[0] = '\0';
state = 2;
}
else if (j < 80 - 1)
value[j++] = tolower(*cp);
value[j++] = tolower(*tp);
}
else if (state == 2)
{
hex_str[0] = tolower(*cp);
hex_str[0] = tolower(*tp);
state = 3;
}
else if (state == 3)
{
hex_str[1] = tolower(*cp);
hex_str[1] = tolower(*tp);
hex_str[2] = '\0';
hex_val = strtoul(hex_str, NULL, 16);
if (hex_val < ' ' || hex_val > '~')
@@ -489,8 +491,8 @@ void process_form(int n, BUFFER* bp)
}
if (state == 9)
{
dprintf(0, "name=\"%s\", value=\"%s\"\n", name, value);
if (param_set(&counter.params, name, value))
dbg_printf(0, "name=\"%s\", value=\"%s\"\n", name, value);
if (param_set(&cp->params, name, value))
;
else if (strcmp(name, "xxx"))
{
@@ -510,19 +512,19 @@ void process_form(int n, BUFFER* bp)
*/
void put_page_refresh(int n)
{
dprintf(0, "put_page_refresh\n");
dbg_printf(0, "put_page_refresh\n");
BUFFER html;
BUFFER buffer;
char* bp;
COUNTER* cp = &counter;
COUNTER* cp = (COUNTER*) sock_device(n);
int refresh;
#if 1
{
refresh = cntr_time_to_next_report(cp) + 1;
refresh = (int) cntr_time_to_next_report(cp) + 1;
}
#else
PARAMETERS* pp = &counter.params;
PARAMETERS* pp = &cp->params;
make_report(cp);
refresh = (pp->poll_period * pp->sample_period * pp->report_period + 500) / 1000;
#endif
@@ -563,19 +565,19 @@ void put_page_refresh(int n)
*/
void put_form_refresh(int n)
{
dprintf(0, "put_form_refresh\n");
dbg_printf(0, "put_form_refresh\n");
BUFFER html;
BUFFER buffer;
char* bp;
COUNTER* cp = &counter;
COUNTER* cp = (COUNTER*) sock_device(n);
int refresh;
#if 1
{
refresh = cntr_time_to_next_report(cp) + 1;
refresh = (int) cntr_time_to_next_report(cp) + 1;
}
#else
PARAMETERS* pp = &counter.params;
PARAMETERS* pp = &cp->params;
make_report(cp);
refresh = (pp->poll_period * pp->sample_period * pp->report_period + 500) / 1000;
#endif
@@ -616,47 +618,48 @@ void put_form_refresh(int n)
*/
void process_command(int n, BUFFER* bp)
{
dprintf(0, "process_command(%d, %s)\n", n, bp->body);
dbg_printf(0, "process_command(%d, %s)\n", n, bp->body);
bool sics = false;
int error = 1;
char command[80];
char param[80];
int len = 0;
char* cp = bp->body;
while (isspace(*cp))
++cp;
char* tp = bp->body;
COUNTER* cp = static_cast<COUNTER*>(sock_device(n));
while (isspace(*tp))
++tp;
len = 0;
while (*cp && !isspace(*cp))
while (*tp && !isspace(*tp))
{
if (len < 80 - 1)
command[len++] = *cp;
++cp;
command[len++] = *tp;
++tp;
}
command[len] = '\0';
if (strcasecmp(command, "SICS") == 0)
{
sics = true;
while (isspace(*cp))
++cp;
while (isspace(*tp))
++tp;
len = 0;
while (*cp && !isspace(*cp))
while (*tp && !isspace(*tp))
{
if (len < 80 - 1)
command[len++] = *cp;
++cp;
command[len++] = *tp;
++tp;
}
command[len] = '\0';
}
while (isspace(*cp))
++cp;
while (isspace(*tp))
++tp;
if (strcasecmp(command, "START") == 0)
error = cntr_start(&counter);
error = cntr_start(cp);
else if (strcasecmp(command, "STOP") == 0)
error = cntr_stop(&counter);
error = cntr_stop(cp);
else if (strcasecmp(command, "PAUSE") == 0)
error = cntr_pause(&counter);
error = cntr_pause(cp);
else if (strcasecmp(command, "RESUME") == 0)
error = cntr_resume(&counter);
error = cntr_resume(cp);
else if (strcasecmp(command, "REPORT") == 0)
{
int match = 1;
@@ -664,11 +667,11 @@ void process_command(int n, BUFFER* bp)
if (sics)
match = 2;
len = 0;
while (*cp && !isspace(*cp))
while (*tp && !isspace(*tp))
{
if (len < 80 - 1)
param[len++] = *cp;
++cp;
param[len++] = *tp;
++tp;
}
param[len] = '\0';
if (strcasecmp(param, "OFF") == 0)
@@ -678,24 +681,24 @@ void process_command(int n, BUFFER* bp)
else if (strcasecmp(command, "SET") == 0)
{
/* set parameter */
dprintf(0, "SET %s\n", cp);
if (param_set_cmd(&counter.params, cp))
dbg_printf(0, "SET %s\n", tp);
if (param_set_cmd(&cp->params, tp))
error = 0;
}
else if (strcasecmp(command, "GET") == 0)
{
/* get parameter */
param_get_cmd(&counter.params, cp, n);
param_get_cmd(&cp->params, tp, n);
return;
}
else if (strcasecmp(command, "READ") == 0)
{
cntr_read(&counter, n);
cntr_read(cp, n);
return;
}
else if (!sics)
{
cntr_send(&counter, n);
cntr_send(cp, n);
return;
}
if (error == 0)