Home | History | Annotate | Download | only in app
      1 //
      2 // Copyright 2005 The Android Open Source Project
      3 //
      4 // Create or attach to a named bi-directional channel on the local machine.
      5 //
      6 #ifndef __LIBS_LOCALBICHANNEL_H
      7 #define __LIBS_LOCALBICHANNEL_H
      8 
      9 #ifdef HAVE_ANDROID_OS
     10 #error DO NOT USE THIS FILE IN THE DEVICE BUILD
     11 #endif
     12 
     13 #include "Pipe.h"
     14 
     15 namespace android {
     16 
     17 /*
     18  * This is essentially a wrapper class for UNIX-domain sockets.  The
     19  * idea is to set one up with create() or attach to one with attach()
     20  * and then extract the unidirectional read/write Pipes.  These can
     21  * be used directly or stuffed into a MessageStream.
     22  *
     23  * The name for the pipe should be a short filename made up of alphanumeric
     24  * characters.  Depending on the implementation, we may create a file in
     25  * /tmp with the specified name, removing any existing copy.
     26  */
     27 class LocalBiChannel {
     28 public:
     29     LocalBiChannel(void);
     30     ~LocalBiChannel(void);
     31 
     32     /* create the "listen" side */
     33     bool create(const char* name);
     34 
     35     /*
     36      * Listen for a connection.  When we get one, we create unidirectional
     37      * read/write pipes and return them.
     38      */
     39     bool listen(Pipe** ppReadPipe, Pipe** ppWritePipe);
     40 
     41     /*
     42      * Attach to a channel created by somebody else.  Returns pipes.
     43      */
     44     bool attach(const char* name, Pipe** ppReadPipe, Pipe** ppWritePipe);
     45 
     46 private:
     47     char*       mFileName;
     48     bool        mIsListener;
     49     unsigned long mHandle;
     50 };
     51 
     52 }; // namespace android
     53 
     54 #endif // __LIBS_LOCALBICHANNEL_H
     55