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

ProxyPullSupplier.cc

Go to the documentation of this file.
00001 //                            Package   : omniEvents
00002 // ProxyPullSupplier.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 "ProxyPullSupplier.h"
00025 #include "Orb.h"
00026 #include "omniEventsLog.h"
00027 
00028 #define DB(l,x) ((omniORB::traceLevel >= l) && (cerr << x << endl))
00029 
00030 namespace OmniEvents {
00031 
00032 //
00033 //  ProxyPullSupplierManager
00034 //
00035 
00036 PortableServer::Servant ProxyPullSupplierManager::incarnate(
00037   const PortableServer::ObjectId& oid,
00038   PortableServer::POA_ptr         poa
00039 )
00040 {
00041   // ?? Check that OID is valid here.
00042   ProxyPullSupplier_i* result =new ProxyPullSupplier_i(_managedPoa,_queue);
00043   _servants.insert(result);
00044   return result;
00045 }
00046 
00047 ProxyPullSupplierManager::ProxyPullSupplierManager(
00048   PortableServer::POA_ptr parentPoa,
00049   EventQueue&             q
00050 )
00051 : ProxyManager(parentPoa,"ProxyPullSupplier"),
00052   _queue(q)
00053 {
00054   // pass
00055 }
00056 
00057 CosEventChannelAdmin::ProxyPullSupplier_ptr
00058 ProxyPullSupplierManager::createObject()
00059 {  
00060   return createNarrowedReference<CosEventChannelAdmin::ProxyPullSupplier>(
00061            _managedPoa,
00062            CosEventChannelAdmin::_tc_ProxyPullSupplier->id()
00063          );
00064 }
00065 
00066 
00067 //
00068 //  ProxyPullSupplier_i
00069 //
00070 
00071 // CORBA interface methods
00072 
00073 void ProxyPullSupplier_i::connect_pull_consumer(
00074   CosEventComm::PullConsumer_ptr pullConsumer
00075 )
00076 {
00077   try
00078   {
00079     if(CORBA::is_nil(pullConsumer))
00080         throw CORBA::BAD_PARAM();
00081     if(!CORBA::is_nil(_target) || !CORBA::is_nil(_req))
00082         throw CosEventChannelAdmin::AlreadyConnected();
00083     _target=CosEventComm::PullConsumer::_duplicate(pullConsumer);
00084 
00085     omniEventsLog::persist();
00086   }
00087   catch(...)
00088   {
00089     _target=CosEventComm::PullConsumer::_nil();
00090     deactivateObject();
00091     throw;
00092   }
00093 }
00094 
00095 void ProxyPullSupplier_i::disconnect_pull_supplier()
00096 {
00097   DB(5,"ProxyPullSupplier_i::disconnect_pull_supplier()");
00098   deactivateObject();
00099   if(CORBA::is_nil(_target))
00100   {
00101     throw CORBA::BAD_INV_ORDER(
00102       omni::BAD_INV_ORDER_RequestUsedMoreThanOnce,
00103       CORBA::COMPLETED_YES
00104     );
00105   }
00106   else
00107   {
00108     CORBA::Request_var req=_target->_request("disconnect_pull_consumer");
00109     req->send_deferred();
00110     Orb::inst().orphanRequest(req._retn());
00111     _target=CosEventComm::PullConsumer::_nil();
00112   }
00113 }
00114 
00115 CORBA::Any* ProxyPullSupplier_i::pull()
00116 {
00117   if(moreEvents())
00118       return new CORBA::Any(*nextEvent());
00119   else
00120       throw CORBA::TRANSIENT(
00121         omni::TRANSIENT_CallTimedout,
00122         CORBA::COMPLETED_NO
00123       );
00124 }
00125 
00126 CORBA::Any* ProxyPullSupplier_i::try_pull(CORBA::Boolean& has_event)
00127 {
00128   if(moreEvents())
00129   {
00130     has_event=1;
00131     return new CORBA::Any(*nextEvent());
00132   }
00133   else
00134   {
00135     has_event=0;
00136     return new CORBA::Any();
00137   }
00138 }
00139 
00140 //
00141 
00142 ProxyPullSupplier_i::ProxyPullSupplier_i(
00143   PortableServer::POA_ptr poa,
00144   EventQueue& q
00145 )
00146 : Proxy(poa),
00147   EventQueue::Reader(q),
00148   _target(CosEventComm::PullConsumer::_nil())
00149 {
00150   // pass
00151 }
00152 
00153 void ProxyPullSupplier_i::reincarnate(const OEP_prxy& prxy)
00154 {
00155   CosEventComm::PullConsumer_var pullConsumer =
00156     string_to_<CosEventComm::PullConsumer>(prxy.getIor());
00157   // Do not activate until we know that we have read a valid target.
00158   activateObjectWithId(prxy.getKey());
00159   connect_pull_consumer(pullConsumer.in());
00160 }
00161 
00162 void ProxyPullSupplier_i::output(ostream& os)
00163 {
00164   Output out =basicOutput(os,"pxyPullSupplier",3,this,_target.in());
00165 }
00166 
00167 
00168 }; // end namespace OmniEvents

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