Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagecpp
titleACS/LGPL/CommonSoftware/acsexmpl/ws/src/acsexmplFridgeImpl.cpp
linenumberstrue
#include <acsexmplFridgeS.h>
#include <acsncSimpleSupplier.h>

nc::SimpleSupplier {}m_FridgeSupplier_p* = 0;

m_FridgeSupplier_p = new nc::SimpleSupplier(FRIDGE::CHANNELNAME_FRIDGE,
											this);


FRIDGE::temperatureDataBlockEvent t_data;
t_data.absoluteDiff = (double)0.0;
t_data.status = FRIDGE::ATREF;

m_FridgeSupplier_p->publishData<FRIDGE::temperatureDataBlockEvent>(t_data);

if (m_FridgeSupplier_p)
{
	m_FridgeSupplier_p->disconnect();
	m_FridgeSupplier_p=0;
}

...

1

A user-defined IDL structure is packed into all events. Therefore, the stub header must be included.

4

Declare a pointer for the SimpleSupplier class.

6-7

Create and initialize the SimpleSupplier instance.

6

The channel events will be published on.

7

A pointer to an ACSComponentImpl is needed to pack the component's name into the event.

9

Create a new temperatureDataBlockEvent that will be packed into an event.

10-11

Fill the fields of the temperatureDataBlockEvent with arbitrary data.

13

publishData is a blocking call that actually sends the structured event to consumers. The template parameter is identical to the type of data being published.

15-19

It is necessary to disconnect from the channel after we are done sending events to prevent remote memory leaks from occurring. One should never delete the Supplier directly as it's a CORBA object.

...

...

C++ Consumer

A C++ SimpleConsumer utilizes a handler function for a single event type and does not have to be overridden. C++ Consumer objects need to be instantiated from within the context of a component or after a MACI SimpleClient has been created.

...

Example

The following depicts the usage of a SimpleConsumer. As always, bolded text should be adapted for your particular needs and error handling has been omitted.
ACS/LGPL/CommonSoftware/acsexmpl/ws/src/acsexmplClientFridgeNC.cpp:



Code Block
languagecpp
titleACS/LGPL/CommonSoftware/acsexmpl/ws/src/acsexmplClientFridgeNC.cpp
linenumberstrue
#include "acsexmplFridgeC.h"

...


//…

...


//-----------------------------------------------------------------------------

...


void myHandlerFunction(FRIDGE::temperatureDataBlockEvent joe, void *other)

...


{

...


ACS_SHORT_LOG((LM_INFO, "::myHandlerFunction(...): %f is the tempdiff.",

...


joe.absoluteDiff));

...


}

...


//-----------------------------------------------------------------------------

...


//…

...



nc::

...

SimpleConsumer<FRIDGE::

...

temperatureDataBlockEvent> {}simpConsumer_p{*}=0;

...


ACS_NEW_SIMPLE_CONSUMER(simpConsumer_p,

...


						FRIDGE::temperatureDataBlockEvent,

...


						FRIDGE::CHANNELNAME_FRIDGE,

...


						myHandlerFunction,

...


						(void *)0);

...



simpConsumer_p->consumerReady();

...



ACE_Time_Value time(150);

...


client.run(time);

...


simpConsumer_p->disconnect(); simpConsumer_p=0;

...


//…


1

The client header stub generated by the IDL compiler is used to insert and extract user-defined IDL structures to and from CORBA Any's.

4-8

myHandlerFunction is a void function designed to manipulate one type of IDL struct/event, a temperatureDataBlockEvent. Each time a temperatureDataBlockEvent event is received, SimpleConsumer will call this function.

4

Handler functions must not return any value and shall take in two parameters: the user-defined IDL structure defining ICD events and a void * whose value will always be identical to the void * on line 17.

6-7

Do something useful with the event.

12-17

A SimpleConsumer instance is created. Note that the ACS_NEW_SIMPLE_CONSUMER macro must be used to do this!

12

Create a SimpleConsumer pointer using the event type FRIDGE::temperatureDataBlockEvent for the templated parameter.

13

simpConsumer_p is a pointer to an unallocated SimpleConsumer.

14

The second parameter is the type of event to be received (i.e., a user-defined IDL struct). SimpleConsumers are only capable of receiving and processing a single type.

15

The name of the channel we will subscribe too. In this case it's the "fridge" channel.

16

This function will be invoked each time an event is received.

17

A void * that will be sent to the handler function (line 4) each time an event is received. It can very useful to pass in an object for the void * which will perform some operation on the event from the handler function.

18

Tell the channel we are ready to begin consuming events.

20-22

Run this example for 150 seconds and then disconnect the consumer from the channel.

22

Disconnect from the channel to prevent remote memory leaks from occurring. Do not delete the Consumer!

...


Python Supplier

Python suppliers are very powerful in the fact that they do not have to be subclassed and act as SimpleSupplier's.

...

Example

The following depicts the full implementation of a Supplier which publishes one event and then disconnects from the channel. As always, bolded text should be adapted for your particular needs and error handling has been omitted.
ACS/LGPL/CommonSoftware/acspyexmpl/src/acspyexmplFridgeNCSupplier.py

...