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 "ProxyPushConsumer.h"
00025 #include "Orb.h"
00026 #include "omniEventsLog.h"
00027
00028 #include <assert.h>
00029
00030 #define DB(l,x) ((omniORB::traceLevel >= l) && (cerr << x << endl))
00031
00032 namespace OmniEvents {
00033
00034 void ProxyPushConsumer_i::connect_push_supplier(
00035 CosEventComm::PushSupplier_ptr pushSupplier)
00036 {
00037
00038 if(CORBA::is_nil(pushSupplier))
00039 return;
00040
00041 ObjectId oid =currentObjectId();
00042 Connections_t::iterator pos =_connections.find(oid);
00043
00044 if(pos!=_connections.end())
00045 throw CosEventChannelAdmin::AlreadyConnected();
00046
00047 _connections.insert(Connections_t::value_type(
00048 oid,
00049 CosEventComm::PushSupplier::_duplicate(pushSupplier)
00050 ));
00051
00052 omniEventsLog::persist();
00053 }
00054
00055
00056 void ProxyPushConsumer_i::disconnect_push_consumer()
00057 {
00058 DB(5,"ProxyPushConsumer_i::disconnect_push_consumer()");
00059 ObjectId oid =currentObjectId();
00060 Connections_t::iterator pos =_connections.find(oid);
00061
00062 if(pos!=_connections.end())
00063 {
00064 CORBA::Request_var req =
00065 pos->second->_request("disconnect_push_supplier");
00066 req->send_oneway();
00067 _connections.erase(pos);
00068 }
00069 }
00070
00071
00072 void ProxyPushConsumer_i::push(const CORBA::Any& event)
00073 {
00074 _queue.push_back(new CORBA::Any(event));
00075 }
00076
00077
00078 ProxyPushConsumer_i::ProxyPushConsumer_i(
00079 PortableServer::POA_ptr p,
00080 list<CORBA::Any*>& q
00081 )
00082 : Servant(PortableServer::POA::_nil()),
00083 _connections(),
00084 _queue(q)
00085 {
00086 using namespace PortableServer;
00087 try
00088 {
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 CORBA::PolicyList policies;
00099 policies.length(7);
00100 policies[0]=p->create_lifespan_policy(PERSISTENT);
00101 policies[1]=p->create_id_assignment_policy(USER_ID);
00102 policies[2]=p->create_id_uniqueness_policy(MULTIPLE_ID);
00103 policies[3]=p->create_implicit_activation_policy(NO_IMPLICIT_ACTIVATION);
00104 policies[4]=p->create_request_processing_policy(USE_DEFAULT_SERVANT);
00105 policies[5]=p->create_servant_retention_policy(NON_RETAIN);
00106 policies[6]=p->create_thread_policy(SINGLE_THREAD_MODEL);
00107
00108
00109 CORBA::String_var parentName =p->the_name();
00110 string poaName =string(parentName.in())+".ProxyPushConsumer";
00111 POAManager_var parentManager =p->the_POAManager();
00112 _poa=p->create_POA(poaName.c_str(),parentManager.in(),policies);
00113 }
00114 catch(POA::AdapterAlreadyExists& ex)
00115 {
00116 cerr<<"POA::AdapterAlreadyExists"<<endl;
00117 }
00118 catch(POA::InvalidPolicy& ex)
00119 {
00120 cerr<<"POA::InvalidPolicy: "<<ex.index<<endl;
00121 }
00122
00123 _poa->set_servant(this);
00124 }
00125
00126
00127 ProxyPushConsumer_i::~ProxyPushConsumer_i()
00128 {
00129
00130 }
00131
00132
00133 CosEventChannelAdmin::ProxyPushConsumer_ptr
00134 ProxyPushConsumer_i::createObject()
00135 {
00136 return createNarrowedReference<CosEventChannelAdmin::ProxyPushConsumer>(
00137 _poa,
00138 CosEventChannelAdmin::_tc_ProxyPushConsumer->id()
00139 );
00140 }
00141
00142
00143 void ProxyPushConsumer_i::reincarnate(
00144 const char* thisOid,
00145 const char* supplierIOR
00146 )
00147 {
00148 ObjectId oid(thisOid);
00149
00150 Connections_t::iterator pos =_connections.find(oid);
00151 if(pos!=_connections.end())
00152 throw CosEventChannelAdmin::AlreadyConnected();
00153
00154 CosEventComm::PushSupplier_var pushSupplier;
00155 try
00156 {
00157 CORBA::Object_ptr obj =Orb::inst()._orb->string_to_object(supplierIOR);
00158 pushSupplier=CosEventComm::PushSupplier::_narrow(obj);
00159 }
00160 catch(...)
00161 {
00162 }
00163
00164 if(CORBA::is_nil(pushSupplier))
00165 throw CORBA::BAD_PARAM();
00166
00167 _connections.insert(Connections_t::value_type(
00168 oid,
00169 pushSupplier._retn()
00170 ));
00171 }
00172
00173
00174 void ProxyPushConsumer_i::output(ostream& os) const
00175 {
00176 for(Connections_t::const_iterator i=_connections.begin();
00177 i!=_connections.end();
00178 ++i)
00179 {
00180 os << "\t\t\tpxyPushConsumer\n"
00181 << "\t\t\t{\n"
00182 << "\t\t\t\tKEY\t" << i->first._str << "\n";
00183 if(!CORBA::is_nil(i->second.in()))
00184 {
00185 CORBA::String_var iorstr;
00186 iorstr = Orb::inst()._orb->object_to_string(i->second.in());
00187 os << "\t\t\t\tIOR\t" << iorstr << "\n";
00188 }
00189 os << "\t\t\t}\n";
00190 }
00191 }
00192
00193
00194 ProxyPushConsumer_i::ObjectId
00195 ProxyPushConsumer_i::currentObjectId() const
00196 {
00197 ProxyPushConsumer_i::ObjectId result;
00198 try
00199 {
00200 using namespace PortableServer;
00201 result._oid=Orb::inst()._POACurrent->get_object_id();
00202 CORBA::String_var oidStr =ObjectId_to_string(result._oid.in());
00203 result._str=string(oidStr.in());
00204 }
00205 catch(PortableServer::Current::NoContext ex)
00206 {
00207 cerr<<"No context!!"<<endl;
00208 }
00209 catch(CORBA::BAD_PARAM ex)
00210 {
00211
00212 assert(0);
00213 }
00214 return result;
00215 }
00216
00217
00218
00219
00220
00221
00222 ProxyPushConsumer_i::ObjectId::ObjectId(const char* str)
00223 : _str(str)
00224 {
00225 _oid=PortableServer::string_to_ObjectId(_str.c_str());
00226 }
00227
00228
00229 };