| 1 |
/* |
| 2 |
* Component of the D-ITG 2.8.1 (r1023) platform (http://traffic.comics.unina.it/software/ITG) |
| 3 |
* |
| 4 |
* Copyright : (C) 2004-2013 by Alessio Botta, Walter de Donato, Alberto Dainotti, |
| 5 |
* Stefano Avallone, Antonio Pescape' (PI) |
| 6 |
* COMICS (COMputer for Interaction and CommunicationS) Group |
| 7 |
* Department of Electrical Engineering and Information Technologies |
| 8 |
* University of Napoli "Federico II". |
| 9 |
* email : [email protected], [email protected], [email protected], |
| 10 |
* [email protected], [email protected] |
| 11 |
* |
| 12 |
* This program is free software: you can redistribute it and/or modify |
| 13 |
* it under the terms of the GNU General Public License as published by |
| 14 |
* the Free Software Foundation, either version 3 of the License, or |
| 15 |
* (at your option) any later version. |
| 16 |
* |
| 17 |
* This program is distributed in the hope that it will be useful, |
| 18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
* GNU General Public License for more details. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU General Public License |
| 23 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 24 |
* |
| 25 |
* For commercial use please refer to D-ITG Professional. |
| 26 |
*/ |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include "../common/thread.h" |
| 31 |
#include "../libITG/ITGapi.h" |
| 32 |
#include <stdio.h> |
| 33 |
#include <string.h> |
| 34 |
#include <cstdlib> |
| 35 |
|
| 36 |
#ifdef UNIX |
| 37 |
#include <pthread.h> |
| 38 |
#endif |
| 39 |
|
| 40 |
#include "ITGManager.h" |
| 41 |
|
| 42 |
char host[] = "localhost"; |
| 43 |
char nameProgram[] = "ITGManager"; |
| 44 |
|
| 45 |
|
| 46 |
void Terminate(int sig) |
| 47 |
{ |
| 48 |
#ifdef UNIX |
| 49 |
exit(1); |
| 50 |
#endif |
| 51 |
#ifdef WIN32 |
| 52 |
ExitProcess(0); |
| 53 |
#endif |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
void* waitStopKey(void* s) |
| 58 |
{ |
| 59 |
char c[10000]; |
| 60 |
do { |
| 61 |
fgets(c, 10000, stdin); |
| 62 |
if (c[0] == 'C') break; |
| 63 |
if (c[0] == '-') DITGsend(host, c); |
| 64 |
} while (c != 0); |
| 65 |
printf("Terminated by request\n"); |
| 66 |
Terminate(0); |
| 67 |
return NULL; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
int main(int argc, char* argv[]) |
| 73 |
{ |
| 74 |
char *sender, *msg; |
| 75 |
int i; |
| 76 |
char command[10000] = ""; |
| 77 |
|
| 78 |
if (argc > 1) if (strcmp(argv[1], "-h") == 0) { |
| 79 |
printf("\nITGManager 0.1 (c) 2007 Volker Semken\n\n"); |
| 80 |
printf("Usage: ITGManager <host> <settings>\n\n"); |
| 81 |
printf(" <host> ITGSend Hostname or IP address\n"); |
| 82 |
printf(" <settings> Command line options used for ITGSend\n"); |
| 83 |
Terminate(0); |
| 84 |
} |
| 85 |
|
| 86 |
printf("ITGManager started. Press Ctrl-C to terminate\n"); |
| 87 |
pthread_t pkey; |
| 88 |
CREATE_THREAD((void*)"wait", &waitStopKey, NULL, pkey, true); |
| 89 |
|
| 90 |
if (argc > 1) strcpy(host, argv[1]); |
| 91 |
printf("Using \"%s\" as destination ITGSender\n", host); |
| 92 |
for (i=2;i<argc;i++) strcat(strcat(command, " "), argv[i]); |
| 93 |
if (argc > 2) DITGsend(host, command); |
| 94 |
|
| 95 |
do { |
| 96 |
if ((i = catchManagerMsg(&sender, &msg)) != MNG_NOMSG) { |
| 97 |
printf("Received msg type %d %s %s\n", i, sender, msg); |
| 98 |
fflush(stdout); |
| 99 |
} |
| 100 |
#ifdef UNIX |
| 101 |
sleep(1); |
| 102 |
#else |
| 103 |
Sleep(1); |
| 104 |
#endif |
| 105 |
} while (1); |
| 106 |
} |