[Pkg-corba-commits] r68 - in /trunk/omnievents/src: ./ PersistNode.cc Servant.cc main.cc

tgg at users.alioth.debian.org tgg at users.alioth.debian.org
Thu Nov 29 21:15:18 UTC 2007


Author: tgg
Date: Thu Nov 29 21:15:18 2007
New Revision: 68

URL: http://svn.debian.org/wsvn/pkg-corba/?sc=1&rev=68
Log:
add patched files fixing #424376

Added:
    trunk/omnievents/src/
    trunk/omnievents/src/PersistNode.cc
    trunk/omnievents/src/Servant.cc
    trunk/omnievents/src/main.cc

Added: trunk/omnievents/src/PersistNode.cc
URL: http://svn.debian.org/wsvn/pkg-corba/trunk/omnievents/src/PersistNode.cc?rev=68&op=file
==============================================================================
--- trunk/omnievents/src/PersistNode.cc (added)
+++ trunk/omnievents/src/PersistNode.cc Thu Nov 29 21:15:18 2007
@@ -1,0 +1,180 @@
+//                            Package   : omniEvents
+// PersistNode.cc             Created   : 2004/04/29
+//                            Author    : Alex Tingle
+//
+//    Copyright (C) 2004 Alex Tingle.
+//
+//    This file is part of the omniEvents application.
+//
+//    omniEvents is free software; you can redistribute it and/or
+//    modify it under the terms of the GNU Lesser General Public
+//    License as published by the Free Software Foundation; either
+//    version 2.1 of the License, or (at your option) any later version.
+//
+//    omniEvents is distributed in the hope that it will be useful,
+//    but WITHOUT ANY WARRANTY; without even the implied warranty of
+//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//    Lesser General Public License for more details.
+//
+//    You should have received a copy of the GNU Lesser General Public
+//    License along with this library; if not, write to the Free Software
+//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+
+#include "PersistNode.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <climits>
+
+namespace OmniEvents {
+
+
+PersistNode::PersistNode(istream& is)
+{
+  while( readnode(is) ){}
+}
+
+PersistNode::~PersistNode()
+{
+  for(map<string,PersistNode*>::iterator i=_child.begin(); i!=_child.end(); ++i)
+      delete i->second;
+}
+
+void PersistNode::output(ostream& os,string name) const
+{
+  if(!name.empty()) // Don't output root node.
+  {
+    os<<name<<'\n';
+    for(map<string,string>::const_iterator i=_attr.begin();
+        i!=_attr.end();
+        ++i)
+    {
+      os<<" "<<i->first<<"="<<i->second<<'\n';
+    }
+    os<<" ;;\n";
+    name+="/";
+  }
+  for(map<string,PersistNode*>::const_iterator i=_child.begin();
+      i!=_child.end();
+     ++i)
+  {
+    i->second->output(os,name+i->first);
+  }
+}
+
+
+inline bool PersistNode::readnode(istream& is)
+{
+  PersistNode* node =NULL;
+  string tok;
+  while(true)
+  {
+    if(!readtoken(is,tok) || tok==";;")
+        return bool(node);
+    else if(node)
+        node->addattr(tok);
+    else if(tok[0]=='-')
+        delnode(tok.substr(1));
+    else
+        node=addnode(tok);
+  }
+}
+
+inline bool PersistNode::readtoken(istream& is, string& tok)
+{
+  while(is)
+  {
+    is>>tok;
+    if(tok.empty())
+        break;
+    if(tok[0]!='#')
+        return true;
+    is.ignore(INT_MAX,'\n');
+  }
+  return false;
+}
+
+PersistNode* PersistNode::addnode(const string& name)
+{
+  string::size_type pos =name.find('/');
+  // get reference to Next node in the path.
+  PersistNode*& newchild =_child[name.substr(0,pos)];
+
+  if(pos==string::npos) // leaf: add new leaf.
+  {
+    if(newchild)
+        delete newchild; // overwrite old leaf (and its children)
+    newchild=new PersistNode();
+    return newchild;
+  }
+  else // branch: just add the branch if it's missing, and then recurse.
+  {
+    if(!newchild)
+        newchild=new PersistNode();
+    return newchild->addnode(name.substr(pos+1));
+  }
+}
+
+void PersistNode::delnode(const string& name)
+{
+  string::size_type pos =name.find('/');
+  // get reference to Next node in the path.
+  map<string,PersistNode*>::iterator childpos =_child.find(name.substr(0,pos));
+  if(childpos!=_child.end())
+  {
+    if(pos==string::npos) // leaf: delete leaf.
+    {
+      delete childpos->second;
+      _child.erase(childpos);
+    }
+    else // branch: recurse
+    {
+      childpos->second->delnode(name.substr(pos+1));
+    }
+  }
+}
+
+void PersistNode::addattr(const string& keyvalue)
+{
+  string::size_type pos =keyvalue.find('=');
+  _attr[keyvalue.substr(0,pos)]=(pos==string::npos?"":keyvalue.substr(pos+1));
+}
+
+void PersistNode::addattr(const string& key, long value)
+{
+  char buf[64];
+  sprintf(buf,"%i",value);
+  _attr[key]=string(buf);
+}
+
+bool PersistNode::hasAttr(const string& key) const
+{
+  return( _attr.find(key)!=_attr.end() );
+}
+string PersistNode::attrString(const string& key, const string& fallback) const
+{
+  map<string,string>::const_iterator pos=_attr.find(key);
+  if(pos==_attr.end())
+      return fallback;
+  else
+      return pos->second;
+}
+long PersistNode::attrLong(const string& key, long fallback) const
+{
+  map<string,string>::const_iterator pos=_attr.find(key);
+  if(pos==_attr.end())
+      return fallback;
+  else
+      return atol(pos->second.c_str());
+}
+PersistNode* PersistNode::child(const string& key) const
+{
+  map<string,PersistNode*>::const_iterator pos=_child.find(key);
+  if(pos==_child.end())
+      return NULL;
+  else
+      return pos->second;
+}
+
+}; // end namespace OmniEvents

Added: trunk/omnievents/src/Servant.cc
URL: http://svn.debian.org/wsvn/pkg-corba/trunk/omnievents/src/Servant.cc?rev=68&op=file
==============================================================================
--- trunk/omnievents/src/Servant.cc (added)
+++ trunk/omnievents/src/Servant.cc Thu Nov 29 21:15:18 2007
@@ -1,0 +1,213 @@
+//                            Package   : omniEvents
+// Servant.cc                 Created   : 2003/12/04
+//                            Author    : Alex Tingle
+//
+//    Copyright (C) 2003-2005 Alex Tingle.
+//
+//    This file is part of the omniEvents application.
+//
+//    omniEvents is free software; you can redistribute it and/or
+//    modify it under the terms of the GNU Lesser General Public
+//    License as published by the Free Software Foundation; either
+//    version 2.1 of the License, or (at your option) any later version.
+//
+//    omniEvents is distributed in the hope that it will be useful,
+//    but WITHOUT ANY WARRANTY; without even the implied warranty of
+//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//    Lesser General Public License for more details.
+//
+//    You should have received a copy of the GNU Lesser General Public
+//    License along with this library; if not, write to the Free Software
+//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+
+#include "Servant.h"
+#include "Orb.h"
+
+#ifdef HAVE_SYS_TYPES_H
+#  include <sys/types.h> // getpid
+#endif
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>    // getpid
+#elif defined(HAVE_PROCESS_H)
+# include <process.h>
+#endif
+
+#include <stdio.h>     // sprintf
+#include <cstdlib>
+#include <assert.h>
+
+#ifdef HAVE_IOSTREAM
+#  include <iostream>
+#else
+#  include <iostream.h>
+#endif
+
+#ifdef HAVE_STD_IOSTREAM
+using namespace std;
+#endif
+
+namespace OmniEvents {
+
+
+CORBA::Object_ptr createReference(
+  PortableServer::POA_ptr poa,          // POA to own new object
+  const char*             repositoryId  // e.g. _tc_ProxyPushSupplier->id()
+)
+{
+  CORBA::String_var oidStr =newUniqueId();
+
+  PortableServer::ObjectId_var oid =
+    PortableServer::string_to_ObjectId(oidStr.in());
+
+  CORBA::Object_var obj =
+    poa->create_reference_with_id(oid.in(),repositoryId);
+
+  assert(!CORBA::is_nil(obj));
+  return obj._retn();
+}
+
+char* newUniqueId()
+{
+  static long  count=0;
+  static omni_mutex  mutex;
+  int  mypid =getpid(); // MS VC++6 doesn't have type pid_t!
+  unsigned long  sec,nsec;
+  omni_thread::get_time(&sec,&nsec); // More portable than just time().
+  char buf[128];
+  {
+    omni_mutex_lock l(mutex);
+    sprintf(buf,"%lx.%d.%lx",++count,mypid,sec);
+  }
+  return CORBA::string_dup(buf);
+}
+
+
+//
+//  Servant
+//
+
+
+#if OMNIEVENTS__DEBUG_SERVANT
+#  define OMNIEVENTS__ADDR "["<<long(this)<<"] "
+int Servant::_objectCount =0;
+#else
+#  define OMNIEVENTS__ADDR
+#endif
+
+
+Servant::Servant(PortableServer::POA_ptr poa)
+: _poa(PortableServer::POA::_duplicate(poa))
+{
+#if OMNIEVENTS__DEBUG_SERVANT
+  ++_objectCount;
+  DB(21,OMNIEVENTS__ADDR "Servant::Servant() count="<<_objectCount)
+#endif
+}
+
+
+Servant::~Servant()
+{
+#if OMNIEVENTS__DEBUG_SERVANT
+  --_objectCount;
+  DB(20,OMNIEVENTS__ADDR "Servant::~Servant() count="<<_objectCount)
+#endif
+}
+
+
+PortableServer::POA_ptr Servant::_default_POA()
+{
+  return PortableServer::POA::_duplicate(_poa.in());
+}
+
+
+void Servant::activateObjectWithId(const char* oidStr)
+{
+  using namespace PortableServer;
+  CORBA::String_var poaName =_poa->the_name();
+  DB(5,OMNIEVENTS__ADDR "Activating object "<<poaName.in()<<"/"<<oidStr);
+  try
+  {
+    ObjectId_var oid =string_to_ObjectId(oidStr);
+    _poa->activate_object_with_id(oid.in(),this);
+  }
+  catch(CORBA::BAD_PARAM& ex)
+  {
+    DB(0,"Can't activate "<<oidStr<<": "
+      "BAD_PARAM" IF_OMNIORB4(" ("<<NP_MINORSTRING(ex)<<")") )
+    throw;
+  }
+  catch(POA::ServantAlreadyActive& ex)
+  {
+    DB(0,"Can't activate "<<oidStr<<": Servant is already active.")
+    throw;
+  }
+  catch(POA::ObjectAlreadyActive& ex)
+  {
+    DB(0,"Can't activate "<<oidStr<<": Object is already active.")
+    throw;
+  }
+  catch(POA::WrongPolicy& ex)
+  {
+    DB(0,"Can't activate "<<oidStr<<": POA '"<<poaName.in()
+        <<"' has wrong policy for activate_object_with_id().")
+    exit(1); // Programming error - so quit.
+  }
+}
+
+
+void Servant::deactivateObject()
+{
+  using namespace PortableServer;
+  CORBA::String_var poaName =_poa->the_name();
+
+  ObjectId_var oid;
+  try
+  {
+    oid=_poa->servant_to_id(this);
+  }
+  catch(POA::ServantNotActive& ex)
+  {
+    DB(0,"Can't deactivate servant: POA '"<<poaName.in()
+        <<"' says it is not active.")
+    return;
+  }
+  catch(POA::WrongPolicy& ex)
+  {
+    DB(0,"Can't deactivate servant: POA '"<<poaName.in()
+        <<"' has wrong policy for servant_to_id().")
+    exit(1); // Programming error - so quit.
+  }
+
+  CORBA::String_var oidStr;
+  try
+  {
+    oidStr=ObjectId_to_string(oid.in());
+  }
+  catch(CORBA::BAD_PARAM& ex)
+  {
+    DB(0,"Can't deactivate servant. ObjectId looks bad: "
+      "BAD_PARAM" IF_OMNIORB4(" ("<<NP_MINORSTRING(ex)<<")") )
+    return;
+  }
+
+  try
+  {
+    DB(7,OMNIEVENTS__ADDR "Deactivating object "<<poaName<<"/"<<oidStr.in());
+    _poa->deactivate_object(oid.in());
+  }
+  catch(POA::ObjectNotActive& ex)
+  {
+    DB(0,"Can't deactivate "<<oidStr<<": Object is not active.")
+    return;
+  }
+  catch(POA::WrongPolicy& ex)
+  {
+    DB(0,"Can't deactivate "<<oidStr<<": POA '"<<poaName.in()
+        <<"' has wrong policy for deactivate_object().")
+    exit(1); // Programming error - so quit.
+  }
+}
+
+}; // end namespace OmniEvents

Added: trunk/omnievents/src/main.cc
URL: http://svn.debian.org/wsvn/pkg-corba/trunk/omnievents/src/main.cc?rev=68&op=file
==============================================================================
--- trunk/omnievents/src/main.cc (added)
+++ trunk/omnievents/src/main.cc Thu Nov 29 21:15:18 2007
@@ -1,0 +1,322 @@
+//                            Package   : omniEvents
+//  main.cc                   Created   : 2004/08/01
+//                            Author    : Alex Tingle.
+//
+//    Copyright (C) 1998 Paul Nader, 2004-2005 Alex Tingle.
+//
+//    This file is part of the omniEvents application.
+//
+//    omniEvents is free software; you can redistribute it and/or
+//    modify it under the terms of the GNU Lesser General Public
+//    License as published by the Free Software Foundation; either
+//    version 2.1 of the License, or (at your option) any later version.
+//
+//    omniEvents is distributed in the hope that it will be useful,
+//    but WITHOUT ANY WARRANTY; without even the implied warranty of
+//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//    Lesser General Public License for more details.
+//
+//    You should have received a copy of the GNU Lesser General Public
+//    License along with this library; if not, write to the Free Software
+//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+// Description:
+//    Event Services Channel Factory implementation. The factory registers
+//    itself with the naming service. Clients wishing to create event
+//    channels can either use the factory by resolving its name with the
+//    naming service or create in-process channels.
+//
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#ifdef HAVE_GETOPT
+#  include <unistd.h>
+extern char* optarg;
+extern int optind;
+#else
+#  include "getopt.h"
+#endif
+
+#include "main.h"
+#include "omniEvents.h"
+#include "naming.h"
+#include "omniEventsLog.h"
+#include "EventChannelFactory.h"
+#include "Orb.h"
+#include "daemon.h"
+#include "version.h"
+
+#if defined(HAVE_SIGNAL_H) && defined(HAVE_SIGSET)
+#  include <signal.h>
+#  define SIGSET(sig,func) ::sigset(sig,func)
+#elif defined(HAVE_SIGNAL_H)
+#  include <signal.h>
+#  define SIGSET(sig,func) ::signal(sig,func)
+#endif
+
+#ifdef HAVE_OMNIORB4
+#  include <omniORB4/internal/orbOptions.h>
+#endif
+
+#include <cstdlib>
+#include <stdio.h> // for sprintf
+
+int main(int argc, char** argv)
+{
+  OmniEvents::Daemon daemon(argc,argv);
+
+#ifdef HAVE_OMNIORB4
+  try
+  {
+    // Duplicate argv & argc.
+    int    originalArgc =argc;
+    char** originalArgv =new char*[originalArgc];
+    for(int i=0; i<originalArgc; ++i)
+        originalArgv[i]=strdup(argv[i]);
+
+    // Remove ORB arguments from argc & argv.
+    try {
+      omni::orbOptions::singleton().extractInitOptions(argc,argv);
+    }
+    catch(...) {
+      argc=originalArgc;
+      argv=originalArgv;
+    }
+#endif
+
+  using namespace OmniEvents;
+
+  //
+  // Process Options
+  const char* endPointNoListen =NULL;
+  int         port             =0;
+  const char* logDir           =NULL;
+  const char* factoryName      ="EventChannelFactory";
+  bool        verbose          =false;
+
+  int c;
+  while ((c = getopt(argc,argv,"O:a:p:l:P:N:dft:vVh")) != EOF)
+  {
+     switch (c)
+     {
+        case 'O': break; // Helps protect us from -ORB arguments.
+        
+     // Initialisation options (only useful on first run)
+        case 'a': endPointNoListen=optarg;
+                  break;
+
+        case 'p': port=atoi(optarg);
+                  if (port <= 0)
+                  {
+                     cerr<<"\nError: port must be a positive integer"<<endl;
+                     usage(argc,argv);
+                  }
+                  break;
+
+     // Other options
+        case 'l': logDir=optarg;
+                  break;
+
+        case 'P': daemon.pidfile(optarg);
+                  break;
+
+        case 'N': factoryName=optarg;
+                  break;
+
+        case 'd': cerr<<"Option '-d' is deprecated. Use '-f' instead."<<endl;
+                  daemon.foreground(true);
+                  break;
+
+        case 'f': daemon.foreground(true);
+                  break;
+
+     // Informational options
+        case 't': daemon.tracefile(optarg);
+                  break;
+
+        case 'v': verbose=true;
+                  break;
+        
+        case 'V': cout<<OmniEvents::version()<<endl;
+                  ::exit(0);
+
+        case 'h':
+        default : usage(argc,argv);
+                  break;
+     }
+  }
+
+  //
+  // Create database instance.
+  omniEventsLog logfile(logDir);
+  PersistNode* initialState =NULL;
+  if(logfile.fileExists(logfile.activeFilename()))
+  {
+    // Read library file.
+    initialState=logfile.parse();
+    // Check for incompatibilities between options and the file.
+    if(port && port!=initialState->child("ecf")->attrLong("port"))
+    {
+      cerr<<
+        "Error: Option '-p "<<port<<"' conflicts with value '"<<
+        initialState->child("ecf")->attrLong("port")<<"'\n stored in"
+        " database file '"<<logfile.activeFilename()<<"'.\n"
+        " Either delete the file to clear the database, or do not use the"
+        " '-p' option."<<endl;
+      exit(1);
+    }
+    if(endPointNoListen && string(endPointNoListen)!=
+         initialState->child("ecf")->attrString("endPointNoListen"))
+    {
+      cerr<<
+        "Error: Option '-a "<<endPointNoListen<<"' conflicts with value '"<<
+        initialState->child("ecf")->attrString("endPointNoListen")<<"'\n"
+        " stored in database file '"<<logfile.activeFilename()<<"'.\n"
+        " Either delete the file to clear the database, or do not use the"
+        " '-a' option."<<endl;
+      exit(1);
+    }
+  }
+  else if(logfile.fileExists(logfile.backupFilename()))
+  {
+    // Quit with an error.
+    cerr <<
+      "Error: backup file '" << logfile.backupFilename() << "' exists.\n"
+      " Rename it to '" << logfile.activeFilename() << "'\n"
+      " to recover the server's state, or delete it to create a new\n"
+      " database file." << endl;
+    exit(1);
+  }
+  else
+  {
+    // Create initial state without a library file.
+    initialState=logfile.bootstrap(port?port:11169,endPointNoListen);
+  }
+  port=initialState->child("ecf")->attrLong("port",port);
+  string endPoint2=initialState->child("ecf")->attrString("endPointNoListen");
+
+  //
+  // Daemonise
+  daemon.daemonize();
+
+  //
+  // Initialise orb & POAs.
+#ifdef HAVE_OMNIORB4
+  char endPoint[64];
+  sprintf(endPoint,"giop:::%d",port);
+  if(endPoint2.empty())
+  {
+    const char* opts[][2] ={ {"endPoint",endPoint}, {0,0} };
+    Orb::inst()._orb=CORBA::ORB_init(originalArgc,originalArgv,"omniORB4",opts);
+  }
+  else
+  {
+    const char* opts[][2] ={
+      {"endPoint",endPoint},
+      {"endPointNoListen",endPoint2.c_str()},
+      {0,0} };
+    Orb::inst()._orb=CORBA::ORB_init(originalArgc,originalArgv,"omniORB4",opts);
+  }
+#else
+  insertArgs(argc, argv, 1, 2);
+  argv[1] = strdup("-ORBpoa_iiop_port");
+  argv[2] = new char[32 + 1];
+  sprintf(argv[2], "%d", port);
+  Orb::inst()._orb=CORBA::ORB_init(argc,argv);
+#endif
+  Orb::inst().resolveInitialReferences();
+  {
+    PortableServer::POAManager_var pman;
+    pman=Orb::inst()._RootPOA->the_POAManager();
+    pman->activate();
+    pman=Orb::inst()._omniINSPOA->the_POAManager();
+    pman->activate();
+  }
+
+  //
+  // If omniEvents is restarting then the omniEventsLog object
+  // will take care of creating the factory and any subordinate
+  // event channels, proxies, etc under it.
+  logfile.incarnateFactory(initialState);
+  delete initialState; // Tidy up.
+  initialState=NULL;
+
+  {
+    //
+    // Register factory with the Naming Service.
+    omniEvents::EventChannelFactory_var factory( logfile.factory()->_this() );
+    bindName2Object(
+      Orb::inst()._NameService.in(), 
+      str2name(factoryName),
+      factory.in()
+    );
+
+    //
+    // Print the factory IOR.
+    if(verbose)
+    {
+      DB(1,"Starting omniEvents on port "<<port)
+      if(!endPoint2.empty())
+          DB(1,"Alternate endPoint "<<endPoint2.c_str())
+      CORBA::String_var iorstr =
+        Orb::inst()._orb->object_to_string(factory.in());
+      DB(1,iorstr.in())
+    }
+  } // factory reference is released.
+
+#ifdef HAVE_SIGNAL_H
+  SIGSET(SIGINT , ::OmniEvents_Orb_shutdown);
+  SIGSET(SIGTERM, ::OmniEvents_Orb_shutdown);
+#  ifdef SIGUSR1
+  SIGSET(SIGUSR1, ::OmniEvents_Orb_bumpTraceLevel);
+#  endif
+#  ifdef SIGPIPE
+  SIGSET(SIGPIPE, SIG_IGN); // Ignore broken pipes
+#  endif
+#endif
+
+  daemon.runningOk();
+
+  //
+  // Start the background tasks.
+  logfile.runWorker(); // Logfile's worker thread.
+  Orb::inst().run();   // Use the main thread to collect orphaned responses.
+
+  DB(1,"Shutdown requested.")
+  Orb::inst()._orb->shutdown(1); // Synchronous shutdown
+  Orb::inst()._orb->destroy(); // clean up
+
+  return 0; // Delete any pidfile & exit.
+
+#ifdef HAVE_OMNIORB4
+  }
+  catch (CORBA::SystemException& ex) {
+    DB(0,"System exception: "<<ex._name()<<" ("<<NP_MINORSTRING(ex)<<")")
+  }
+  catch (CORBA::Exception& ex) {
+    DB(0,"CORBA exception: "<<ex._name())
+  }
+  return 1;
+#endif
+} // end main()
+
+
+//
+// Signal handlers.
+//
+
+extern "C"
+{
+  void OmniEvents_Orb_shutdown(int signum)
+  {
+    OmniEvents::Orb::inst().shutdown(signum);
+  }
+
+  void OmniEvents_Orb_bumpTraceLevel(int signum)
+  {
+    omniORB::traceLevel=(omniORB::traceLevel+5)%45;
+    DB(0,"TRACE LEVEL BUMPED TO "<<omniORB::traceLevel<<" BY SIGNAL "<<signum)
+  }
+}




More information about the Pkg-corba-commits mailing list