Fresco/Berlin/server ServerImpl.cc,1.9,1.10 ServerImpl.hh,1.7,1.8 server.cc,1.64,1.65

Neil John Pilgrim <[email protected]>
Newsgroups gmane.comp.video.fresco.cvs
Message-ID <[email protected]>
Update of /cvs/fresco/Fresco/Berlin/server
In directory purcel:/tmp/cvs-serv29796/Berlin/server

Modified Files:
	ServerImpl.cc ServerImpl.hh server.cc 
Log Message:
- Hitting ESC on desktop should now exit server cleanly (no inf-loops/crashes)
- Hitting Ctrl-C on controlling terminal of server should now exit it cleanly
- On exiting cleanly, server references are unpublished
=> Closes bug82 and bug126


Index: ServerImpl.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/server/ServerImpl.cc,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ServerImpl.cc	18 Dec 2002 06:00:06 -0000	1.9
+++ ServerImpl.cc	23 Jan 2003 00:43:01 -0000	1.10
@@ -104,20 +104,21 @@
   for (clist_t::iterator i = _contexts.begin(); i != _contexts.end(); i++)
     ServerImpl::destroy_context(*i);
   _contexts.clear();
-  exit(0);
 }
 
 void ServerImpl::ping()
 {
   Trace trace("ServerImpl::ping");
   Prague::Guard<Mutex> guard (_mutex);
-  clist_t tmp;
+  clist_t updated_contexts;
   for (clist_t::iterator i = _contexts.begin(); i != _contexts.end(); i++)
+  {
     if ((*i)->ping())
-	tmp.push_back(*i);
+	updated_contexts.push_back(*i);
     else
 	destroy_context(*i);
-  _contexts = tmp;
+  }
+  _contexts = updated_contexts;
 };
 
 void ServerImpl::scan(const std::string &name)

Index: ServerImpl.hh
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/server/ServerImpl.hh,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ServerImpl.hh	2 Jun 2002 05:26:13 -0000	1.7
+++ ServerImpl.hh	23 Jan 2003 00:43:01 -0000	1.8
@@ -94,11 +94,9 @@
   void stop();
   //. Pings all ServerContexts and destroys those that do not
   //. respond (aka. crashed).
-
   void ping();
   //. This scans all directories given as modulepath in berlinrc for Kits
   //. and loads the whole lot of them.
-
   void scan(const std::string &);
   //. Deletes all known Kits.
   void clear();

Index: server.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/server/server.cc,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- server.cc	3 Jan 2003 18:19:21 -0000	1.64
+++ server.cc	23 Jan 2003 00:43:01 -0000	1.65
@@ -77,10 +77,17 @@
 
 struct Dump : Signal::Notifier 
 {
+  private:
+  Prague::Semaphore & my_semaphore;
+  Dump(Dump const &);                   // no impl
+  Dump const & operator=(Dump const &); // no impl
+  public:
+  Dump(Prague::Semaphore & semaphore)
+          : my_semaphore(semaphore){}
   void notify(int signo) /*FOLD00*/
-    {
+  {
       switch (signo)
-        {
+      {
         case Signal::usr2: 
           if (Console::instance())
           {
@@ -88,6 +95,7 @@
             Console::instance()->wakeup();
           }
           return;
+        case Signal::interrupt: break;
         case Signal::hangup: Profiler::dump(std::cerr); break;
         case Signal::abort:
         case Signal::segv:
@@ -104,10 +112,12 @@
                       << "(together with a description\n"
                       << "of your configuration and what you were doing"
                       << " before the crash).\n\n";
-            exit(-1);
+            exit(-1); // NOTE: Must exit after getting segv:
+                      // behaviour is undefined if not!
           }
-        }
-    }
+      }
+      my_semaphore.post();
+  }
 };
 
 //. Execute a client using the command in 'value'. The process is stored in
@@ -169,11 +179,13 @@
   // Setup signalhandling
   // ---------------------------------------------------------------
   
-  Dump *dump = new Dump;
+  Prague::Semaphore sem;
+  Dump *dump = new Dump(sem);
   Signal::set(Signal::usr2, dump);
   Signal::set(Signal::abort, dump);
   Signal::set(Signal::segv, dump);
   Signal::set(Signal::hangup, dump);
+  Signal::set(Signal::interrupt, dump);
   
   // ---------------------------------------------------------------
   // Parse commandline arguments
@@ -471,6 +483,7 @@
        DrawingKit_var drawing =
        server->resolve<DrawingKit>("IDL:fresco.org/Fresco/DrawingKit:1.0",
                                    props, poa);
+       Logger::log(Logger::drawing) << "DrawingKit is resolved." << std::endl;
        if (CORBA::is_nil(drawing))
        {
          std::cerr << "ERROR: Unable to open "
@@ -501,7 +514,7 @@
                server->resolve<LayoutKit>("IDL:fresco.org/Fresco/LayoutKit:1.0",
                                           props, poa);
        Layout::Stage_var stage = layout->create_stage();
-       DesktopImpl *desktop = new DesktopImpl(orb, stage);
+       DesktopImpl *desktop = new DesktopImpl(orb, stage, sem);
        screen->body(Desktop_var(desktop->_this()));
        screen->append_controller(Desktop_var(desktop->_this()));
        Logger::log(Logger::layout) << "Desktop is created." << std::endl;
@@ -512,7 +525,7 @@
        Logger::log(Logger::loader) << "singletons set" << std::endl;
 
        // ---------------------------------------------------------------
-       // Start the server - Initialise the client listener and publish it
+       // Start the server thread - start the client listener and publish it
        // ---------------------------------------------------------------
 
        server->start();
@@ -532,11 +545,31 @@
        if (!value.empty())
        {
          exec_child(child, value);
+         Logger::log(Logger::loader) << "Child process started." << std::endl;
        }
 
-       Logger::log(Logger::loader) << "Running the ScreenManager now."
+       // ---------------------------------------------------------------
+       // Start ScreenManager thread
+       // ---------------------------------------------------------------
+
+       smanager->start();
+       Logger::log(Logger::loader) << "ScreenManager is running." << std::endl;
+
+       // ---------------------------------------------------------------
+       // Wait until we receive a request to shut down, then do so
+       // NOTE: server/smanager threads assumed to be shut-down implicitly
+       // ---------------------------------------------------------------
+
+       Logger::log(Logger::loader) << "Blocking waiting for shutdown request." 
                                    << std::endl;
-       smanager->run();
+       sem.wait();
+       Logger::log(Logger::loader) << "Starting server shutdown." << std::endl;
+ 
+       unpublish_server(orb);
+       Logger::log(Logger::loader) << "Un-published Server." << std::endl;
+
+       server->stop();
+       Logger::log(Logger::loader) << "Server stopped." << std::endl;
   }
   catch (const CORBA::SystemException &e)
   {
@@ -566,8 +599,8 @@
       std::cerr << "ERROR: *UNKNOWN* exception caught" << std::endl;
   };
 
+  Logger::log(Logger::corba) << "CORBA servants gone." << std::endl;
   delete child;
-  if (!CORBA::is_nil(orb)) orb->destroy();
   return 0;
 }
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.