| |
| #include "LocalPrinter.hh" |
| |
| #include "USBProtocol.hh" |
| #include "umlrtcommsportrole.hh" |
| #include "umlrtmessage.hh" |
| #include "umlrtslot.hh" |
| #include <cstddef> |
| #include "umlrtcapsuleclass.hh" |
| #include "umlrtframeservice.hh" |
| class UMLRTRtsInterface; |
| struct UMLRTCommsPort; |
| |
| Capsule_LocalPrinter::Capsule_LocalPrinter( const UMLRTCapsuleClass * cd, UMLRTSlot * st, const UMLRTCommsPort * * border, const UMLRTCommsPort * * internal, bool isStat ) |
| : UMLRTCapsule( NULL, cd, st, border, internal, isStat ) |
| , currentState( SPECIAL_INTERNAL_STATE_UNVISITED ) |
| , usbPort( borderPorts[borderport_usbPort] ) |
| , usbClass( Printer ) |
| , printingData( false ) |
| { |
| stateNames[top__Disconnected] = "top__Disconnected"; |
| stateNames[top__Connected] = "top__Connected"; |
| stateNames[SPECIAL_INTERNAL_STATE_UNVISITED] = "<uninitialized>"; |
| } |
| |
| |
| void Capsule_LocalPrinter::inject( const UMLRTMessage & message ) |
| { |
| msg = &message; |
| switch( currentState ) |
| { |
| case top__Connected: |
| currentState = state_____top__Connected( &message ); |
| break; |
| case top__Disconnected: |
| currentState = state_____top__Disconnected( &message ); |
| break; |
| default: |
| break; |
| } |
| } |
| |
| void Capsule_LocalPrinter::initialize( const UMLRTMessage & message ) |
| { |
| msg = &message; |
| actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__initialize( &message ); |
| currentState = choice_____top__ChoicePoint2( &message ); |
| } |
| |
| const char * Capsule_LocalPrinter::getCurrentStateString() const |
| { |
| return stateNames[currentState]; |
| } |
| |
| |
| |
| |
| void Capsule_LocalPrinter::entryaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__Disconnected__Disconnected( const UMLRTMessage * msg ) |
| { |
| // the following code has been generated |
| /* UMLRT-CODEGEN:platform:/resource/ComputerSystem/ComputerSystem.uml#_0AZmkO0EEeST5KnPUdkGIg */ |
| #define rtdata ( (void *)msg->getParam( 0 ) ) |
| // generated code ends |
| time_t currentTime; |
| struct tm *localTime; |
| time( ¤tTime ); |
| localTime = localtime( ¤tTime ); |
| std::cout << std::setfill('0') << "[" << (localTime->tm_year + 1900) << "." << std::setw(2) << (localTime->tm_mon + 1) << "." << std::setw(2) << localTime->tm_mday << " " << std::setw(2) << localTime->tm_hour << ":" << std::setw(2) << localTime->tm_min << ":" << std::setw(2) << localTime->tm_sec << "] "; |
| std::cout << "[" << this->getName() << "] is in {Disconnected} state." << std::endl; |
| // the following code has been generated |
| #undef rtdata |
| // generated code ends |
| } |
| |
| void Capsule_LocalPrinter::transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__MessageSent__DeviceClassSent( const UMLRTMessage * msg ) |
| { |
| // the following code has been generated |
| /* UMLRT-CODEGEN:platform:/resource/ComputerSystem/ComputerSystem.uml#_rPoUsMOoEeSy9Z1Kd1VJnQ */ |
| #define rtdata ( (void *)msg->getParam( 0 ) ) |
| // generated code ends |
| time_t currentTime; |
| struct tm *localTime; |
| time( ¤tTime ); |
| localTime = localtime( ¤tTime ); |
| std::cout << std::setfill('0') << "[" << std::setw(2) << localTime->tm_hour << ":" << std::setw(2) << localTime->tm_min << ":" << std::setw(2) << localTime->tm_sec << "] "; |
| std::cout << "[" << this->getName() << "] sent its device class to the hub and is now {Connected}." << std::endl; |
| // the following code has been generated |
| #undef rtdata |
| // generated code ends |
| } |
| |
| void Capsule_LocalPrinter::transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__MsgSendFail__PrinterConnectionFailed( const UMLRTMessage * msg ) |
| { |
| // the following code has been generated |
| /* UMLRT-CODEGEN:platform:/resource/ComputerSystem/ComputerSystem.uml#_rVg5EMOOEeSSS8SwKHucgQ */ |
| #define rtdata ( (void *)msg->getParam( 0 ) ) |
| // generated code ends |
| time_t currentTime; |
| struct tm *localTime; |
| time( ¤tTime ); |
| localTime = localtime( ¤tTime ); |
| std::cout << std::setfill('0') << "[" << std::setw(2) << localTime->tm_hour << ":" << std::setw(2) << localTime->tm_min << ":" << std::setw(2) << localTime->tm_sec << "] "; |
| std::cout << "[" << this->getName() << "] Error sending device class to hub : connection failed {" << connectionStatus << "]" << std::endl; |
| // the following code has been generated |
| #undef rtdata |
| // generated code ends |
| } |
| |
| void Capsule_LocalPrinter::transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__initialize__Connect_Printer( const UMLRTMessage * msg ) |
| { |
| // the following code has been generated |
| /* UMLRT-CODEGEN:platform:/resource/ComputerSystem/ComputerSystem.uml#__DwQMMOMEeSSS8SwKHucgQ */ |
| #define rtdata ( (void *)msg->getParam( 0 ) ) |
| // generated code ends |
| time_t currentTime; |
| struct tm *localTime; |
| time( ¤tTime ); |
| localTime = localtime( ¤tTime ); |
| std::cout << std::setfill('0') << "[" << std::setw(2) << localTime->tm_hour << ":" << std::setw(2) << localTime->tm_min << ":" << std::setw(2) << localTime->tm_sec << "] "; |
| std::cout << "[" << this->getName() << "] initializing." << std::endl; |
| connectionStatus = usbPort.deviceClass(usbClass).send(); |
| // the following code has been generated |
| #undef rtdata |
| // generated code ends |
| } |
| |
| void Capsule_LocalPrinter::transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onConnect__connectingPrinter( const UMLRTMessage * msg ) |
| { |
| // the following code has been generated |
| /* UMLRT-CODEGEN:platform:/resource/ComputerSystem/ComputerSystem.uml#_DS0ocAupEeWCGuiso4e4-g */ |
| #define rtdata ( (void *)msg->getParam( 0 ) ) |
| // generated code ends |
| time_t currentTime; |
| struct tm *localTime; |
| time( ¤tTime ); |
| localTime = localtime( ¤tTime ); |
| std::cout << std::setfill('0') << "[" << std::setw(2) << localTime->tm_hour << ":" << std::setw(2) << localTime->tm_min << ":" << std::setw(2) << localTime->tm_sec << "] "; |
| std::cout << "[" << this->getName() << "] received a connection request and is now in {Connected} state." << std::endl; |
| // the following code has been generated |
| #undef rtdata |
| // generated code ends |
| } |
| |
| void Capsule_LocalPrinter::transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onData__PrintData( const UMLRTMessage * msg ) |
| { |
| // the following code has been generated |
| /* UMLRT-CODEGEN:platform:/resource/ComputerSystem/ComputerSystem.uml#_mQV8wMOTEeSSS8SwKHucgQ */ |
| #define umlrtparam_data ( *(const void * *)msg->getParam( 0 ) ) |
| #define rtdata ( (void *)msg->getParam( 0 ) ) |
| // generated code ends |
| /** |
| * Only show logging start on 1st dataset received |
| */ |
| if ( ! printingData ) { |
| time_t currentTime; |
| struct tm *localTime; |
| time( ¤tTime ); |
| localTime = localtime( ¤tTime ); |
| std::cout << std::setfill('0') << "[" << std::setw(2) << localTime->tm_hour << ":" << std::setw(2) << localTime->tm_min << ":" << std::setw(2) << localTime->tm_sec << "] "; |
| std::cout << "[" << this->getName() << "] Printing Start ==========" << std::endl; |
| printingData = true; |
| } |
| std::cout << (char *) umlrtparam_data; |
| usbPort.status(100).send(); |
| // the following code has been generated |
| #undef rtdata |
| #undef umlrtparam_data |
| // generated code ends |
| } |
| |
| void Capsule_LocalPrinter::transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onEOD__PrintingEnd( const UMLRTMessage * msg ) |
| { |
| // the following code has been generated |
| /* UMLRT-CODEGEN:platform:/resource/ComputerSystem/ComputerSystem.uml#_Li3_IMOUEeSSS8SwKHucgQ */ |
| #define rtdata ( (void *)msg->getParam( 0 ) ) |
| // generated code ends |
| std::cout << std::endl; |
| time_t currentTime; |
| struct tm *localTime; |
| time( ¤tTime ); |
| localTime = localtime( ¤tTime ); |
| std::cout << std::setfill('0') << "[" << std::setw(2) << localTime->tm_hour << ":" << std::setw(2) << localTime->tm_min << ":" << std::setw(2) << localTime->tm_sec << "] "; |
| std::cout << "[" << this->getName() << "] Printing Ended ==========" << std::endl; |
| printingData = false; |
| // the following code has been generated |
| #undef rtdata |
| // generated code ends |
| } |
| |
| void Capsule_LocalPrinter::transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onEject__EjectPrinter( const UMLRTMessage * msg ) |
| { |
| // the following code has been generated |
| /* UMLRT-CODEGEN:platform:/resource/ComputerSystem/ComputerSystem.uml#_13uUwMOoEeSy9Z1Kd1VJnQ */ |
| #define rtdata ( (void *)msg->getParam( 0 ) ) |
| // generated code ends |
| time_t currentTime; |
| struct tm *localTime; |
| time( ¤tTime ); |
| localTime = localtime( ¤tTime ); |
| std::cout << std::setfill('0') << "[" << std::setw(2) << localTime->tm_hour << ":" << std::setw(2) << localTime->tm_min << ":" << std::setw(2) << localTime->tm_sec << "] "; |
| std::cout << "[" << this->getName() << "] ejected!" << std::endl; |
| // the following code has been generated |
| #undef rtdata |
| // generated code ends |
| } |
| |
| bool Capsule_LocalPrinter::guard_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__MessageSent__ifConnected( const UMLRTMessage * msg ) |
| { |
| #define rtdata ( (void *)msg->getParam( 0 ) ) |
| // generated code ends |
| return(connectionStatus); |
| // the following code has been generated |
| #undef rtdata |
| // generated code ends |
| } |
| |
| bool Capsule_LocalPrinter::guard_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__MsgSendFail__ifNotConnected( const UMLRTMessage * msg ) |
| { |
| #define rtdata ( (void *)msg->getParam( 0 ) ) |
| // generated code ends |
| return(! connectionStatus); |
| // the following code has been generated |
| #undef rtdata |
| // generated code ends |
| } |
| |
| void Capsule_LocalPrinter::actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__MessageSent( const UMLRTMessage * msg ) |
| { |
| transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__MessageSent__DeviceClassSent( msg ); |
| } |
| |
| void Capsule_LocalPrinter::actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__MsgSendFail( const UMLRTMessage * msg ) |
| { |
| transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__MsgSendFail__PrinterConnectionFailed( msg ); |
| entryaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__Disconnected__Disconnected( msg ); |
| } |
| |
| void Capsule_LocalPrinter::actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__initialize( const UMLRTMessage * msg ) |
| { |
| transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__initialize__Connect_Printer( msg ); |
| } |
| |
| void Capsule_LocalPrinter::actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onConnect( const UMLRTMessage * msg ) |
| { |
| transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onConnect__connectingPrinter( msg ); |
| } |
| |
| void Capsule_LocalPrinter::actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onData( const UMLRTMessage * msg ) |
| { |
| transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onData__PrintData( msg ); |
| } |
| |
| void Capsule_LocalPrinter::actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onEOD( const UMLRTMessage * msg ) |
| { |
| transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onEOD__PrintingEnd( msg ); |
| } |
| |
| void Capsule_LocalPrinter::actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onEject( const UMLRTMessage * msg ) |
| { |
| transitionaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onEject__EjectPrinter( msg ); |
| entryaction_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__Disconnected__Disconnected( msg ); |
| } |
| |
| Capsule_LocalPrinter::State Capsule_LocalPrinter::choice_____top__ChoicePoint2( const UMLRTMessage * msg ) |
| { |
| if( guard_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__MsgSendFail__ifNotConnected( msg ) ) |
| { |
| actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__MsgSendFail( msg ); |
| return top__Disconnected; |
| } |
| else if( guard_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__MessageSent__ifConnected( msg ) ) |
| { |
| actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__MessageSent( msg ); |
| return top__Connected; |
| } |
| return currentState; |
| } |
| |
| Capsule_LocalPrinter::State Capsule_LocalPrinter::state_____top__Connected( const UMLRTMessage * msg ) |
| { |
| switch( msg->destPort->role()->id ) |
| { |
| case port_usbPort: |
| switch( msg->getSignalId() ) |
| { |
| case USBProtocol::signal_data: |
| actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onData( msg ); |
| return top__Connected; |
| case USBProtocol::signal_eod: |
| actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onEOD( msg ); |
| return top__Connected; |
| case USBProtocol::signal_Eject: |
| actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onEject( msg ); |
| return top__Disconnected; |
| default: |
| this->unexpectedMessage(); |
| break; |
| } |
| return currentState; |
| default: |
| this->unexpectedMessage(); |
| break; |
| } |
| return currentState; |
| } |
| |
| Capsule_LocalPrinter::State Capsule_LocalPrinter::state_____top__Disconnected( const UMLRTMessage * msg ) |
| { |
| switch( msg->destPort->role()->id ) |
| { |
| case port_usbPort: |
| switch( msg->getSignalId() ) |
| { |
| case USBProtocol::signal_connect: |
| actionchain_____action_____ComputerSystem__Hardware__ExternalDevices__LocalPrinter__LocalPrinter_SM__Region1__onConnect( msg ); |
| return top__Connected; |
| default: |
| this->unexpectedMessage(); |
| break; |
| } |
| return currentState; |
| default: |
| this->unexpectedMessage(); |
| break; |
| } |
| return currentState; |
| } |
| |
| |
| |
| |
| |
| void Capsule_LocalPrinter::bindPort( bool isBorder, int portId, int index ) |
| { |
| if( isBorder ) |
| switch( portId ) |
| { |
| case borderport_usbPort: |
| UMLRTFrameService::sendBoundUnbound( borderPorts, borderport_usbPort, index, true ); |
| break; |
| } |
| } |
| |
| void Capsule_LocalPrinter::unbindPort( bool isBorder, int portId, int index ) |
| { |
| if( isBorder ) |
| switch( portId ) |
| { |
| case borderport_usbPort: |
| UMLRTFrameService::sendBoundUnbound( borderPorts, borderport_usbPort, index, false ); |
| UMLRTFrameService::disconnectPort( borderPorts[borderport_usbPort], index ); |
| break; |
| } |
| } |
| |
| |
| |
| |
| |
| static const UMLRTCommsPortRole portroles_border[] = |
| { |
| { |
| Capsule_LocalPrinter::port_usbPort, |
| "USBProtocol", |
| "usbPort", |
| "", |
| 1, |
| true, |
| false, |
| false, |
| false, |
| false, |
| false, |
| true |
| }, |
| { |
| Capsule_LocalPrinter::port_log, |
| "Log", |
| "log", |
| "", |
| 1, |
| true, |
| false, |
| false, |
| false, |
| false, |
| false, |
| false |
| } |
| }; |
| |
| static void instantiate_LocalPrinter( const UMLRTRtsInterface * rts, UMLRTSlot * slot, const UMLRTCommsPort * * borderPorts ) |
| { |
| slot->capsule = new Capsule_LocalPrinter( &LocalPrinter, slot, borderPorts, NULL, false ); |
| } |
| |
| const UMLRTCapsuleClass LocalPrinter = |
| { |
| "LocalPrinter", |
| NULL, |
| instantiate_LocalPrinter, |
| 0, |
| NULL, |
| 2, |
| portroles_border, |
| 0, |
| NULL |
| }; |
| |