diff options
Diffstat (limited to 'runtime/org.eclipse.etrice.modellib.cpp/src-gen')
4 files changed, 946 insertions, 0 deletions
diff --git a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.cpp b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.cpp new file mode 100644 index 000000000..8639764df --- /dev/null +++ b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.cpp @@ -0,0 +1,399 @@ +/** + * @author generated by eTrice + * + * Source File of ActorClass ATimingService + * + */ + +#include "ATimingService.h" + +#include "common/messaging/RTObject.h" +#include "common/messaging/RTServices.h" +#include "common/debugging/DebuggingService.h" +#include "common/debugging/MSCFunctionObject.h" + +using namespace etRuntime; + + +/*--------------------- begin user code ---------------------*/ +// uc3 +/*--------------------- end user code ---------------------*/ + +ATimingService::ATimingService(etRuntime::IRTObject* parent, const String& name) + : ActorClassBase(parent, name) + , timer(this, "timer", IFITEM_timer) + , tcbs() + , usedTcbsRoot(0) + , freeTcbsRoot(0) +{ + MSCFunctionObject mscFunctionObject(getInstancePathName(), "Constructor"); + + for (int i = 0; i < s_numberOfStates; i++) { + history[i] = NO_STATE; + } + setClassName("ATimingService"); + + // sub actors + + /* user defined constructor body */ + memset(tcbs.getData(), sizeof(tcbs), 0); +} + +void ATimingService::initialize() { + MSCFunctionObject mscFunctionObject(getInstancePathName(), "initialize()"); + + ActorClassBase::initialize(); + + + // wiring + + // activate polling for data-driven communication + RTServices::getInstance().getMsgSvcCtrl().getMsgSvc(getThread())->addPollingMessageReceiver(*this); +} + +void ATimingService::setProbesActive(bool recursive, bool active) { + DebuggingService::getInstance().addPortInstance(m_RTSystemPort); + for(int i = 0; i < timer.getNInterfaceItems(); i++) + DebuggingService::getInstance().addPortInstance(*(timer.getInterfaceItem(i))); +} + +void ATimingService::destroy(){ + MSCFunctionObject mscFunctionObject(getInstancePathName(), "destroy()"); + + /* user defined destructor body */ + DebuggingService::getInstance().addMessageActorDestroy(*this); + RTServices::getInstance().getMsgSvcCtrl().getMsgSvc(getThread())->removePollingMessageReceiver(*this); + ActorClassBase::destroy(); +} + +/*--------------------- operations ---------------------*/ + etTimerControlBlock* ATimingService::getTcb() { + etTimerControlBlock* temp = freeTcbsRoot; + + if (freeTcbsRoot != 0) { + freeTcbsRoot = freeTcbsRoot->next; + temp->next = 0; + } + return temp; +} + void ATimingService::returnTcb(etTimerControlBlock* block) { + block->next = freeTcbsRoot; + freeTcbsRoot = block; +} + void ATimingService::removeTcbFromUsedList(int32 idx) { + etTimerControlBlock* temp = usedTcbsRoot; + etTimerControlBlock* temp2 = usedTcbsRoot; + + if (temp == 0) + return; + + if (usedTcbsRoot->portIdx == idx) { + /* element found, the first one */ + usedTcbsRoot = usedTcbsRoot->next; + returnTcb(temp); + return; + } + + temp = temp->next; + while (temp != 0) { + if (temp->portIdx == idx) { + temp2->next = temp->next; + returnTcb(temp); + return; + } else { + /* try next */ + temp2 = temp; + temp = temp->next; + } + } +} + void ATimingService::putTcbToUsedList(etTimerControlBlock* block) { + etTimerControlBlock* temp = usedTcbsRoot; + etTimerControlBlock* temp2 = usedTcbsRoot; + + if (temp == 0) { + /* list empty put new block to root */ + block->next = 0; + usedTcbsRoot = block; + return; + } + + while (1) { + if (temp != 0) { + if (isTimeGreater(&block->expTime, &temp->expTime)) { + /* try next position */ + temp2 = temp; + temp = temp->next; + } else { + /* right position found */ + block->next = temp; + if (temp == usedTcbsRoot) { + usedTcbsRoot = block; + } else { + temp2->next = block; + } + return; + } + } else { + /* end of list reached */ + block->next = 0; + temp2->next = block; + return; + } + } +} + bool ATimingService::isTimeGreater(etTime* t1, etTime* t2) { + if (t1->sec > t2->sec) + return ET_TRUE; + if (t1->sec < t2->sec) + return ET_FALSE; + if (t1->nSec > t2->nSec) + return ET_TRUE; + return ET_FALSE; +} + void ATimingService::addTime(etTime* t1, etTime* t2) { + t1->sec += t2->sec; + t1->nSec += t2->nSec; + while (t1->nSec >= 1000000000L) { + t1->sec++; + t1->nSec -= 1000000000L; + } +} + +// state names +const String ATimingService::s_stateStrings[] = { + "<no state>", + "<top>", + "Operational" +}; +const int ATimingService::s_numberOfStates = 3; + +void ATimingService::setState(int new_state) { + DebuggingService::getInstance().addActorState(*this, s_stateStrings[new_state].c_str()); + m_state = new_state; +} + +/* Entry and Exit Codes */ +void ATimingService::entry_Operational() { + // prepare +} + void ATimingService::do_Operational() { + // maintain timers + etTimerControlBlock* temp; + etTime t; + + getTimeFromTarget(&t); + while (usedTcbsRoot != 0) { + if (isTimeGreater(&t, &(usedTcbsRoot->expTime))) { + timer.get(usedTcbsRoot->portIdx).timeout(); + temp = usedTcbsRoot; + usedTcbsRoot = usedTcbsRoot->next; + if ((temp->pTime.sec == 0) && (temp->pTime.nSec == 0)) { + // single shot timer + returnTcb(temp); + } else { + // periodic timer + addTime(&temp->expTime, &temp->pTime); + putTcbToUsedList(temp); + } + } else { + break; + } + } +} + +/* Action Codes */ +void ATimingService::action_TRANS_INITIAL_TO__Operational() { + int i; + usedTcbsRoot = 0; + freeTcbsRoot = &tcbs[0]; + tcbs[ET_NB_OF_TCBS - 1].next = 0; + for (i = 0; i < ET_NB_OF_TCBS - 1; i++) { + tcbs[i].next = &tcbs[i + 1]; + } +} +void ATimingService::action_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1(const InterfaceItemBase* ifitem, uint32 time) { + etTimerControlBlock* timer = getTcb(); + etTime t; + if (timer != 0) { + t.sec = time / 1000; + t.nSec = (time % 1000) * 1000000L; + timer->pTime.sec = 0; + timer->pTime.nSec = 0; + timer->portIdx = ifitem->getIdx(); + getTimeFromTarget(&(timer->expTime)); + addTime(&(timer->expTime), &t); + putTcbToUsedList(timer); + } +} +void ATimingService::action_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3(const InterfaceItemBase* ifitem, uint32 time) { + etTimerControlBlock* timer = getTcb(); + etTime t; + if (timer != 0) { + t.sec = time / 1000; + t.nSec = (time % 1000) * 1000000L; + timer->pTime = t; + timer->portIdx = ifitem->getIdx(); + getTimeFromTarget(&(timer->expTime)); + addTime(&(timer->expTime), &t); + putTcbToUsedList(timer); + } +} +void ATimingService::action_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4(const InterfaceItemBase* ifitem) { + removeTcbFromUsedList(ifitem->getIdx()); +} + +/* State Switch Methods */ +/** + * calls exit codes while exiting from the current state to one of its + * parent states while remembering the history + * @param current__et - the current state + * @param to - the final parent state + */ +void ATimingService::exitTo(etInt16 current__et, etInt16 to) { + while (current__et!=to) { + switch (current__et) { + case STATE_Operational: + this->history[STATE_TOP] = STATE_Operational; + current__et = STATE_TOP; + break; + default: + /* should not occur */ + break; + } + } +} + +/** + * calls action, entry and exit codes along a transition chain. The generic data are cast to typed data + * matching the trigger of this chain. The ID of the final state is returned + * @param chain__et - the chain ID + * @param generic_data__et - the generic data pointer + * @return the +/- ID of the final state either with a positive sign, that indicates to execute the state's entry code, or a negative sign vice versa + */ +etInt16 ATimingService::executeTransitionChain(int chain__et, const InterfaceItemBase* ifitem, void* generic_data__et) { + switch (chain__et) { + case ATimingService::CHAIN_TRANS_INITIAL_TO__Operational: + { + action_TRANS_INITIAL_TO__Operational(); + return STATE_Operational; + } + case ATimingService::CHAIN_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1: + { + uint32 time = *(static_cast<uint32*>(generic_data__et)); + action_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1(ifitem, time); + return STATE_Operational; + } + case ATimingService::CHAIN_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3: + { + uint32 time = *(static_cast<uint32*>(generic_data__et)); + action_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3(ifitem, time); + return STATE_Operational; + } + case ATimingService::CHAIN_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4: + { + action_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4(ifitem); + return STATE_Operational; + } + default: + /* should not occur */ + break; + } + return NO_STATE; +} + +/** + * calls entry codes while entering a state's history. The ID of the final leaf state is returned + * @param state__et - the state which is entered + * @return - the ID of the final leaf state + */ +etInt16 ATimingService::enterHistory(etInt16 state__et) { + etBool skip_entry__et = false; + if (state__et >= STATE_MAX) { + state__et = (state__et - STATE_MAX); + skip_entry__et = true; + } + while (true) { + switch (state__et) { + case STATE_Operational: + if (!(skip_entry__et)) entry_Operational(); + /* in leaf state: return state id */ + return STATE_Operational; + case STATE_TOP: + state__et = this->history[STATE_TOP]; + break; + default: + /* should not occur */ + break; + } + skip_entry__et = false; + } + /* return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true) */ +} + +void ATimingService::executeInitTransition() { + int chain__et = ATimingService::CHAIN_TRANS_INITIAL_TO__Operational; + etInt16 next__et = ATimingService::executeTransitionChain(chain__et, 0, 0); + next__et = ATimingService::enterHistory(next__et); + setState(next__et); +} + +/* receiveEvent contains the main implementation of the FSM */ +void ATimingService::receiveEventInternal(InterfaceItemBase* ifitem, int localId, int evt, void* generic_data__et) { + int trigger__et = (ifitem==0)? POLLING : localId + EVT_SHIFT*evt; + int chain__et = NOT_CAUGHT; + etInt16 catching_state__et = NO_STATE; + + if (!handleSystemEvent(ifitem, evt, generic_data__et)) { + switch (getState()) { + case STATE_Operational: + switch(trigger__et) { + case POLLING: + do_Operational(); + break; + case TRIG_timer__startTimeout: + { + chain__et = ATimingService::CHAIN_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1; + catching_state__et = STATE_TOP; + } + break; + case TRIG_timer__startTimer: + { + chain__et = ATimingService::CHAIN_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3; + catching_state__et = STATE_TOP; + } + break; + case TRIG_timer__kill: + { + chain__et = ATimingService::CHAIN_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4; + catching_state__et = STATE_TOP; + } + break; + default: + /* should not occur */ + break; + } + break; + default: + /* should not occur */ + break; + } + } + if (chain__et != NOT_CAUGHT) { + ATimingService::exitTo(getState(), catching_state__et); + { + etInt16 next__et = ATimingService::executeTransitionChain(chain__et, ifitem, generic_data__et); + next__et = ATimingService::enterHistory(next__et); + setState(next__et); + } + } +} +void ATimingService::receiveEvent(InterfaceItemBase* ifitem, int evt, void* generic_data__et) { + int localId = (ifitem==0)? 0 : ifitem->getLocalId(); + ATimingService::receiveEventInternal(ifitem, localId, evt, generic_data__et); +} +void ATimingService::receive(const Message* msg) { + receiveEvent(0, -1, 0); +} + + diff --git a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.h b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.h new file mode 100644 index 000000000..d351dd0aa --- /dev/null +++ b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.h @@ -0,0 +1,176 @@ +/** + * @author generated by eTrice + * + * Header File of ActorClass ATimingService + * + */ + +#ifndef _ROOM_BASIC_SERVICE_TIMING_ATIMINGSERVICE_H_ +#define _ROOM_BASIC_SERVICE_TIMING_ATIMINGSERVICE_H_ + +#include "common/etDatatypesCpp.hpp" +#include "common/messaging/IRTObject.h" +#include "common/modelbase/PortBase.h" +#include "common/modelbase/ReplicatedActorClassBase.h" +#include "common/modelbase/InterfaceItemBase.h" +#include "common/modelbase/SubSystemClassBase.h" +#include "common/messaging/Address.h" +#include "common/messaging/IMessageReceiver.h" +#include "common/debugging/DebuggingService.h" + +#include "room/basic/service/timing/PTimer.h" + +#include "common/modelbase/ActorClassBase.h" + +/*--------------------- begin user code ---------------------*/ +#include "osal/etTime.h" +#define ET_NB_OF_TCBS 30 +typedef struct etTCB etTimerControlBlock; +struct etTCB { + etTime expTime; + etTime pTime; + int32 portIdx; + etTimerControlBlock* next; +}; +/*--------------------- end user code ---------------------*/ + +using namespace etRuntime; + + +class ATimingService : public etRuntime::ActorClassBase { + + + protected: + //--------------------- ports + + //--------------------- sub actors + + //--------------------- saps + + //--------------------- services + PTimerReplPort timer; + + //--------------------- interface item IDs + typedef enum { + IFITEM_timer = 1 + } interface_items; + + /*--------------------- attributes ---------------------*/ + StaticArray<etTimerControlBlock, 30> tcbs; + etTimerControlBlock* usedTcbsRoot; + etTimerControlBlock* freeTcbsRoot; + + /*--------------------- operations ---------------------*/ + etTimerControlBlock* getTcb(); + void returnTcb(etTimerControlBlock* block); + void removeTcbFromUsedList(int32 idx); + void putTcbToUsedList(etTimerControlBlock* block); + bool isTimeGreater(etTime* t1, etTime* t2); + void addTime(etTime* t1, etTime* t2); + + public: + //--------------------- construction + ATimingService(etRuntime::IRTObject* parent, const String& name); + void initialize(void); + void setProbesActive(bool recursive, bool active); + + //--------------------- port getters + + + PTimerReplPort& getTimer (){ + return this->timer; + } + + //--------------------- lifecycle functions + virtual void destroy(); + + /* state IDs */ + typedef enum { + STATE_Operational = 2, + STATE_MAX = 3 + } state_ids; + + /* transition chains */ + typedef enum { + CHAIN_TRANS_INITIAL_TO__Operational = 1, + CHAIN_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1 = 2, + CHAIN_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3 = 3, + CHAIN_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4 = 4 + } ChainIDs; + + /* triggers */ + typedef enum { + POLLING = 0, + TRIG_timer__startTimer = IFITEM_timer + EVT_SHIFT*PTimer::IN_startTimer, + TRIG_timer__startTimeout = IFITEM_timer + EVT_SHIFT*PTimer::IN_startTimeout, + TRIG_timer__kill = IFITEM_timer + EVT_SHIFT*PTimer::IN_kill + } triggers; + + static const String s_stateStrings[]; + static const int s_numberOfStates; + + int history[3]; + + void setState(int new_state); + + /* Entry and Exit Codes */ + virtual void entry_Operational(); + virtual void do_Operational(); + + /* Action Codes */ + virtual void action_TRANS_INITIAL_TO__Operational(); + virtual void action_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1(const InterfaceItemBase* ifitem, uint32 time); + virtual void action_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3(const InterfaceItemBase* ifitem, uint32 time); + virtual void action_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4(const InterfaceItemBase* ifitem); + + /* State Switch Methods */ + /** + * calls exit codes while exiting from the current state to one of its + * parent states while remembering the history + * @param current__et - the current state + * @param to - the final parent state + */ + void exitTo(etInt16 current__et, etInt16 to); + + /** + * calls action, entry and exit codes along a transition chain. The generic data are cast to typed data + * matching the trigger of this chain. The ID of the final state is returned + * @param chain__et - the chain ID + * @param generic_data__et - the generic data pointer + * @return the +/- ID of the final state either with a positive sign, that indicates to execute the state's entry code, or a negative sign vice versa + */ + etInt16 executeTransitionChain(int chain__et, const InterfaceItemBase* ifitem, void* generic_data__et); + + /** + * calls entry codes while entering a state's history. The ID of the final leaf state is returned + * @param state__et - the state which is entered + * @return - the ID of the final leaf state + */ + etInt16 enterHistory(etInt16 state__et); + + void executeInitTransition(); + + /* receiveEvent contains the main implementation of the FSM */ + void receiveEventInternal(InterfaceItemBase* ifitem, int localId, int evt, void* generic_data__et); + void receiveEvent(InterfaceItemBase* ifitem, int evt, void* generic_data__et); + virtual void receive(const etRuntime::Message* msg); + + /*--------------------- begin user code ---------------------*/ + // uc2 + /*--------------------- end user code ---------------------*/ + +}; + +class ReplicatedATimingService : public ReplicatedActorClassBase { +public: + ReplicatedATimingService(IRTObject* parent, const String& name) : + ReplicatedActorClassBase(parent, name) {} + +protected: + ActorClassBase* createActor(IRTObject* parent, const String& name) { + return new ATimingService(parent, name); + } +}; + + +#endif /* _ROOM_BASIC_SERVICE_TIMING_ATIMINGSERVICE_H_ */ diff --git a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.cpp b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.cpp new file mode 100644 index 000000000..dce6afef7 --- /dev/null +++ b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.cpp @@ -0,0 +1,226 @@ +/** + * @author generated by eTrice + * + * Source File of ProtocolClass PTimer + * + */ + +#include "PTimer.h" + +#include "common/debugging/DebuggingService.h" +#include "common/debugging/MSCFunctionObject.h" +#include "common/messaging/AbstractMessageReceiver.h" +#include "common/messaging/Address.h" +#include "common/messaging/Message.h" +#include "common/modelbase/IEventReceiver.h" + +using namespace etRuntime; + + + +/* message names as strings for debugging (generate MSC) */ +const String PTimer::s_messageStrings[] = {"MIN", "timeout", "startTimer","startTimeout","kill","MAX"}; + +const String& PTimer::getMessageString(int msg_id) { + if ((MSG_MIN < msg_id ) && ( msg_id < MSG_MAX )) { + return s_messageStrings[msg_id]; + } else { + // id out of range + static const String errorMsg = "Message ID out of range"; + return errorMsg; + } +} + +//------------------------------------------------------------------------------------------------------------ +// port class +//------------------------------------------------------------------------------------------------------------ + +PTimerPort::PTimerPort(IInterfaceItemOwner* actor, const String& name, int localId) + : PortBase(actor, name, localId, 0) +{ +} + +PTimerPort::PTimerPort(IInterfaceItemOwner* actor, const String& name, int localId, int idx) + : PortBase(actor, name, localId, idx) +{ +} + +void PTimerPort::destroy() { + DebuggingService::getInstance().removePortInstance(*this); + PortBase::destroy(); +} + +void PTimerPort::receive(const Message* msg) { + // TODO JH further + if (! PTimer::isValidIncomingEvtID(msg->getEvtId())) { + //std::cout << "unknown" << std::endl; + } + + DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), PTimer::getMessageString(msg->getEvtId()).c_str()); + + getActor()->receiveEvent(this, msg->getEvtId(), msg->getData()); +} + + +// sent messages +void PTimerPort::timeout() { + timeout_impl(); +} + +void PTimerPort::timeout_impl() { + DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), + PTimer::getMessageString(PTimer::OUT_timeout).c_str()); + if (getPeerAddress().isValid()) { + Message* buffer = dynamic_cast<IMessageService*>(getPeerMsgReceiver())->getMessageBuffer(sizeof(Message)); + if (buffer) { + getPeerMsgReceiver()->receive(new (buffer) Message(getPeerAddress(), PTimer::OUT_timeout)); + } + } +} + +//------------------------------------------------------------------------------------------------------------ +// replicated port class +//------------------------------------------------------------------------------------------------------------ +PTimerReplPort::PTimerReplPort(IInterfaceItemOwner* actor, const String& name, int localId) : + ReplicatedPortBase(actor, name, localId) +{ +} + +// outgoing messages +void PTimerReplPort::timeout(){ + for (Vector<etRuntime::InterfaceItemBase*>::iterator it = getItems().begin(); it != getItems().end(); ++it) { + (dynamic_cast<PTimerPort*>(*it))->timeout(); + } +} +//------------------------------------------------------------------------------------------------------------ +// conjugated port class +//------------------------------------------------------------------------------------------------------------ + +PTimerConjPort::PTimerConjPort(IInterfaceItemOwner* actor, const String& name, int localId) + : PortBase(actor, name, localId, 0) + , status(0) +{ +} + +PTimerConjPort::PTimerConjPort(IInterfaceItemOwner* actor, const String& name, int localId, int idx) + : PortBase(actor, name, localId, idx) + , status(0) +{ +} + +void PTimerConjPort::destroy() { + DebuggingService::getInstance().removePortInstance(*this); + PortBase::destroy(); +} + +void PTimerConjPort::receive(const Message* msg) { + // TODO JH further + if (! PTimer::isValidOutgoingEvtID(msg->getEvtId())) { + //std::cout << "unknown" << std::endl; + } + + DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), PTimer::getMessageString(msg->getEvtId()).c_str()); + + switch (msg->getEvtId()) { + case PTimer::OUT_timeout: + { + + //TODO: clear active bit in case of single shot timer + if (status!=0){ + if (status==ET_TIMER_RUNNING){ + // single shot timer + status=0; + } + // msg to fsm + getActor()->receiveEvent(this, msg->getEvtId(), msg->getData()); + } + } + break; + default: + getActor()->receiveEvent(this, msg->getEvtId(), msg->getData()); + break; + } +} + +/*--------------------- operations ---------------------*/ + +// sent messages +void PTimerConjPort::startTimer(uint32 time) { + if (status==0){ + status=ET_TIMER_RUNNING | ET_TIMER_PERIODIC; + startTimer_impl(time); + } +} + +void PTimerConjPort::startTimer_impl(uint32 time) { + DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), + PTimer::getMessageString(PTimer::IN_startTimer).c_str()); + if (getPeerAddress().isValid()) { + Message* buffer = dynamic_cast<IMessageService*>(getPeerMsgReceiver())->getMessageBuffer(sizeof(DataMessage<uint32>)); + if (buffer) { + getPeerMsgReceiver()->receive(new (buffer) DataMessage<uint32>(getPeerAddress(), PTimer::IN_startTimer, time)); + } + } +} +void PTimerConjPort::startTimeout(uint32 time) { + if (status==0){ + status = ET_TIMER_RUNNING; + startTimeout_impl(time); + } +} + +void PTimerConjPort::startTimeout_impl(uint32 time) { + DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), + PTimer::getMessageString(PTimer::IN_startTimeout).c_str()); + if (getPeerAddress().isValid()) { + Message* buffer = dynamic_cast<IMessageService*>(getPeerMsgReceiver())->getMessageBuffer(sizeof(DataMessage<uint32>)); + if (buffer) { + getPeerMsgReceiver()->receive(new (buffer) DataMessage<uint32>(getPeerAddress(), PTimer::IN_startTimeout, time)); + } + } +} +void PTimerConjPort::kill() { + + if (status!=0){ + status=0; + kill_impl(); + } +} + +void PTimerConjPort::kill_impl() { + DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), + PTimer::getMessageString(PTimer::IN_kill).c_str()); + if (getPeerAddress().isValid()) { + Message* buffer = dynamic_cast<IMessageService*>(getPeerMsgReceiver())->getMessageBuffer(sizeof(Message)); + if (buffer) { + getPeerMsgReceiver()->receive(new (buffer) Message(getPeerAddress(), PTimer::IN_kill)); + } + } +} + +//------------------------------------------------------------------------------------------------------------ +// conjugated replicated port class +//------------------------------------------------------------------------------------------------------------ +PTimerConjReplPort::PTimerConjReplPort(IInterfaceItemOwner* actor, const String& name, int localId) : + ReplicatedPortBase(actor, name, localId) +{ +} + +// incoming messages +void PTimerConjReplPort::startTimer(uint32 time){ + for (Vector<etRuntime::InterfaceItemBase*>::iterator it = getItems().begin(); it != getItems().end(); ++it) { + (dynamic_cast<PTimerConjPort*>(*it))->startTimer( time); + } +} +void PTimerConjReplPort::startTimeout(uint32 time){ + for (Vector<etRuntime::InterfaceItemBase*>::iterator it = getItems().begin(); it != getItems().end(); ++it) { + (dynamic_cast<PTimerConjPort*>(*it))->startTimeout( time); + } +} +void PTimerConjReplPort::kill(){ + for (Vector<etRuntime::InterfaceItemBase*>::iterator it = getItems().begin(); it != getItems().end(); ++it) { + (dynamic_cast<PTimerConjPort*>(*it))->kill(); + } +} + + diff --git a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.h b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.h new file mode 100644 index 000000000..be5e64f10 --- /dev/null +++ b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.h @@ -0,0 +1,145 @@ +/** + * @author generated by eTrice + * + * Header File of ProtocolClass PTimer + * + */ + +#ifndef _ROOM_BASIC_SERVICE_TIMING_PTIMER_H_ +#define _ROOM_BASIC_SERVICE_TIMING_PTIMER_H_ + +#include "common/modelbase/InterfaceItemBase.h" +#include "common/modelbase/PortBase.h" +#include "common/modelbase/ReplicatedInterfaceItemBase.h" +#include "common/modelbase/ReplicatedPortBase.h" +#include "common/etDatatypesCpp.hpp" + + +/*--------------------- begin user code ---------------------*/ +#define ET_TIMER_RUNNING 0x01 +#define ET_TIMER_PERIODIC 0x02 +/*--------------------- end user code ---------------------*/ + + +class PTimer { + public: + /* message IDs */ + typedef enum { + MSG_MIN = 0, + OUT_timeout = 1, + IN_startTimer = 2, + IN_startTimeout = 3, + IN_kill = 4, + MSG_MAX = 5 + } msg_ids; + + /*--------------------- begin user code ---------------------*/ + //uc2 + /*--------------------- end user code ---------------------*/ + + static bool isValidEvtID(int evtId) { + return ((MSG_MIN < evtId) && (evtId < MSG_MAX)); + } + static bool isValidOutgoingEvtID(int evtId) { + return ((MSG_MIN < evtId) && (evtId < IN_startTimer)); + } + static bool isValidIncomingEvtID(int evtId) { + return ((IN_startTimer <= evtId) && (evtId < MSG_MAX)); + } + static const etRuntime::String& getMessageString(int msg_id); + + private: + static const etRuntime::String s_messageStrings[]; + +}; + +//------------------------------------------------------------------------------------------------------------ +// port class +//------------------------------------------------------------------------------------------------------------ +class PTimerPort : public etRuntime::PortBase { + public: + PTimerPort(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId); + PTimerPort(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId, int idx); + + virtual void destroy(); + + virtual void receive(const etRuntime::Message* m); + + + // sent messages + public: void timeout(); + private: void timeout_impl(); +}; + +//------------------------------------------------------------------------------------------------------------ +// replicated port class +//------------------------------------------------------------------------------------------------------------ +class PTimerReplPort : public etRuntime::ReplicatedPortBase { + + public: + PTimerReplPort(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId); + + int getReplication() const { return getNInterfaceItems(); } + int getIndexOf(const etRuntime::InterfaceItemBase& ifitem) const { return ifitem.getIdx(); } + PTimerPort& get(int idx) const { return *dynamic_cast<PTimerPort*>(getInterfaceItem(idx)); } + + // outgoing messages + public: void timeout(); + + protected: + virtual etRuntime::InterfaceItemBase* createInterfaceItem(etRuntime::IInterfaceItemOwner* rcv, const etRuntime::String& name, int lid, int idx) { + return new PTimerPort(rcv, name, lid, idx); + } + +}; +//------------------------------------------------------------------------------------------------------------ +// conjugated port class +//------------------------------------------------------------------------------------------------------------ +class PTimerConjPort : public etRuntime::PortBase { + public: + PTimerConjPort(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId); + PTimerConjPort(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId, int idx); + + virtual void destroy(); + + virtual void receive(const etRuntime::Message* m); + + /*--------------------- attributes ---------------------*/ + int8 status; + /*--------------------- operations ---------------------*/ + + // sent messages + public: void startTimer(uint32 time); + private: void startTimer_impl(uint32 time); + public: void startTimeout(uint32 time); + private: void startTimeout_impl(uint32 time); + public: void kill(); + private: void kill_impl(); +}; + +//------------------------------------------------------------------------------------------------------------ +// conjugated replicated port class +//------------------------------------------------------------------------------------------------------------ +class PTimerConjReplPort : public etRuntime::ReplicatedPortBase { + + public: + PTimerConjReplPort(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId); + + int getReplication() const { return getNInterfaceItems(); } + int getIndexOf(const etRuntime::InterfaceItemBase& ifitem) const { return ifitem.getIdx(); } + PTimerConjPort& get(int idx) const { return *dynamic_cast<PTimerConjPort*>(getInterfaceItem(idx)); } + + // incoming messages + public: void startTimer(uint32 time); + public: void startTimeout(uint32 time); + public: void kill(); + + protected: + virtual etRuntime::InterfaceItemBase* createInterfaceItem(etRuntime::IInterfaceItemOwner* rcv, const etRuntime::String& name, int lid, int idx) { + return new PTimerConjPort(rcv, name, lid, idx); + } + +}; + + +#endif /* _ROOM_BASIC_SERVICE_TIMING_PTIMER_H_ */ |