HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_NamedPipe.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_NamedPipe.h ( UT Library, C++)
7  *
8  * COMMENTS: This is a read pipe which gets around the problem of having a
9  * broken pipe if you close before reading all of the input from
10  * the pipe command.
11  */
12 
13 #ifndef __UT_NamedPipe__
14 #define __UT_NamedPipe__
15 
16 #include "UT_API.h"
17 #include "UT_NonCopyable.h"
18 #include "UT_String.h"
19 
20 #include <SYS/SYS_Handle.h>
21 
22 #if defined(LINUX) || defined(MBSD)
23  #include <stdio.h>
24 #endif
25 
27 public:
28  explicit UT_NamedPipe(SYS_Handle *filehandle);
29 
30  // If the pipe is open and destructed, the process will be killed.
31  ~UT_NamedPipe();
32 
34 
35  // Returns 1 if the pipe is open, 0 otherwise.
36  int isOpen() const;
37 
38  // Create a named pipe of the given name. Returns 0 on error, 1 on success.
39  // Created pipes are all write-only.
40  int create(const char *filename, bool blocking_pipe = false);
41 
42  // Open a named pipe ofh the given name. Returns 0 on error, 1 on success.
43  // Opened pipes are all read only.
44  int open(const char *filename);
45 
46  // Close the pipe.
47  void close();
48 
49  // Read up to the specified number of bytes. Returns the number of bytes
50  // actually read. This call never blocks.
51  int read(char *data, int len);
52 
53  // Prepare named pipe for writing. Call this before doing a block
54  // of writes. Under NT it makes sure the pipe is connected. Does
55  // nothing under SGI.
56  void prepWrite();
57 
58  // Write the specified number of bytes. Returns the number of bytes
59  // actually read. This call blocks until all bytes have been written.
60  int write(const char *data, int len);
61 
62  // Flush input or output.
63  void flush();
64 
65  // Returns 1 if there is data to be read, 0 if not, and less
66  // than 0 if error.
67  int dataAvailable();
68 
69 private:
70 
71  SYS_Handle *myFileHandle;
72 
73  int myCreated;
74  UT_String myFileName;
75  int myBytePending;
76  char myNextByte;
77 #ifndef WIN32
78  FILE *myPipe;
79 #endif
80 };
81 
82 #endif
GT_API const UT_StringHolder filename
#define UT_API
Definition: UT_API.h:14
void close() override
int open(float queuesize) override
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
Definition: format.h:895