ALMA Computing Group

acsexmplClientFridgeNC.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 *    ALMA - Atacama Large Millimiter Array
00003 *    (c) NRAO, 2003
00004 *    Copyright by NRAO (in the framework of the ALMA collaboration)
00005 *    All rights reserved
00006 *
00007 *    This library is free software; you can redistribute it and/or
00008 *    modify it under the terms of the GNU Lesser General Public
00009 *    License as published by the Free Software Foundation; either
00010 *    version 2.1 of the License, or (at your option) any later version.
00011 *
00012 *    This library is distributed in the hope that it will be useful,
00013 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 *    Lesser General Public License for more details.
00016 *
00017 *    You should have received a copy of the GNU Lesser General Public
00018 *    License along with this library; if not, write to the Free Software
00019 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 *
00021 *
00022 * "@(#) $Id: acsexmplClientFridgeNC.cpp,v 1.12 2008/07/27 15:10:49 cparedes Exp $"
00023 *
00024 * who       when      what
00025 * --------  --------  ----------------------------------------------
00026 * david 2003-02-13   created
00027 */
00046 
00051 
00085 /* @}*/
00086 /* @}*/
00088 #include <maciSimpleClient.h>
00089 #include <acsncSimpleConsumer.h>
00090 #include "acsexmplFridgeC.h"
00092 ACE_RCSID(acsexmpl, acsexmplFridgeNCClient, "$Id: acsexmplClientFridgeNC.cpp,v 1.12 2008/07/27 15:10:49 cparedes Exp $")
00093 //-----------------------------------------------------------------------------
00094 
00095 
00104 void myHandlerFunction(FRIDGE::temperatureDataBlockEvent joe, void *handlerParam)
00105 {
00106     int *eventCount = (int *)handlerParam;
00107 
00108     if (*eventCount < 5)
00109         {
00110         ACS_SHORT_LOG((LM_INFO, "::myHandlerFunction(...): %f is the tempdiff.",
00111                        joe.absoluteDiff));
00112         }
00113     (*eventCount)++;
00114 }
00115 /*******************************************************************************/
00118 int main(int argc, char *argv[])
00119 {
00120     ACS_SHORT_LOG((LM_INFO, "Welcome to %s!", argv[0]));
00121         
00122     //Creates and initializes the SimpleClient object
00123     maci::SimpleClient client;    
00124     
00125     int eventCount = 0;
00126 
00127     try
00128         {
00129         if (client.init(argc,argv) == 0)
00130             {
00131             ACE_DEBUG((LM_DEBUG,"Cannot init client"));
00132             return -1;
00133             }
00134         else
00135             {
00136             //Must log into manager before we can really do anything
00137             client.login();
00138             }
00139 
00140         // Create consumer
00141         //First initialize a SimpleConsumer pointer to 0.
00142         nc::SimpleConsumer<FRIDGE::temperatureDataBlockEvent> *simpConsumer_p=0;
00143         //Pass the pointer, event data type, channel name, and a handler function
00144         //to an ACS macro which initializes the consumer.
00145         ACS_NEW_SIMPLE_CONSUMER(simpConsumer_p, FRIDGE::temperatureDataBlockEvent, FRIDGE::CHANNELNAME_FRIDGE, myHandlerFunction, (void *)&eventCount);
00146 
00147         std::cout << "created a consumer" << std::endl;
00148         //Let the channel know we are ready to begin processing events
00149         simpConsumer_p->consumerReady();
00150 
00151         //Give the Consumer 50 seconds to process as many events as it can.
00152         ACE_Time_Value tv(50);
00153         client.run(tv);
00154         
00155         // Delete the objects or the TAO Notification Service will become 
00156         // corrupted.
00157         simpConsumer_p->disconnect(); 
00158         simpConsumer_p=0;
00159         ACS_SHORT_LOG((LM_INFO,"Releasing..."));
00160         } 
00161     catch(...)
00162         {
00163         ACS_SHORT_LOG((LM_ERROR, "main"));
00164         }
00165     
00166     //Sleep so the test will be deterministic.
00167     client.logout();
00168     ACE_OS::sleep(5);
00169     return 0;
00170 }
00174 /*___oOo___*/
00175 
00176 
00177