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 name_attach_t* attach_info;
00022 int rcvid;
00023 char* name;
00024 size_t nameLen;
00025
00026
00027
00028
00029 pthread_barrier_t barrier1_ServerStarted;
00030 pthread_barrier_t barrier2_ClientFinished;
00031
00032 public:
00033 NameSpace( const char* name0 = "myname", int nbClients = 1, int nbServers = 1 );
00034
00035 virtual ~NameSpace();
00036
00037 void Nattach( const char* name0 = NULL );
00038 void Ndetach();
00039
00040 int Nopen( const char* name0 = NULL );
00041 void Nclose( int fd );
00042
00043 void initName( const char* name0 = NULL );
00044
00045 inline int getChannel() { return attach_info->chid; }
00046
00047 inline void initSync( size_t nbServers, size_t nbClients )
00048 {
00049
00050 pthread_barrier_init( &barrier1_ServerStarted, NULL, nbServers + 1 );
00051 pthread_barrier_init( &barrier2_ClientFinished, NULL, nbClients + 1 );
00052 }
00053
00054 inline void waitForServer()
00055 {
00056 pthread_barrier_wait( &barrier1_ServerStarted );
00057 }
00058
00059 inline void waitForClient()
00060 {
00061 pthread_barrier_wait( &barrier1_ServerStarted );
00062 }
00063
00064 inline const char* getName() { return (const char*)name; }
00065
00066 private:
00067 inline NameSpace( const NameSpace& src );
00068 inline const NameSpace& operator=( const NameSpace& src );
00069 };
00070
00071
00072 #endif // End of NameSpace.hpp