EchoImageServerIce.C

00001 #include "Image/Image.H"
00002 #include "GUI/XWindow.H"
00003 #include "Raster/Raster.H"
00004 #include "Image/Pixels.H"
00005 
00006 #include <Ice/Ice.h>
00007 #include <IceUtil/Thread.h>
00008 #include "Ice/ImageIce.ice.H"
00009 #include "Ice/IceImageUtils.H"
00010 #include "Component/ModelManager.H"
00011 #include "Media/FrameSeries.H"
00012 #include "Image/JPEGUtil.H"
00013 
00014 
00015 
00016 
00017 class ImageShuttleI: public ImageShuttle, public IceUtil::Thread, public ModelComponent {
00018   public:
00019     ImageShuttleI(OptionManager &mgr,
00020         const std::string& descrName = "Image Shuttle",
00021         const std::string& tagName = "ImageShuttle") :
00022       ModelComponent(mgr,descrName, tagName),
00023       itsOfs(new OutputFrameSeries(mgr))
00024   {
00025     addSubComponent(itsOfs);
00026   }
00027 
00028     void start2()
00029     {
00030       IceUtil::ThreadPtr thread = this;
00031       thread->start();
00032     }
00033 
00034     void transferImage(const ImageIce& s, const Ice::Current&)
00035     {
00036       std::vector<unsigned char> bytes = s.data;
00037       itsImage = itsDecompressor.DecompressImage(bytes);
00038     }
00039 
00040     void run()
00041     {
00042       while(1)
00043       {
00044         itsImageMutex.lock();
00045         {
00046           if(itsImage.initialized())
00047             itsOfs->writeRGB(itsImage, "Input");
00048         }
00049         itsImageMutex.unlock();
00050       }
00051 
00052     }
00053 
00054   private:
00055     Image<PixRGB<byte> > itsImage;
00056     nub::ref<OutputFrameSeries> itsOfs;
00057     IceUtil::Mutex itsImageMutex;
00058     JPEGDecompressor itsDecompressor;
00059 };
00060 
00061 
00062 
00063 
00064 int main(int argc, char** argv) {
00065   int status = 0;
00066 
00067   ModelManager manager("EchoImageServerManager");
00068   nub::ref<ImageShuttleI> imageShuttle(new ImageShuttleI(manager));
00069   manager.addSubComponent(imageShuttle);
00070    // Parse command-line:
00071   if (manager.parseCommandLine(argc, argv,
00072         "Usage:: EchoImageServerIce <port> --out=display\n"
00073         "Use the number of your board to determine which port to put here,\n"
00074         "eg. if you have g1 use port 10001. If you have g2, use port 10002,\n"
00075         "and so on...\n", 1, 1)
00076       == false) return(1);
00077 
00078   manager.start();
00079   char buffer[64];
00080   sprintf(buffer,"default -p %s", manager.getExtraArg(0).c_str());
00081 
00082 
00083   Ice::CommunicatorPtr ic;
00084   try {
00085     ic = Ice::initialize(argc, argv);
00086       Ice::ObjectAdapterPtr adapter =
00087         ic->createObjectAdapterWithEndpoints(
00088             "SimpleImageShuttleAdapter", buffer);
00089       Ice::ObjectPtr object = imageShuttle.get();
00090       adapter->add(object, ic->stringToIdentity("SimpleImageShuttle"));
00091       adapter->activate();
00092       ic->waitForShutdown();
00093     } catch (const Ice::Exception& e) {
00094         cerr << e << endl;
00095         status = 1;
00096     } catch (const char* msg) {
00097         cerr << msg << endl;
00098         status = 1;
00099     }
00100     if (ic) {
00101         try {
00102           ic->destroy();
00103 } catch (const Ice::Exception& e) {
00104             cerr << e << endl;
00105             status = 1;
00106         }
00107     }
00108     return status;
00109 
00110 
00111 
00112   return 1;
00113 }
00114 
00115 
Generated on Sun May 8 08:04:51 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3