 |
| People at Fluidsignal Group
|
#include "common.h"
#include "argutils.h"
#define MAX_LINE 70
Mensaje message;
char full_path[100];
char line[MAX_LINE];
char **args;
short state;
#ifdef WIN32
HANDLE idshm;
#endif
#ifdef UNIX
void *shared_segment;
#elif WIN32
LPVOID shared_segment;
#endif
#ifdef UNIX
int input_fd;
#elif WIN32
HANDLE input_fd;
#endif
int
main (int argc, char **argv)
{
if (argc != 2)
{
printf("Use: %s REPEATER_ID\n",argv[0]);
exit(-1);
}
#ifdef UNIX
sprintf(full_path,"/tmp/rp-%s.input",argv[1]);
input_fd = open(full_path, O_WRONLY);
if (input_fd == -1)
{
printf("Can't open repeater input pipe\n");
exit(-1);
}
#elif WIN32
sprintf(full_path,"\\\\.\\pipe\\rp-%d.in", argv[1]);
WaitNamedPipe(full_path,NMPWAIT_WAIT_FOREVER); // Only used when connecting with ConnectNamedPipe
input_fd=CreateFile(full_path,
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
(PHANDLE)NULL);
#endif
printf("Input of repeater attached to output of control\n");
while(printf("CONTROL> ") && fgets(line, MAX_LINE, stdin) != '\0')
{
if(strlen(line)>1) {
line[strlen(line)-1]='\0';
args=split_parameter(line);
if(!strcmp(args[0],"quit"))
{
return 1;
}
if( tokens_count(line) < 4 && tokens_count(line) > 1 )
{
if(tokens_count(line)==2 && !strcmp(args[0],"SHOW"))
{
#ifdef UNIX
shared_segment = (void*)shmat(atoi(args[1]), (void*)0, 0);
#elif WIN32
idshm = CreateFileMapping ((HANDLE) INVALID_HANDLE_VALUE,
NULL,
PAGE_READWRITE,
0,
1024,
args[1]);
if (idshm != NULL)
{
shared_segment = MapViewOfFile(idshm, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
if (shared_segment != NULL)
{
//no se pudo maperar la memoria compartida
}
}
#endif
memcpy(&state,shared_segment,sizeof(short));
printf("Device is: %i\n", state);
}
else
{
message = build_message(orden_t,
CONTROL_ADDRESS,
args[0],
args[1],
args[2] =! NULL ?
args[2] : NULL );
send_message(input_fd,&message);
}
}
else
{
printf("Wrong number of arguments\n");
}
}
}
}