00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00077 if(!caps.getProxyPushSuppliers().empty())
00078 {
00079 _pushSupplier=new ProxyPushSupplierManager(_poa,_queue);
00080 _pushSupplier->reincarnate(caps.getProxyPushSuppliers());
00081 }
00082
00083
00084 if(!caps.getProxyPullSuppliers().empty())
00085 {
00086 _pullSupplier=new ProxyPullSupplierManager(_poa,_queue);
00087 _pullSupplier->reincarnate(caps.getProxyPullSuppliers());
00088 }
00089
00090
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();
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 };