Versions Compared

Key

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

...

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!

...

Code Block
languagepy
titleACS/LGPL/CommonSoftware/acspyexmpl/src/acspyexmplFridgeNCConsumer.py
linenumberstrue
#!/usr/bin/env python
from time import sleep
import FRIDGE
from Acspy.Nc.Consumer import Consumer
#------------------------------------------------------------------------------
def fridgeDataHandler(some_param):
    tempDiff = some_param.absoluteDiff
    print 'The temperature difference is', tempDiff
    return
#------------------------------------------------------------------------------
g = Consumer(FRIDGE.CHANNELNAME_FRIDGE)
g.addSubscription(FRIDGE.temperatureDataBlockEvent, fridgeDataHandler)
g.consumerReady()
sleep(50)
g.disconnect()
#---------------------------------------------------------------------------

...