[Dfsm-devel] dFSM/src/utils dfsm_monitor.cpp,1.11,1.12 send_to.cpp,1.5,1.6 supervisor.cpp,1.8,1.9
Status: Beta
Brought to you by:
amoreno
|
From: Andreu M. <am...@us...> - 2004-03-31 16:54:10
|
Update of /cvsroot/dfsm/dFSM/src/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14362/src/utils Modified Files: dfsm_monitor.cpp send_to.cpp supervisor.cpp Log Message: Tinput interface supports send and send_to (useful for utilities) and change monitor as service Index: send_to.cpp =================================================================== RCS file: /cvsroot/dfsm/dFSM/src/utils/send_to.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** send_to.cpp 12 Sep 2003 16:29:13 -0000 1.5 --- send_to.cpp 31 Mar 2004 16:42:20 -0000 1.6 *************** *** 25,86 **** #include "libdfsm/tevent.h" - int16_t send( u_int16_t machine_n, u_int16_t id_msg, char *data, u_int16_t len) - { - //strstream socket_path; - u_int16_t sockfd; - unsigned char *msg; - struct sockaddr_un address; - int16_t result; - int bytes_sent; - char *ptr; - tEvent::Event *event; - - //socket_path.clear(); - - // Create a socket for the client - sockfd = socket(AF_UNIX, SOCK_STREAM, 0); - // Name the socket, as agreed with the server - address.sun_family = AF_UNIX; - - char tmp[5]; - strncpy(address.sun_path,SOCKET_DIR,99); // 99 = 104 - 5 104 is the maximum length of a unix socket path UNP - sprintf(tmp,"/%d",machine_n); - strncat(address.sun_path,tmp,5); // There won't be more than 999 machines - - // Now connect our socket to the server's socket - result = connect(sockfd, (struct sockaddr *)&address, sizeof(address)); - if(result != -1) { // Connected - // Now we can read/write via sockfd - clog <<"Connected to "<<address.sun_path<<endl; - msg=new unsigned char[sizeof(tEvent::Event)+len]; - event=(tEvent::Event *)msg; - if (msg != NULL) - { - // Compose message. A (tEvent::Event)header + (char *)data - event->id_msg = id_msg; - event->id_sender = 0; // Monitor. Fake value. - event->n_seq = 0; //Test msg. Fake value. - event->size=len; - ptr=(char *)((tEvent::Event *)msg+1); - memcpy(ptr,data,len); - } - if (sizeof(msg)>MAX_PACKET_SIZE) { - // FIXME: Throw an exception - cerr << "ERROR!: Max. packet size exceeded. Message not sent." << endl; - } - else - { - bytes_sent=write(sockfd, msg, sizeof(tEvent::Event)+len) ; - clog<<"Sent "<<bytes_sent<<" bytes to "<<address.sun_path<<endl; - } - close(sockfd); - delete[] msg ; - } - else - { - cerr << "Error while conecting to: "<<address.sun_path<<endl ; - } - } - int main(int argc, char *argv[]) --- 25,28 ---- *************** *** 89,96 **** char *data; machine_n=atoi(argv[1]); id_msg=atoi(argv[2]); cout <<"Machine id: "<<machine_n<<endl; cout <<"Msg id: "<<id_msg<<endl; ! send(machine_n,id_msg,"",0); } --- 31,45 ---- char *data; + if (argc != 3) + { + printf("Usage: send_to machine id_event \n"); + return 0; + } + machine_n=atoi(argv[1]); id_msg=atoi(argv[2]); cout <<"Machine id: "<<machine_n<<endl; cout <<"Msg id: "<<id_msg<<endl; ! send_event_to(machine_n, id_msg, NULL, 0); ! return 1; } Index: supervisor.cpp =================================================================== RCS file: /cvsroot/dfsm/dFSM/src/utils/supervisor.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** supervisor.cpp 19 Mar 2004 21:05:10 -0000 1.8 --- supervisor.cpp 31 Mar 2004 16:42:20 -0000 1.9 *************** *** 21,24 **** --- 21,27 ---- * $Revision$ * $Log$ + * Revision 1.9 2004/03/31 16:42:20 amoreno + * Tinput interface supports send and send_to (useful for utilities) and change monitor as service + * * Revision 1.8 2004/03/19 21:05:10 jvalduvieco * Prerelease cleanup. *************** *** 361,365 **** //Enviar events de shutdown //TODO: haltevent not defined ! if (pg->second->haltevent!=0) tinputs->send_to(pg->second->haltevent, NULL, 0); //Esperar event --- 364,368 ---- //Enviar events de shutdown //TODO: haltevent not defined ! if (pg->second->haltevent!=0) send_event(pg->second->haltevent, NULL, 0); //Esperar event *************** *** 399,403 **** //Enviar events de shutdown //TODO: haltevent not defined ! if (pg->second->resetevent!=0) tinputs->send_to(pg->second->resetevent, NULL, 0); } --- 402,406 ---- //Enviar events de shutdown //TODO: haltevent not defined ! if (pg->second->resetevent!=0) send_event(pg->second->resetevent, NULL, 0); } Index: dfsm_monitor.cpp =================================================================== RCS file: /cvsroot/dfsm/dFSM/src/utils/dfsm_monitor.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dfsm_monitor.cpp 19 Mar 2004 21:05:09 -0000 1.11 --- dfsm_monitor.cpp 31 Mar 2004 16:42:20 -0000 1.12 *************** *** 21,24 **** --- 21,27 ---- * $Revision$ * $Log$ + * Revision 1.12 2004/03/31 16:42:20 amoreno + * Tinput interface supports send and send_to (useful for utilities) and change monitor as service + * * Revision 1.11 2004/03/19 21:05:09 jvalduvieco * Prerelease cleanup. *************** *** 89,92 **** --- 92,101 ---- #include "libdfsm/tfsm.h" + #include "libdfsm/tinput.h" + #include "libdfsm/tevent.h" + + + tEvent *events; + dfsm_monitor::dfsm_monitor(u_int16_t machine):tsm_list(machine, false) { *************** *** 299,370 **** int send_to( bool broadcast, u_int16_t machine_n, u_int16_t id_msg, char *data=0,u_int16_t len=0) { - //strstream socket_path; - u_int16_t sockfd; - unsigned char *msg; - struct sockaddr_un address; - int16_t result; - int bytes_sent; - tEvent::Event *event; - char *ptr; - unsigned long long t1, t2; - tsm_route_table *sm; /**< Shared memory region which contains routing tables(which machines are subscribed to which messsages) */ - string socket_name; /**< Socket name */ - vector<u_int16_t>::iterator vns_i; - vector<u_int16_t> vns; - - if (broadcast) { ! sm = new tsm_route_table(MAX_MACHINE-1, false); ! vns = sm->get_msg_machine(id_msg); } ! else { ! vns.push_back(machine_n); ! } ! ! for (vns_i=vns.begin(); vns_i!=vns.end(); ++vns_i) { ! ! // Create a socket for the client ! sockfd = socket(AF_UNIX, SOCK_STREAM, 0); ! ! // Name the socket, as agreed with the server ! address.sun_family = AF_UNIX; ! ! char tmp[5]; ! strncpy(address.sun_path,SOCKET_DIR,99); // 99 = 104 - 5 104 is the maximum length of a unix socket path UNP ! sprintf(tmp,"/%d",(*vns_i)); ! strncat(address.sun_path,tmp,5); // There won't be more than 999 machines ! ! // Now connect our socket to the server's socket ! result = connect(sockfd, (struct sockaddr *)&address, sizeof(address)); ! if(result == -1) { ! } ! if(result != -1) { // Connected ! // Now we can read/write via sockfd ! msg=new unsigned char[sizeof(tEvent::Event)+len]; ! event=(tEvent::Event *)msg; ! if (msg != NULL) ! { ! // Compose message. A (tEvent::Event)header + (char *)data ! event->id_msg = id_msg; ! event->id_sender = MAX_MACHINE-1; ! event->n_seq = 0; //We not support this feature in monitor ! event->size=len; ! ptr=(char *)((tEvent::Event *)msg+1); ! memcpy(ptr,data,len); ! } ! if (sizeof(msg)>MAX_PACKET_SIZE) { ! // FIXME: Throw an exception ! } ! else ! { ! bytes_sent=write(sockfd, msg, sizeof(tEvent::Event)+len) ; ! } ! close(sockfd); ! delete[] msg ; ! } } - return bytes_sent; } --- 308,319 ---- int send_to( bool broadcast, u_int16_t machine_n, u_int16_t id_msg, char *data=0,u_int16_t len=0) { if (broadcast) { ! return send_event(id_msg, data, len); } ! else { ! return send_event_to(machine_n, id_msg, data, len); } } *************** *** 423,426 **** --- 372,381 ---- map <u_int16_t, dfsm_monitor*> machines; + // Setup Input_service + tEvent *events = new tEvent(); + tinputs->set_event_handler(events); + //tinput_service->run(); + + display_notice(); |