Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

ConsumerAdmin.cc

Go to the documentation of this file.
00001 //                            Package   : omniEvents
00002 // ConsumerAdmin.cc           Created   : 2003/12/04
00003 //                            Author    : Alex Tingle
00004 //
00005 //    Copyright (C) 2003 Alex Tingle.
00006 //
00007 //    This file is part of the omniEvents application.
00008 //
00009 //    omniEvents is free software; you can redistribute it and/or
00010 //    modify it under the terms of the GNU Lesser General Public
00011 //    License as published by the Free Software Foundation; either
00012 //    version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //    omniEvents is distributed in the hope that it will be useful,
00015 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //    Lesser General Public License for more details.
00018 //
00019 //    You should have received a copy of the GNU Lesser General Public
00020 //    License along with this library; if not, write to the Free Software
00021 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 
00024 #include "ConsumerAdmin.h"
00025 
00026 #include "EventChannel.h"
00027 #include "ProxyPushSupplier.h"
00028 #include "ProxyPullSupplier.h"
00029 #include "oep_types.h"
00030 
00031 #define DB(l,x) ((omniORB::traceLevel >= l) && (cerr << x << endl))
00032 
00033 namespace OmniEvents {
00034 
00035 CosEventChannelAdmin::ProxyPushSupplier_ptr
00036 ConsumerAdmin_i::obtain_push_supplier()
00037 {
00038   if(!_pushSupplier)
00039       _pushSupplier=new ProxyPushSupplierManager(_poa,_queue);
00040   return _pushSupplier->createObject();
00041 }
00042 
00043 
00044 CosEventChannelAdmin::ProxyPullSupplier_ptr
00045 ConsumerAdmin_i::obtain_pull_supplier()
00046 {
00047   if(!_pullSupplier)
00048       _pullSupplier=new ProxyPullSupplierManager(_poa,_queue);
00049   return _pullSupplier->createObject();
00050 }
00051 
00052 
00053 ConsumerAdmin_i::ConsumerAdmin_i(
00054   const EventChannel_i&   channel,
00055   PortableServer::POA_ptr poa
00056 )
00057 : Servant(poa),
00058   _queue(channel.maxQueueLength()),
00059   _pushSupplier(NULL),
00060   _pullSupplier(NULL)
00061 {
00062   activateObjectWithId("ConsumerAdmin");
00063 }
00064 
00065 
00066 ConsumerAdmin_i::ConsumerAdmin_i(
00067   const EventChannel_i&   channel,
00068   PortableServer::POA_ptr poa,
00069   const OEP_caps&         caps
00070 )
00071 : Servant(poa),
00072   _queue(channel.maxQueueLength()),
00073   _pushSupplier(NULL),
00074   _pullSupplier(NULL)
00075 {
00076   // Build Push Supplier proxies
00077   if(!caps.getProxyPushSuppliers().empty())
00078   {
00079     _pushSupplier=new ProxyPushSupplierManager(_poa,_queue);
00080     _pushSupplier->reincarnate(caps.getProxyPushSuppliers());
00081   }
00082 
00083   // Build Pull Supplier proxies
00084   if(!caps.getProxyPullSuppliers().empty())
00085   {
00086     _pullSupplier=new ProxyPullSupplierManager(_poa,_queue);
00087     _pullSupplier->reincarnate(caps.getProxyPullSuppliers());
00088   }
00089 
00090   // Reactivate this servant.
00091   activateObjectWithId(caps.getKey());
00092 }
00093 
00094 
00095 ConsumerAdmin_i::~ConsumerAdmin_i()
00096 {
00097   if(_pushSupplier)
00098   {
00099     delete _pushSupplier;
00100     _pushSupplier=NULL;
00101   }
00102   if(_pullSupplier)
00103   {
00104     delete _pullSupplier;
00105     _pullSupplier=NULL;
00106   }
00107 }
00108 
00109 
00110 void ConsumerAdmin_i::send(list<CORBA::Any*>& events)
00111 {
00112   DB(20,"+ ConsumerAdmin_i::send() New events: "<<events.size());
00113   if(_pushSupplier)
00114   {
00115     {
00116       omni_mutex_lock l(_pushSupplier->_lock);
00117       _queue.append(events);
00118     }
00119     _pushSupplier->_condition.signal(); // Wake up the thread if it's asleep.
00120   }
00121   else
00122   {
00123     _queue.append(events);
00124   }
00125 }
00126 
00127 
00128 void ConsumerAdmin_i::discard(list<CORBA::Any*>& events)
00129 {
00130   for(list<CORBA::Any*>::const_iterator i=events.begin();
00131       i!=events.end();
00132       ++i)
00133   {
00134     delete (*i);
00135   }
00136   events.clear();
00137 }
00138 
00139 
00140 void ConsumerAdmin_i::output(ostream& os)
00141 {
00142   Output out(basicOutput(os,"consumerAdmin",2,this));
00143   if(_pushSupplier)
00144      _pushSupplier->output(os);
00145   if(_pullSupplier)
00146      _pullSupplier->output(os);
00147 }
00148 
00149 
00150 }; // end namespace OmniEvents

Generated on Fri Dec 12 10:53:02 2003 for OmniEvents by doxygen1.2.15