int main(int argc, char* argv[]) { if (argc < 3) { fprintf(stderr, "Error: too few args!\n"); fprintf(stderr, "Usage: ./pm_client ip port\n"); exit(EXIT_FAILURE); } int server_port = atoi(argv[2]); sockfd = activeSocket(argv[1], server_port); waitForRequest(sockfd); /* triggr programs based on Runscript */ struct rs_data *ptr = NULL; while ((ptr = get_RunScript()) != NULL) { const char *cmd = get_RunScript_command(ptr); printf("RS:[%s]\n", cmd); //triggerRunScript(cmd); system(cmd); free(ptr); } /* turn on powermemo*/ pid_t pid = triggerPowerMemo(); /* wait for End section */ struct pm_prefix pm_pfx; int n = read(sockfd, &pm_pfx, sizeof(pm_pfx)); if (n < 0 || n == 0) { exit(EXIT_FAILURE); } if (pm_pfx.type == END_SECTION) { /* turn off powermemo */ kill(pid, SIGUSR1); } else { fprintf(stderr, "Error: not an End Section singal!\n"); exit(EXIT_FAILURE); } fprintf(stderr, "memo should be dead already!\n"); /* notify the server that we are done*/ write(sockfd, &pm_pfx, sizeof(pm_pfx)); return 0; }
void WiFlyDevice::runServer() { while (true) { waitForRequest(); } }