IBM Support

Working with the Rhapsody OMEventQueue object

General Page

The executable you create in Rhapsody has a main thread with an event queue. Each active class in your project runs on its own thread and therefore also has its own event queue. It is possible to get the OXF event queues of both the main thread and active threads and periodically list their contents. You can then check the queue for specific events (user-defined events or framework events such as timeouts). This can be done programmatically from within your application.

 

1) The Main Thread

 

You can get the main thread using 
 

OMThread* theMainThread = OMMainThread::instance();

 

You can then get its event queue with:

 

const OMEventQueue* eventQueue = theMainThread->getEventQueue();

 

2) Active Threads

 

OR you can get the event queue of a forked thread from within your active class using:

 

const OMEventQueue* eventQueue = OMThread::getEventQueue();

 

3) Using the OMEventQueue object

 

Now the process for obtaining the list of pending events in the queue is the same:

 

OMEventListType messageList;
eventQueue.getMessageList(messageList);

 

At this point it is good practice to check if the list is empty. We can do this with a call to:

 

messageList.isEmpty();

 

Finally we can iterate the list and print the ID of each event:

 

OMEventQueueIter iter(messageList);
for ( ; (*iter) != 0; ++iter)
{
    IOxfEvent* ev = statsi_cast<IOxfEvent*>(*iter);
    std::cout << ev->getId() << std::endl;
}

 

4) Checking event IDs

 

OXF Framework-defined events - such as timeouts and null-transition events - are defined in OXFEvents.h (located in the Share/LangCpp/oxf directory).
Note that these framework-defined IDs all have negative numbers. 

 

OXFEVENTSH

 

 

User-defined events - those events created in the model and used in statecharts with the "GEN" macro calls - are defined in their package header file.
Note that user-defined events have large positive numbers.

 

USEREVENTS

 

 

For each IOxfEvent that is found in the event queue, we can use IOxfEvent::getId() to check if this is a known framework-defined event from the OXF or a user-defined event from the project:

 

GETID

 

Here is an example of a running executable that prints the contents of the event queue of the active class (the name of each event with its ID/Type).

 

ActiveEventQueue

 

 

 

Example Projects:

ActiveEventMonitor.zip - The active class to be monitored inherits an operation that monitors the event queue within its own thread and display it to the console.

NonActiveEventMonitor.zip - All project events are monitored and displayed to the console.

Please note these projects were created in Rhapsody 8.3.1

[{"Business Unit":{"code":"BU055","label":"Cognitive Applications"},"Product":{"code":"SS7P9W","label":"Rational Rhapsody"},"Component":"","Platform":[{"code":"PF033","label":"Windows"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Document Information

Modified date:
17 October 2018

UID

ibm10735535