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

EventChannelFactory.cc

Go to the documentation of this file.
00001 // -*- Mode: C++; -*-
00002 //                            Package   : omniEvents
00003 // EventChannelFactory_i.cc   Created   : 1/4/98
00004 //                            Author    : Paul Nader (pwn)
00005 //
00006 //    Copyright (C) 1998 Paul Nader.
00007 //
00008 //    This file is part of the omniEvents application.
00009 //
00010 //    omniEvents is free software; you can redistribute it and/or
00011 //    modify it under the terms of the GNU Lesser General Public
00012 //    License as published by the Free Software Foundation; either
00013 //    version 2.1 of the License, or (at your option) any later version.
00014 //
00015 //    omniEvents is distributed in the hope that it will be useful,
00016 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 //    Lesser General Public License for more details.
00019 //
00020 //    You should have received a copy of the GNU Lesser General Public
00021 //    License along with this library; if not, write to the Free Software
00022 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // Description:
00025 //      Implementation of the COSS Event Services Event Channel Factory
00026 //      
00027 
00028 #include "EventChannelFactory.h"
00029 
00030 #include "Orb.h"
00031 #include "EventChannel.h"
00032 #include "omniEventsLog.h"
00033 
00034 #define DB(l,x) ((omniORB::traceLevel >= l) && (cerr << x << endl))
00035 
00036 namespace OmniEvents {
00037 
00038 //------------------------------------------------------------------------
00039 //           Event Channel Factory Interface Implementation
00040 //------------------------------------------------------------------------
00041 EventChannelFactory_i::EventChannelFactory_i(unsigned int port)
00042 : Servant(Orb::inst()._omniINSPOA.in()),
00043   _port(port)
00044 {
00045   activateObjectWithId("omniEvents");
00046 }
00047 
00048 
00049 EventChannelFactory_i::EventChannelFactory_i(
00050   unsigned int port,
00051   OepEcpsList& channels
00052 )
00053 : Servant(Orb::inst()._omniINSPOA.in()),
00054   _port(port)
00055 {
00056   // Create event channels
00057   for(OepEcpsList::iterator i=channels.begin(); i!=channels.end(); i++)
00058   {
00059     EventChannel_i *channel =new EventChannel_i((*i)->getKey(),**i);
00060     channel->start();
00061     _eventChannels.insert(channel);
00062   }
00063   activateObjectWithId("omniEvents");
00064 }
00065 
00066 
00067 CORBA::Boolean
00068 EventChannelFactory_i::supports(const CosLifeCycle::Key &k)
00069 {
00070   if((k.length() == 1) &&
00071      (strcmp(k[0].id, "EventChannel") == 0) &&
00072      (strcmp(k[0].kind, "object interface") == 0))
00073     return 1;
00074   else
00075     return 0;
00076 }
00077 
00078 
00079 CORBA::Object_ptr
00080 EventChannelFactory_i::create_object(
00081   const CosLifeCycle::Key &k,
00082   const CosLifeCycle::Criteria &criteria
00083 )
00084 {
00085   // Check the key
00086   if (! this->supports(k))
00087      throw CosLifeCycle::NoFactory(k);
00088 
00089   CORBA::String_var channelIdStr =newUniqueId();
00090   EventChannel_i* channel =new EventChannel_i(channelIdStr.in());
00091 
00092   // Process criteria
00093   for(CORBA::ULong i=0; i<criteria.length(); i++)
00094   {
00095     if(strcmp(criteria[i].name, "PullRetryPeriod") == 0)
00096     {
00097       CORBA::ULong pullRetryPeriod;
00098       if(! (criteria[i].value >>= pullRetryPeriod))
00099           throw CosLifeCycle::InvalidCriteria(criteria);
00100       if(pullRetryPeriod <= 0)
00101           throw CosLifeCycle::CannotMeetCriteria(criteria);
00102       channel->setPullRetryPeriod(pullRetryPeriod);
00103     }
00104     else if(strcmp(criteria[i].name, "MaxQueueLength") == 0)
00105     {
00106       CORBA::ULong maxQueueLength;
00107       if(! (criteria[i].value >>= maxQueueLength))
00108           throw CosLifeCycle::InvalidCriteria(criteria);
00109       if(maxQueueLength > 0)
00110           channel->setMaxQueueLength(maxQueueLength);
00111       else
00112           DB(1,"Ignoring CosLifeCycle criterion: MaxQueueLength=0");
00113     }
00114     else
00115         DB(1,"Ignoring unknown CosLifeCycle criterion: "<<criteria[i].name);
00116   }
00117 
00118   channel->start();
00119   _eventChannels.insert(channel);
00120 
00121   omniEventsLog::persist();
00122   return channel->_this();
00123 }
00124 
00125 
00126 void
00127 EventChannelFactory_i::output(ostream &os)
00128 {
00129   PortableServer::ObjectId_var oid=_poa->servant_to_id(this);
00130   CORBA::String_var oidStr =PortableServer::ObjectId_to_string(oid.in());
00131 
00132   os << "channelFactory\n{\n"
00133      << "\tPORT\t" << _port << "\n"
00134      << "\tKEY\t" << oidStr.in() << "\n";
00135 
00136   for(set<EventChannel_i*>::iterator i=_eventChannels.begin();
00137       i!=_eventChannels.end();
00138       ++i)
00139   {
00140      os << "\n";
00141      (*i)->output(os);
00142   }
00143 
00144   os << "\n}\n";
00145 }
00146 
00147 
00148 }; // end namespace OmniEvents

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