[Dfsm-devel] dFSM/src/libdfsm tfsm.cpp,1.32,1.33 tfsm_monitor_sensor.cpp,1.2,1.3 tinput.cpp,1.21,1.2
Status: Beta
Brought to you by:
amoreno
|
From: Andreu M. <am...@us...> - 2004-03-31 16:54:10
|
Update of /cvsroot/dfsm/dFSM/src/libdfsm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14362/src/libdfsm Modified Files: tfsm.cpp tfsm_monitor_sensor.cpp tinput.cpp Log Message: Tinput interface supports send and send_to (useful for utilities) and change monitor as service Index: tfsm_monitor_sensor.cpp =================================================================== RCS file: /cvsroot/dfsm/dFSM/src/libdfsm/tfsm_monitor_sensor.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tfsm_monitor_sensor.cpp 3 Aug 2003 21:12:07 -0000 1.2 --- tfsm_monitor_sensor.cpp 31 Mar 2004 16:42:20 -0000 1.3 *************** *** 30,33 **** --- 30,36 ---- * $Revision$ * $Log$ + * Revision 1.3 2004/03/31 16:42:20 amoreno + * Tinput interface supports send and send_to (useful for utilities) and change monitor as service + * * Revision 1.2 2003/08/03 21:12:07 jvalduvieco * Major cleaning: *************** *** 47,53 **** #include "libdfsm/tfsm_monitor_sensor.h" ! tfsm_monitor_sensor::tfsm_monitor_sensor(u_int16_t machine, bool init) : tsm_list(machine, init) ! { } --- 50,58 ---- #include "libdfsm/tfsm_monitor_sensor.h" ! tFsm_monitor_sensor_service* Singleton<tFsm_monitor_sensor_service>::_instance=0; + tfsm_monitor_sensor::tfsm_monitor_sensor() + { + list = NULL; } *************** *** 57,65 **** } bool tfsm_monitor_sensor::push(unsigned char code, unsigned char size, unsigned char *data) { struct timeval time; gettimeofday(&time,NULL); ! return tsm_list::push(code, size, time, data); } --- 62,80 ---- } + + bool tfsm_monitor_sensor::init(u_int16_t machine, bool init) + { + list = new tsm_list(machine, init); + return true; + } + bool tfsm_monitor_sensor::push(unsigned char code, unsigned char size, unsigned char *data) { struct timeval time; + //Don't log monitor traces when not initialized, used in send_to, supervisor and dfsm_monitor. + if (list == NULL) return false; + gettimeofday(&time,NULL); ! return list->push(code, size, time, data); } Index: tfsm.cpp =================================================================== RCS file: /cvsroot/dfsm/dFSM/src/libdfsm/tfsm.cpp,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** tfsm.cpp 26 Mar 2004 12:20:43 -0000 1.32 --- tfsm.cpp 31 Mar 2004 16:42:20 -0000 1.33 *************** *** 30,33 **** --- 30,36 ---- * $Revision$ * $Log$ + * Revision 1.33 2004/03/31 16:42:20 amoreno + * Tinput interface supports send and send_to (useful for utilities) and change monitor as service + * * Revision 1.32 2004/03/26 12:20:43 amoreno * Minor improvement in using tinputs macro *************** *** 151,155 **** tLog tFSM::state_log; - tfsm_monitor_sensor *tFSM::monitor; --- 154,157 ---- *************** *** 181,185 **** strncpy(tFSM::fsm_machine,buf,50) ; - //tFSM::monitor = new tfsm_monitor_sensor(machine ,(machine == 0)); tFSM::events = new tEvent(); tinputs->set_event_handler(tFSM::events); --- 183,186 ---- *************** *** 194,198 **** machine = atoi(socket_number.c_str()); ! tFSM::monitor = new tfsm_monitor_sensor(machine ,(machine == 0)); tFSM::dFSM_log.set_pid(getpid()); tFSM::dFSM_log.set_fsmid(machine); --- 195,199 ---- machine = atoi(socket_number.c_str()); ! monitor_init(machine ,(machine == 0)); tFSM::dFSM_log.set_pid(getpid()); tFSM::dFSM_log.set_fsmid(machine); *************** *** 421,425 **** } ! monitor->push_entry_state(target->get_id()); // Check if events are pended, deferred events mostly, to process it --- 422,426 ---- } ! monitor_push_entry_state(target->get_id()); // Check if events are pended, deferred events mostly, to process it Index: tinput.cpp =================================================================== RCS file: /cvsroot/dfsm/dFSM/src/libdfsm/tinput.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** tinput.cpp 30 Mar 2004 15:12:31 -0000 1.21 --- tinput.cpp 31 Mar 2004 16:42:20 -0000 1.22 *************** *** 30,33 **** --- 30,36 ---- * $Revision$ * $Log$ + * Revision 1.22 2004/03/31 16:42:20 amoreno + * Tinput interface supports send and send_to (useful for utilities) and change monitor as service + * * Revision 1.21 2004/03/30 15:12:31 amoreno * Events are now total ordered. Solved bug in using the same semaphore for sm_route_table and sm_seq *************** *** 145,150 **** // This is a BSAD. Maybe we should put a wrapper method and make this one private. // We should protect against a user mistake in "len". ! // Retornar coses ! int tInput::send_to(u_int16_t id_msg, const char *data=0,u_int16_t len=0) { int16_t sockfd,result; --- 148,152 ---- // This is a BSAD. Maybe we should put a wrapper method and make this one private. // We should protect against a user mistake in "len". ! int tInput::send(u_int16_t id_msg, const char *data=0,u_int16_t len=0) { int16_t sockfd,result; *************** *** 223,227 **** { FSMLOG(3)<<"Sent "<<len<<" data bytes to "<<address.sun_path<<endl; ! tFSM::monitor->push_send_event(id_msg); } } --- 225,229 ---- { FSMLOG(3)<<"Sent "<<len<<" data bytes to "<<address.sun_path<<endl; ! monitor_push_send_event(id_msg); } } *************** *** 236,239 **** --- 238,324 ---- } + int tInput::send_to(u_int16_t machine, u_int16_t id_msg, const char *data=0,u_int16_t len=0) + { + int16_t sockfd,result; + unsigned char *msg; + struct sockaddr_un address; + ssize_t bytes_sent; + tEvent::Event *event; + char *ptr; + + if (sizeof(msg)>MAX_PACKET_SIZE) + { + // FIXME: Throw an exception + FSMLOG(0) << "ERROR!: Max. packet size exceeded. Message not sent." << endl; + return 0; + } + + msg=new unsigned char[sizeof(tEvent::Event)+len]; + if (msg == NULL) + { + // FIXME: Throw an exception + FSMLOG(0) << "ERROR!: Unable to allocate memory for messaget." << endl; + return 0; + } + event=(tEvent::Event *)msg; + + // Compose message. A (tEvent::Event)header + (char *)data + event->id_msg = id_msg; + event->id_sender = atoi(tInput::socket_name); + event->n_seq = tInput::sm_seq->get_n_seq_lock(); //Lock to achive total order of messages + event->size=len; + ptr=(char *)((tEvent::Event *)msg+1); + memcpy(ptr,data,len); + + FSMLOG(2) <<"Sending event "<<id_msg<<endl; + + char tmp[5]; + + // Create a socket for the client + sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + if(sockfd == -1) { + FSMLOG(1) <<"Error creating socket: "<<strerror(errno)<<endl; + tInput::unregister_machine(machine); + } + // Name the socket, as agreed with the server + address.sun_family = AF_UNIX; + strncpy(address.sun_path,SOCKET_DIR,99); // 99 = 104 - 5 + // 104 is the maximum length od a unix socket path UNP + sprintf(tmp,"/%d",machine); + strncat(address.sun_path,tmp,5); // There won't be more than 999 machines /999\0 + // Now connect our socket to the server's socket + result = connect(sockfd, (struct sockaddr *)&address, sizeof(address)); + if(result == -1) + { + // Unregister machine (socket), clean exit. + FSMLOG(2) <<"Unregistering |"<<address.sun_path<<"|"<<endl; + tInput::unregister_machine(machine); + } + else + { // Connected + // Now we can read/write via sockfd + FSMLOG(3) <<"Connected to "<<address.sun_path<<endl; + + bytes_sent=write(sockfd, msg, sizeof(tEvent::Event)+len) ; + if(bytes_sent == -1) { + // Unregister machine (socket), clean exit. + FSMLOG(2) <<"Error sending: "<<strerror(errno)<<endl; + tInput::unregister_machine(machine); + } + else + { + FSMLOG(3)<<"Sent "<<len<<" data bytes to "<<address.sun_path<<endl; + monitor_push_send_event(id_msg); + } + } + close(sockfd); + //delete[] msg ; + + tInput::sm_seq->get_n_seq_unlock(); + delete[] msg ; + return bytes_sent; + } + + const char *tInput::reserve_socket_server() { *************** *** 376,380 **** close(client_sockfd); ! tFSM::monitor->push_receive_event(event.id_msg); } } --- 461,465 ---- close(client_sockfd); ! monitor_push_receive_event(event.id_msg); } } |