[Dfsm-devel] dFSM/src/libdfsm tfsm.cpp,1.33,1.34 tinput.cpp,1.22,1.23
Status: Beta
Brought to you by:
amoreno
|
From: Andreu M. <am...@us...> - 2004-04-03 06:44:16
|
Update of /cvsroot/dfsm/dFSM/src/libdfsm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1816/src/libdfsm Modified Files: tfsm.cpp tinput.cpp Log Message: Add support for manual and automatic state machine identification Index: tfsm.cpp =================================================================== RCS file: /cvsroot/dfsm/dFSM/src/libdfsm/tfsm.cpp,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** tfsm.cpp 31 Mar 2004 16:42:20 -0000 1.33 --- tfsm.cpp 3 Apr 2004 06:32:01 -0000 1.34 *************** *** 30,33 **** --- 30,36 ---- * $Revision$ * $Log$ + * Revision 1.34 2004/04/03 06:32:01 amoreno + * Add support for manual and automatic state machine identification + * * 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 *************** *** 161,165 **** ! tFSM::tFSM(const char *name, u_int8_t log_level, const char* file) { char buf[6]; --- 164,168 ---- ! tFSM::tFSM(u_int16_t machine_id, const char *name, u_int8_t log_level, const char* file) { char buf[6]; *************** *** 184,187 **** --- 187,192 ---- tFSM::events = new tEvent(); + if (machine_id == MACHINE_ID_AUTO) tinputs->init(); + else tinputs->init(machine_id); tinputs->set_event_handler(tFSM::events); tFSM::transition_rep=new tTransition_rep(); Index: tinput.cpp =================================================================== RCS file: /cvsroot/dfsm/dFSM/src/libdfsm/tinput.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** tinput.cpp 31 Mar 2004 16:42:20 -0000 1.22 --- tinput.cpp 3 Apr 2004 06:32:01 -0000 1.23 *************** *** 30,33 **** --- 30,36 ---- * $Revision$ * $Log$ + * Revision 1.23 2004/04/03 06:32:01 amoreno + * Add support for manual and automatic state machine identification + * * 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 *************** *** 136,143 **** tInput::tInput() { ! tInput::socket_name = tInput::reserve_socket_server(); ! tInput::sm = new tsm_route_table(atoi(tInput::socket_name), true); ! tInput::sm_seq = new tsm_seq(atoi(tInput::socket_name)); ! FSMLOG(3) << "TInput constructor. Socket name: "<<tInput::socket_name<<endl; } tInput::~tInput() --- 139,143 ---- tInput::tInput() { ! initialized = false; } tInput::~tInput() *************** *** 145,148 **** --- 145,169 ---- } + bool tInput::init() + { + tInput::socket_name = tInput::reserve_socket_server(); + tInput::sm = new tsm_route_table(atoi(tInput::socket_name), true); + tInput::sm_seq = new tsm_seq(atoi(tInput::socket_name)); + FSMLOG(3) << "TInput initr. Socket name: "<<tInput::socket_name<<endl; + initialized = true; + return true; + } + + bool tInput::init(u_int16_t machine_id) + { + check_socket_dir(); + tInput::socket_name = new char[10]; + sprintf (tInput::socket_name, "%d", machine_id); + tInput::sm = new tsm_route_table(machine_id, true); + tInput::sm_seq = new tsm_seq(machine_id); + FSMLOG(3) << "TInput init. Machine id: "<<machine_id<<endl; + initialized = true; + return true; + } // This is a BSAD. Maybe we should put a wrapper method and make this one private. *************** *** 157,160 **** --- 178,187 ---- char *ptr; + if (!initialized) + { + FSMLOG(0) << "ERROR!: TInput not initialized." << endl; + return 0; + } + if (sizeof(msg)>MAX_PACKET_SIZE) { *************** *** 194,198 **** if(sockfd == -1) { FSMLOG(1) <<"Error creating socket: "<<strerror(errno)<<endl; ! tInput::unregister_machine((*vns_i)); } // Name the socket, as agreed with the server --- 221,225 ---- if(sockfd == -1) { FSMLOG(1) <<"Error creating socket: "<<strerror(errno)<<endl; ! //tInput::unregister_machine((*vns_i)); } // Name the socket, as agreed with the server *************** *** 209,213 **** // Unregister machine (socket), clean exit. FSMLOG(2) <<"Unregistering |"<<address.sun_path<<"|"<<endl; ! tInput::unregister_machine((*vns_i)); } else --- 236,240 ---- // Unregister machine (socket), clean exit. FSMLOG(2) <<"Unregistering |"<<address.sun_path<<"|"<<endl; ! //tInput::unregister_machine((*vns_i)); } else *************** *** 220,224 **** // Unregister machine (socket), clean exit. FSMLOG(2) <<"Error sending: "<<strerror(errno)<<endl; ! tInput::unregister_machine((*vns_i)); } else --- 247,251 ---- // Unregister machine (socket), clean exit. FSMLOG(2) <<"Error sending: "<<strerror(errno)<<endl; ! //tInput::unregister_machine((*vns_i)); } else *************** *** 247,250 **** --- 274,283 ---- char *ptr; + if (!initialized) + { + FSMLOG(0) << "ERROR!: TInput not initialized." << endl; + return 0; + } + if (sizeof(msg)>MAX_PACKET_SIZE) { *************** *** 279,283 **** if(sockfd == -1) { FSMLOG(1) <<"Error creating socket: "<<strerror(errno)<<endl; ! tInput::unregister_machine(machine); } // Name the socket, as agreed with the server --- 312,316 ---- if(sockfd == -1) { FSMLOG(1) <<"Error creating socket: "<<strerror(errno)<<endl; ! //tInput::unregister_machine(machine); } // Name the socket, as agreed with the server *************** *** 293,297 **** // Unregister machine (socket), clean exit. FSMLOG(2) <<"Unregistering |"<<address.sun_path<<"|"<<endl; ! tInput::unregister_machine(machine); } else --- 326,330 ---- // Unregister machine (socket), clean exit. FSMLOG(2) <<"Unregistering |"<<address.sun_path<<"|"<<endl; ! //tInput::unregister_machine(machine); } else *************** *** 304,308 **** // Unregister machine (socket), clean exit. FSMLOG(2) <<"Error sending: "<<strerror(errno)<<endl; ! tInput::unregister_machine(machine); } else --- 337,341 ---- // Unregister machine (socket), clean exit. FSMLOG(2) <<"Error sending: "<<strerror(errno)<<endl; ! //tInput::unregister_machine(machine); } else *************** *** 321,325 **** ! const char *tInput::reserve_socket_server() { // ---------------------------------------------------------------- --- 354,376 ---- ! void tInput::check_socket_dir() ! { ! DIR *dirStructP; ! if((dirStructP = opendir(SOCKET_DIR)) == NULL) ! { ! if (errno == ENOENT) ! { // Doesn't exist ! mkdir(SOCKET_DIR, 0766); // Create directory ! } ! else ! { ! // FIXME: Either we don't have access permissions to this dir or a fatal error ! // has ocurred. We should throw a very big exception here and maybe exit. ! // exit(1); ! } ! } ! } ! ! char *tInput::reserve_socket_server() { // ---------------------------------------------------------------- *************** *** 391,394 **** --- 442,446 ---- } + void tInput::run() { *************** *** 402,405 **** --- 454,463 ---- tEvent::Event event; + if (!initialized) + { + FSMLOG(0) << "ERROR!: TInput not initialized." << endl; + return ; + } + client_len=sizeof(client_address); server_len = sizeof(server_address); *************** *** 467,470 **** --- 525,534 ---- const char *tInput::get_socket_name() const { + if (!initialized) + { + FSMLOG(0) << "ERROR!: TInput not initialized." << endl; + return ""; + } + return tInput::socket_name; } *************** *** 473,477 **** { // Unregister a machine (socket) ! tInput::sm->del_machine(machine_number); // Delete related routes --- 537,547 ---- { // Unregister a machine (socket) ! ! if (!initialized) ! { ! FSMLOG(0) << "ERROR!: TInput not initialized." << endl; ! return; ! } ! tInput::sm->del_machine(machine_number); // Delete related routes *************** *** 487,490 **** --- 557,566 ---- void tInput::register_msg(u_int16_t id_msg) { + if (!initialized) + { + FSMLOG(0) << "ERROR!: TInput not initialized." << endl; + return; + } + tInput::sm->add_msg_machine(id_msg, atoi(tInput::socket_name)); } |