EchoImageServer.C

Go to the documentation of this file.
00001 /*!@file Corba/Objects/EchoImageServer.C a test program to send an image using corba:
00002   This is the server class that echos the image  */
00003 
00004 //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00006 // University of Southern California (USC) and the iLab at USC.         //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: Lior Elazary <lelazary@yahoo.com>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Corba/Objects/EchoImageServer.C $
00036 // $Id: EchoImageServer.C 6795 2006-06-29 20:45:32Z rjpeters $
00037 //
00038 
00039 #include <stdlib.h>
00040 #include <time.h>
00041 #include <iostream>
00042 #include <unistd.h>
00043 #include <fcntl.h>
00044 #include <sys/types.h>
00045 #include <sys/stat.h>
00046 #include <signal.h>
00047 #include "Component/ModelManager.H"
00048 #include "GUI/XWinManaged.H"
00049 #include "Image/Pixels.H"
00050 #include "Image/ShapeOps.H"
00051 #include "Image/ColorOps.H"
00052 #include "SIFT/ScaleSpace.H"
00053 #include "EchoImageServerSK.hh"
00054 #include "Corba/ImageOrbUtil.H"
00055 #include "Corba/ImageOrbUtil.H"
00056 #include "Corba/CorbaUtil.H"
00057 #include "Corba/Objects/EchoImageServer.H"
00058 
00059 CORBA::ORB_var orb;
00060 CosNaming::Name objectName;
00061 
00062 bool Debug = false;
00063 
00064 //! Signal handler (e.g., for control-C)
00065 void terminate(int s)
00066 {
00067   LERROR("*** INTERRUPT ***");
00068   unbindObject(orb, "saliency", "EchoImage", objectName);
00069   orb->shutdown(0);
00070 }
00071 
00072 void EchoImageServer_i::shutdown()
00073 {
00074   // Shutdown the ORB
00075   unbindObject(orb, "saliency", "EchoImage", objectName);
00076   orb->shutdown(0);
00077 }
00078 
00079 
00080 EchoImageServer_i::EchoImageServer_i()
00081 {
00082 }
00083 
00084 
00085 EchoImageServer_i::~EchoImageServer_i()
00086 {
00087 
00088 }
00089 
00090 ImageOrb* EchoImageServer_i::echo(const ImageOrb& img)
00091 {
00092   LINFO("Got Image");
00093   Image< PixRGB<byte> > image;
00094   orb2Image(img, image);
00095 
00096   LINFO("Echoing image back");
00097   return image2Orb(image);
00098 }
00099 
00100 
00101 //start the class server
00102 int main(int argc, char **argv)
00103 {
00104 
00105   MYLOGVERB = LOG_INFO;
00106 
00107   // Instantiate a ModelManager:
00108   ModelManager manager("EchoImage Corba Object");
00109 
00110   if (manager.parseCommandLine((const int)argc, (const char**)argv, "", 0, 0) == false)
00111     return(1);
00112 
00113   if (manager.debugMode()){
00114     Debug = true;
00115   } else {
00116     LINFO("Running as a daemon. Set --debug to see any errors.");
00117     //Become a daemon
00118     // fork off the parent process
00119     pid_t pid = fork();
00120     if (pid < 0)
00121       LFATAL("Can not fork");
00122 
00123     if (pid > 0)
00124       exit(0); //exit the parent process
00125 
00126     // Change the file mask
00127     umask(0);
00128 
00129     //Create a new system id so that the kernel wont think we are an orphan.
00130     pid_t sid = setsid();
00131     if (sid < 0)
00132       LFATAL("Can not become independent");
00133 
00134     fclose(stdin);
00135     fclose(stdout);
00136     fclose(stderr);
00137 
00138   }
00139   // catch signals and redirect them to terminate for clean exit:
00140   signal(SIGHUP, terminate); signal(SIGINT, terminate);
00141   signal(SIGQUIT, terminate); signal(SIGTERM, terminate);
00142   signal(SIGALRM, terminate);
00143 
00144 
00145   //Create the object and run in
00146   orb = CORBA::ORB_init(argc, argv);
00147 
00148   CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00149   PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
00150 
00151   EchoImageServer_i* myobj = new EchoImageServer_i();
00152 
00153 
00154   PortableServer::ObjectId_var objID = poa->activate_object(myobj);
00155 
00156   //get a ref string
00157   obj = myobj->_this();
00158   CORBA::String_var sior(orb->object_to_string(obj));
00159   std::cerr << "'" << (char*)sior << "'" << "\n";
00160 
00161   if( !bindObjectToName(orb, obj, "saliency", "EchoImage", "EchoImage", objectName) )
00162     return 1;
00163   myobj->_remove_ref();
00164 
00165   PortableServer::POAManager_var pman = poa->the_POAManager();
00166   pman->activate();
00167 
00168   try
00169   {
00170     manager.start();
00171     //run the object untill shutdown or killed
00172     orb->run();
00173   } catch (...) {
00174     LINFO("Error starting server");
00175   }
00176 
00177   LINFO("Shutting down");
00178   unbindObject(orb, "saliency", "EchoImage", objectName);
00179 
00180   manager.stop();
00181 
00182   return 0;
00183 }
00184 
00185 // ######################################################################
00186 /* So things look consistent in everyone's emacs... */
00187 /* Local Variables: */
00188 /* indent-tabs-mode: nil */
00189 /* End: */
Generated on Sun May 8 08:40:23 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3