Fresco/Berlin/src KitImpl.cc,1.11,1.12 Makefile.in,1.39,1.40 ServerContextImpl.cc,1.7,1.8 ServerImpl.cc,1.10,1.11

Stefan Seefeld <[email protected]>
Newsgroups gmane.comp.video.fresco.cvs
Message-ID <[email protected]>
Update of /cvs/fresco/Fresco/Berlin/src
In directory purcel:/tmp/cvs-serv31700/Berlin/src

Modified Files:
	KitImpl.cc Makefile.in ServerContextImpl.cc ServerImpl.cc 
Log Message:
a somewhat lengthy fix for http://issues.fresco.org/bug92

Index: KitImpl.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/src/KitImpl.cc,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- KitImpl.cc	23 Jan 2003 22:31:07 -0000	1.11
+++ KitImpl.cc	18 Feb 2003 07:26:39 -0000	1.12
@@ -25,6 +25,7 @@
 #include <Berlin/Logger.hh>
 #include <Berlin/KitImpl.hh>
 #include "Berlin/ServantBase.hh"
+#include "Berlin/ServerContextImpl.hh"
 #include <typeinfo>
 
 using namespace Prague;
@@ -35,8 +36,13 @@
   Mutex mutex;
 };
 
-KitImpl::KitImpl(const std::string &id, const Fresco::Kit::PropertySeq &p)
-  : _repo_id(id), _props(new Fresco::Kit::PropertySeq(p)), _refcount(1)
+KitImpl::KitImpl(const std::string &id,
+		 const Fresco::Kit::PropertySeq &p,
+		 ServerContextImpl *c)
+  : my_repo_id(id),
+    my_props(new Fresco::Kit::PropertySeq(p)),
+    my_refcount(1),
+    my_context(c)
 {
   Trace trace("KitImpl::KitImpl");
 #ifdef LCLOG
@@ -47,13 +53,14 @@
 KitImpl::~KitImpl()
 {
   Trace trace("KitImpl::~KitImpl");  
-  Logger::log(Logger::lifecycle) << "destroying POA... " << _poa << std::endl;
-  _poa->destroy(true, true);
-  Logger::log(Logger::lifecycle) << "destroying POA done " << _poa << std::endl;
+  Logger::log(Logger::lifecycle) << "destroying POA... " << my_poa << std::endl;
+  my_poa->destroy(true, false);
+  Logger::log(Logger::lifecycle) << "destroying POA done " << my_poa << std::endl;
 #ifdef LCLOG
   Logger::log(Logger::lifecycle) << "KitImpl::~KitImpl: " << this << " destructed" << std::endl;
 #endif
-  delete _props;
+  delete my_props;
+  if (my_context) my_context->erase(this);
 }
 
 CORBA::Boolean KitImpl::supports(const Fresco::Kit::PropertySeq &p)
@@ -62,18 +69,18 @@
   const Fresco::Kit::Property *begin2 = p.get_buffer();
   const Fresco::Kit::Property *end2 = begin2 + p.length();
   for (const Fresco::Kit::Property *property2 = begin2; property2 != end2; property2++)
-    {
-      const Fresco::Kit::Property *begin1 = _props->get_buffer();
-      const Fresco::Kit::Property *end1 = begin1 + _props->length();
-      const Fresco::Kit::Property *property1;
-      for (property1 = begin1; property1 != end1; property1++)
-	if (strcmp(property1->name, property2->name) == 0)
-	  {
-	    if (strcmp(property1->value, property2->value) == 0) break;
-	    else return false; // value not supported
-	  }
-      if (property1 == end1) return false; // property not supported
-    }
+  {
+    const Fresco::Kit::Property *begin1 = my_props->get_buffer();
+    const Fresco::Kit::Property *end1 = begin1 + my_props->length();
+    const Fresco::Kit::Property *property1;
+    for (property1 = begin1; property1 != end1; property1++)
+      if (strcmp(property1->name, property2->name) == 0)
+      {
+	if (strcmp(property1->value, property2->value) == 0) break;
+	else return false; // value not supported
+      }
+    if (property1 == end1) return false; // property not supported
+  }
   return true;
 }
 
@@ -83,8 +90,8 @@
 #ifdef LCLOG
   Logger::log(Logger::lifecycle) << "activating " << servant << " (" << typeid(*servant).name() << ")" << std::endl;
 #endif
-  PortableServer::ObjectId *oid = _poa->activate_object(servant);
-  servant->_poa = PortableServer::POA::_duplicate(_poa);
+  PortableServer::ObjectId *oid = my_poa->activate_object(servant);
+  servant->_poa = PortableServer::POA::_duplicate(my_poa);
   servant->_remove_ref();
   delete oid;
   servant->activate_composite();
@@ -93,11 +100,11 @@
 void KitImpl::deactivate(::ServantBase *servant)
 {
   Trace trace("KitImpl::deactivate(PortableServer::Servant)");
-  PortableServer::ObjectId *oid = _poa->servant_to_id(servant);
+  PortableServer::ObjectId *oid = my_poa->servant_to_id(servant);
 #ifdef LCLOG
   Logger::log(Logger::lifecycle) << "deactivating " << servant << " (" << typeid(*servant).name() << ")" << std::endl;
 #endif
-  _poa->deactivate_object(*oid);
+  my_poa->deactivate_object(*oid);
   delete oid;
 }
 
@@ -105,7 +112,7 @@
 {
   Trace trace("KitImpl::increment");
   Prague::Guard<Mutex> guard(mutex);
-  ++_refcount;
+  ++my_refcount;
 #ifdef LCLOG
   Logger::log(Logger::lifecycle) << "KitImpl::increment on " << this << " (" << typeid(*this).name() << "): new count is " << _refcount << std::endl;
 #endif
@@ -117,7 +124,7 @@
   bool done;
   {
     Prague::Guard<Mutex> guard(mutex);
-    done = --_refcount;
+    done = --my_refcount;
 #ifdef LCLOG
     Logger::log(Logger::lifecycle) << "KitImpl::decrement on " << this << " (" << typeid(*this).name() << "): new count is " << _refcount << std::endl;
 #endif

Index: Makefile.in
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/src/Makefile.in,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- Makefile.in	4 Jan 2003 14:15:14 -0000	1.39
+++ Makefile.in	18 Feb 2003 07:26:40 -0000	1.40
@@ -42,7 +42,7 @@
 	   DesktopImpl.cc ScreenImpl.cc ScreenManager.cc EventManager.cc \
 	   PositionalFocus.cc NonPositionalFocus.cc FilterImpl.cc SubjectImpl.cc \
 	   PNG.cc RasterImpl.cc \
-	   KitImpl.cc RCManager.cc
+	   KitImpl.cc RCManager.cc ServerContextImpl.cc ServerImpl.cc
 
 DEP	:= $(patsubst %.cc, %.d, $(SRC))
 HDR	:= Console.hh Color.hh Event.hh GapBuffer.hh Geometry.hh \
@@ -56,7 +56,8 @@
 	   ControllerImpl.hh ViewImpl.hh DesktopImpl.hh ScreenImpl.hh \
 	   ScreenManager.hh EventManager.hh PositionalFocus.hh \
 	   NonPositionalFocus.hh FilterImpl.hh SubjectImpl.hh KitImpl.hh \
-	   RCManager.hh DefaultPOA.hh ObserverImpl.hh config.hh
+	   RCManager.hh DefaultPOA.hh ObserverImpl.hh config.hh \
+           ServerContextImpl.hh ServerImpl.hh
 
 CHDR	:= DirectBuffer.hh Renderer.hh GLContext.hh SHMDrawableFactory.hh GGIDrawableFactory.hh
 OBJ	:= $(patsubst %.cc, %.o, $(SRC))

Index: ServerContextImpl.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/src/ServerContextImpl.cc,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ServerContextImpl.cc	8 Feb 2003 02:12:39 -0000	1.7
+++ ServerContextImpl.cc	18 Feb 2003 07:26:40 -0000	1.8
@@ -29,24 +29,24 @@
 #include <Berlin/Logger.hh>
 #include <Berlin/KitImpl.hh>
 #include <Fresco/Unicode.hh>
-#include "ServerContextImpl.hh"
-#include "ServerImpl.hh"
+#include <Berlin/ServerContextImpl.hh>
+#include <Berlin/ServerImpl.hh>
 #include <sstream>
 
 using namespace Prague;
 using namespace Fresco;
 
-unsigned long ServerContextImpl::_counter = 0;
+unsigned long ServerContextImpl::my_counter = 0;
 
 // this is the thing which holds all the references to things a client allocates
 // (for garbage collection), does security checks for new allocation, and
 // occasionally pings the client to make sure it's still there.
 
 ServerContextImpl::ServerContextImpl(ServerImpl *s, const CORBA::PolicyList &policies, ClientContext_ptr c)
-    : _server(s), _policies(policies), _client(ClientContext::_duplicate(c))
+    : my_server(s), my_policies(policies), my_client(ClientContext::_duplicate(c))
 {
   Trace trace("ServerContextImpl::ServerContextImpl");
-  Babylon::String title = Unicode::to_internal(*_client->application_title());
+  Babylon::String title = Unicode::to_internal(*my_client->application_title());
   Logger::log(Logger::corba) << (void *)(this) << " is the ServerContext "
 			     << "for application \"" << title.utf8()
 			     << "\"." << std::endl;
@@ -55,32 +55,35 @@
 ServerContextImpl::~ServerContextImpl()
 {
   Trace trace("ServerContextImpl::~ServerContextImpl");
-  for (klist_t::iterator i = _kits.begin(); i != _kits.end(); ++i)
+  for (klist_t::iterator i = my_kits.begin(); i != my_kits.end(); ++i)
     (*i).second->decrement();
   Logger::log(Logger::corba) << "ServerContext " << (void *)(this)
 			     << " destructed." << std::endl;
 }
 
-ClientContext_ptr ServerContextImpl::client() { return ClientContext::_duplicate(_client);}
+ClientContext_ptr ServerContextImpl::client()
+{
+  return ClientContext::_duplicate(my_client);
+}
 
 // will fill the rest of these in as needs arise. They should do something reasonably obvious.
 
 void ServerContextImpl::set_singleton(const char *name, CORBA::Object_ptr singleton)
   throw (SecurityException, SingletonFailureException)
 {
-  _server->set_singleton(name, singleton);
+  my_server->set_singleton(name, singleton);
 }
 
 void ServerContextImpl::remove_singleton(const char *name)
   throw (SecurityException, SingletonFailureException)
 {
-  _server->remove_singleton(name);
+  my_server->remove_singleton(name);
 }
 
 CORBA::Object_ptr ServerContextImpl::get_singleton(const char *name) 
   throw (SecurityException, SingletonFailureException)
 {
-  return _server->get_singleton(name);
+  return my_server->get_singleton(name);
 }
 
 // this method should eventually do some kind of checking on the
@@ -94,28 +97,28 @@
   /*
    * look for loaded kits first
    */
-  klist_t::iterator k1 = _kits.lower_bound(type), k2 = _kits.upper_bound(type);
+  klist_t::iterator k1 = my_kits.lower_bound(type), k2 = my_kits.upper_bound(type);
   for (klist_t::iterator i = k1; i != k2; ++i)
     if ((*i).second->supports(properties))
-      {
-	(*i).second->increment();
-	return (*i).second->_this();
-      }
+    {
+      (*i).second->increment();
+      return (*i).second->_this();
+    }
   /*
    * now try the factories
    */
   PortableServer::POA_var root = _default_POA();
   std::ostringstream oss;
-  oss << '#' << _counter++ << std::ends;
+  oss << '#' << my_counter++;
   PortableServer::POAManager_var manager = root->the_POAManager();
   PortableServer::POA_var poa =
-    root->create_POA(oss.str().c_str(), manager, _policies);
+    root->create_POA(oss.str().c_str(), manager, my_policies);
   Logger::log(Logger::lifecycle) << "created new POA for kit of type "
 	  << type << " (id is " << oss.str() << ')' << std::endl;
-  KitImpl *kit = _server->create(type, properties, poa);
+  KitImpl *kit = my_server->create(type, properties, poa, this);
   if (!kit) throw CreationFailureException();
   kit->bind(ServerContext_var(_this()));
-  _kits.insert(klist_t::value_type(type, kit));
+  my_kits.insert(klist_t::value_type(type, kit));
   return kit->_this();
 }
 
@@ -125,11 +128,23 @@
 bool ServerContextImpl::ping()
 {
   Trace trace("ServerContextImpl::ping");
-  Prague::Guard<Mutex> guard(_mutex);
+  Prague::Guard<Mutex> guard(my_mutex);
   bool alive = true;
-  if (CORBA::is_nil(_client)) alive = false;
+  if (CORBA::is_nil(my_client)) alive = false;
   else
-    try { _client->ping();}
+    try { my_client->ping();}
     catch (...) { alive = false;}
   return alive;
+}
+
+void ServerContextImpl::erase(KitImpl *kit)
+{
+  std::string type = kit->repo_id();
+  klist_t::iterator k1 = my_kits.lower_bound(type), k2 = my_kits.upper_bound(type);
+  for (klist_t::iterator i = k1; i != k2; ++i)
+    if ((*i).second == kit)
+    {
+      my_kits.erase(i);
+      return;
+    }
 }

Index: ServerImpl.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/src/ServerImpl.cc,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- ServerImpl.cc	23 Jan 2003 00:43:01 -0000	1.10
+++ ServerImpl.cc	18 Feb 2003 07:26:40 -0000	1.11
@@ -25,30 +25,30 @@
 #include <Prague/Sys/Directory.hh>
 #include "Berlin/Logger.hh"
 #include "Berlin/ImplVar.hh"
-#include "ServerImpl.hh"
-#include "ServerContextImpl.hh"
+#include "Berlin/ServerImpl.hh"
+#include "Berlin/ServerContextImpl.hh"
 
 using namespace Prague;
 using namespace Fresco;
 
-ServerImpl *ServerImpl::_server = 0;;
+ServerImpl *ServerImpl::my_server = 0;;
 
 ServerImpl *ServerImpl::create(PortableServer::POA_ptr poa, const CORBA::PolicyList &policies)
 {
-  assert(_server == 0);
-  _server = new ServerImpl(policies);
-  _server->_poa = PortableServer::POA::_duplicate(poa);
-  return _server;
+  assert(my_server == 0);
+  my_server = new ServerImpl(policies);
+  my_server->my_poa = PortableServer::POA::_duplicate(poa);
+  return my_server;
 }
 
 ServerImpl *ServerImpl::instance()
 {
-  return _server;
+  return my_server;
 }
 
 ServerImpl::ServerImpl(const CORBA::PolicyList &policies)
-  : _policies(policies),
-    _thread(&ServerImpl::run, this)
+  : my_policies(policies),
+    my_thread(&ServerImpl::run, this)
 {
 }
 
@@ -57,9 +57,9 @@
     throw (SecurityException)
 {
   Trace trace("ServerImpl::create_server_context");
-  Prague::Guard<Mutex> guard (_mutex);
-  Impl_var<ServerContextImpl> sc(new ServerContextImpl(this, _policies, c));
-  _contexts.push_back(sc);
+  Prague::Guard<Mutex> guard(my_mutex);
+  Impl_var<ServerContextImpl> sc(new ServerContextImpl(this, my_policies, c));
+  my_contexts.push_back(sc);
   return sc._retn()->_this();
 }
 
@@ -67,63 +67,63 @@
 			       CORBA::Object_ptr singleton) 
   throw (SecurityException, SingletonFailureException)
 {
-  Prague::Guard<Mutex> guard (_mutex);
+  Prague::Guard<Mutex> guard(my_mutex);
   // test wether the name is allready in use:
-  smap_t::iterator p = _singletons.find(name);
-  if (p != _singletons.end()) throw SingletonFailureException();
-  else _singletons[name] = singleton;
+  smap_t::iterator p = my_singletons.find(name);
+  if (p != my_singletons.end()) throw SingletonFailureException();
+  else my_singletons[name] = singleton;
 }
 
 void ServerImpl::remove_singleton(const char *name) 
   throw (SecurityException, SingletonFailureException)
 {
-  Prague::Guard<Mutex> guard (_mutex);
-  smap_t::iterator p = _singletons.find(name);
-  if (p != _singletons.end()) _singletons.erase(p);
+  Prague::Guard<Mutex> guard(my_mutex);
+  smap_t::iterator p = my_singletons.find(name);
+  if (p != my_singletons.end()) my_singletons.erase(p);
   throw SingletonFailureException();
 }
 
 CORBA::Object_ptr ServerImpl::get_singleton(const char *name) 
   throw (SecurityException, SingletonFailureException)
 {
-  Prague::Guard<Mutex> guard (_mutex);
-  smap_t::iterator p = _singletons.find(name);
-  if (p != _singletons.end()) return CORBA::Object::_duplicate(p->second);
+  Prague::Guard<Mutex> guard(my_mutex);
+  smap_t::iterator p = my_singletons.find(name);
+  if (p != my_singletons.end()) return CORBA::Object::_duplicate(p->second);
   throw SingletonFailureException();
 }
 
 void ServerImpl::start()
 {
-  _thread.start();
+  my_thread.start();
 }
 
 void ServerImpl::stop()
 {
   Trace trace("ServerImpl::stop");
-  Prague::Guard<Mutex> guard (_mutex);
-  for (clist_t::iterator i = _contexts.begin(); i != _contexts.end(); i++)
+  Prague::Guard<Mutex> guard (my_mutex);
+  for (clist_t::iterator i = my_contexts.begin(); i != my_contexts.end(); i++)
     ServerImpl::destroy_context(*i);
-  _contexts.clear();
+  my_contexts.clear();
 }
 
 void ServerImpl::ping()
 {
   Trace trace("ServerImpl::ping");
-  Prague::Guard<Mutex> guard (_mutex);
+  Prague::Guard<Mutex> guard(my_mutex);
   clist_t updated_contexts;
-  for (clist_t::iterator i = _contexts.begin(); i != _contexts.end(); i++)
+  for (clist_t::iterator i = my_contexts.begin(); i != my_contexts.end(); i++)
   {
     if ((*i)->ping())
-	updated_contexts.push_back(*i);
+      updated_contexts.push_back(*i);
     else
-	destroy_context(*i);
+      destroy_context(*i);
   }
-  _contexts = updated_contexts;
+  my_contexts = updated_contexts;
 };
 
 void ServerImpl::scan(const std::string &name)
 {
-  Prague::Guard<Mutex> guard(_mutex);
+  Prague::Guard<Mutex> guard(my_mutex);
   /*
    * load all files in <name> according to the regexp '\\.so$'
    */
@@ -139,7 +139,7 @@
 	  Logger::log(Logger::loader) << (*i)->name() << " not loadable " << e.what() << std::endl;
 	  continue;
 	}
-      _plugins.push_back(plugin);
+      my_plugins.push_back(plugin);
       Logger::log(Logger::loader) << "ServerImpl: loaded plugin for " << (*plugin)->repo_id() << " from " << (*i)->name() << std::endl;
     }
 }
@@ -147,35 +147,36 @@
 //. hope you know what you are doing if you call this...
 void ServerImpl::clear()
 {
-  Prague::Guard<Mutex> guard(_mutex);
-  for (pmap_t::iterator i = _plugins.begin(); i != _plugins.end(); ++i) delete *i;
-  _plugins.clear();
+  Prague::Guard<Mutex> guard(my_mutex);
+  for (pmap_t::iterator i = my_plugins.begin(); i != my_plugins.end(); ++i) delete *i;
+  my_plugins.clear();
 }
 
 ServerImpl::PluginList ServerImpl::list()
 {
   PluginList pl;
-  for (pmap_t::iterator i = _plugins.begin(); i != _plugins.end(); ++i)
+  for (pmap_t::iterator i = my_plugins.begin(); i != my_plugins.end(); ++i)
     pl.insert(PluginList::value_type((**i)->repo_id(), (**i)->properties()));
   return pl;
 }
 
 KitImpl *ServerImpl::create(const char *type,
 			    const Kit::PropertySeq &properties,
-			    PortableServer::POA_ptr poa)
+			    PortableServer::POA_ptr poa,
+			    ServerContextImpl *context)
 {
   Trace trace("ServerImpl::create");
-  for (pmap_t::iterator i = _plugins.begin(); i != _plugins.end(); ++i)
+  for (pmap_t::iterator i = my_plugins.begin(); i != my_plugins.end(); ++i)
     if ((**i)->_is_a(type) && (**i)->supports(properties))
-      {
-	KitImpl *kit = (**i)->clone(properties);
-	kit->_poa = PortableServer::POA::_duplicate(poa);
-	PortableServer::POA_var root = kit->_default_POA();
-	PortableServer::ObjectId *oid = root->activate_object(kit);
-	kit->_remove_ref();
-	delete oid;
-	return kit;
-      }
+    {
+      KitImpl *kit = (**i)->clone(properties, context);
+      kit->my_poa = PortableServer::POA::_duplicate(poa);
+      PortableServer::POA_var root = kit->_default_POA();
+      PortableServer::ObjectId *oid = root->activate_object(kit);
+      kit->_remove_ref();
+      delete oid;
+      return kit;
+    }
   return 0;
 }
 
@@ -183,10 +184,10 @@
 {
   ServerImpl *server = reinterpret_cast<ServerImpl *>(X);
   while (true)
-    {
-      Thread::delay(1000);
-      server->ping();
-    }
+  {
+    Thread::delay(1000);
+    server->ping();
+  }
   return 0;
 }
 
@@ -202,38 +203,38 @@
    */
   catch (const CORBA::OBJECT_NOT_EXIST &)
   {
-      std::cerr << "Caught CORBA::OBJECT_NOT_EXIST while cleaning up "
-		<< "a ServerContext" << std::endl;
+    std::cerr << "Caught CORBA::OBJECT_NOT_EXIST while cleaning up "
+	      << "a ServerContext" << std::endl;
   }
   catch (const CORBA::COMM_FAILURE &)
   {
-      std::cerr << "Caught CORBA::COMM_FAILURE while cleaning up "
-		<< "a ServerContext" << std::endl;
+    std::cerr << "Caught CORBA::COMM_FAILURE while cleaning up "
+	      << "a ServerContext" << std::endl;
   }
   catch (const CORBA::TRANSIENT &)
   {
-      std::cerr << "Caught CORBA::TRANSIENT while cleaning up "
-		<< "a ServerContext" << std::endl;
+    std::cerr << "Caught CORBA::TRANSIENT while cleaning up "
+	      << "a ServerContext" << std::endl;
   }
   catch (const PortableServer::POA::ObjectNotActive &)
   {
-      std::cerr << "Caught POA::ObjectNotActive while cleaning up "
-		<< "a ServerContext" << std::endl;
+    std::cerr << "Caught POA::ObjectNotActive while cleaning up "
+	      << "a ServerContext" << std::endl;
   }
   catch (const PortableServer::POA::WrongPolicy &)
   {
-      std::cerr << "Caught POA::WrongPolicy while cleaning up "
-		<< "a ServerContext" << std::endl;
+    std::cerr << "Caught POA::WrongPolicy while cleaning up "
+	      << "a ServerContext" << std::endl;
   }
   catch(const std::exception & e)
   {
-      std::cerr << "Caught a std::exeception while cleaning up "
-		<< "a ServerContext (" << e.what() << ")" << std::endl;
+    std::cerr << "Caught a std::exeception while cleaning up "
+	      << "a ServerContext (" << e.what() << ")" << std::endl;
   }
   catch(...)
   {
-      std::cerr << "Caught unknown exception while cleaning up "
-		<< "a ServerContext" << std::endl;
+    std::cerr << "Caught unknown exception while cleaning up "
+	      << "a ServerContext" << std::endl;
   }
   delete oid;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.