Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/nto/NameSpace.hpp

Go to the documentation of this file.
00001 #ifndef __J2K__NameSpace_HPP__
00002 #define __J2K__NameSpace_HPP__
00003 
00004 #include <j2k/Fred/Standard.hpp>
00005 #include <j2k/nto/Basic_PThread.hpp>
00006 #include <j2k/nto/Message.hpp>
00007 
00008 #include <stdio.h>
00009 #include <errno.h>
00010 #include <stdlib.h>
00011 #include <string.h>
00012 #include <pthread.h>
00013 #include <sys/neutrino.h>
00014 #include <sys/dispatch.h>
00015 
00016 #define ATTACH_POINT  "myname"
00017 
00018 class NameSpace 
00019 { 
00020 private:
00021   char*  name;
00022   size_t nameLen;
00023   name_attach_t* attach_info;
00024   int    rcvid;
00025 
00026   // Creation/Destruction Synchronization mechanisms
00027   // Make sure Servers are started  before Clients can query
00028   // Make sure Clients are started  before any Clients can query
00029   // Make sure Clients are finished before the main() caller can exit.
00030   pthread_barrier_t  barrier1_ServerStarted;
00031   pthread_barrier_t  barrier2_ClientStarted;
00032   pthread_barrier_t  barrier3_ClientFinished;
00033 
00034 public:
00035   NameSpace(    const char* name0 = "myname", size_t nbConsumers = 1, size_t nbProducers = 1, size_t nbServers = 1 );
00036 
00037   virtual ~NameSpace();
00038 
00039   void Nattach( const char* name0 = NULL );
00040   void Ndetach();
00041 
00042   int  Nopen(   const char* name0 = NULL );
00043   void Nclose( int fd );
00044 
00045   void initName( const char* name0 = NULL );
00046 
00047   inline int getChannel()  {   return attach_info->chid;   }
00048 
00049   inline void initSync( size_t nbConsumers = 1, size_t nbProducers = 1, size_t nbServers = 1 )
00050   {
00051     // Add 1 each for the caller.
00052     pthread_barrier_init( &barrier1_ServerStarted,  NULL, nbServers + 1 );
00053     pthread_barrier_init( &barrier2_ClientStarted,  NULL, nbConsumers + nbProducers + 1 );
00054     pthread_barrier_init( &barrier3_ClientFinished, NULL, nbConsumers + 1 );
00055   }
00056 
00057   inline void waitForServer()
00058   {
00059     pthread_barrier_wait( &barrier1_ServerStarted );
00060   }
00061 
00062   inline void waitForThreads()
00063   {
00064     pthread_barrier_wait( &barrier2_ClientStarted );
00065   }
00066 
00067   inline void waitForClient()
00068   {
00069     pthread_barrier_wait( &barrier3_ClientFinished );
00070   }
00071 
00072   inline const char* getName() { return (const char*)name; }
00073 
00074 private:
00075   inline NameSpace( const NameSpace& src );
00076   inline const NameSpace& operator=( const NameSpace& src );
00077 };
00078 
00079 
00080 #endif  // End of NameSpace.hpp

Generated on Sun Oct 14 18:46:39 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001