Added additional argument to RPC_make_arg_list and RPC_undo_arg_list to
[dyninst.git] / pdutil / h / rpcUtil.h
1
2 #ifndef RPC_UTIL
3 #define RPC_UTIL
4
5 /*
6  * $Log: rpcUtil.h,v $
7  * Revision 1.26  1994/11/11 06:59:09  markc
8  * Added additional argument to RPC_make_arg_list and RPC_undo_arg_list to
9  * support remote executition for paradyndPVM.
10  *
11  * Revision 1.25  1994/11/01  16:07:33  markc
12  * Added Object classes that provide os independent symbol tables.
13  * Added stl-like container classes with iterators.
14  *
15  * Revision 1.24  1994/10/12  20:22:08  krisna
16  * hpux update
17  *
18  * Revision 1.23  1994/09/22  03:18:05  markc
19  * changes to remove compiler warnings
20  * changed pid passed to RPCprocessCreate
21  *
22  * Revision 1.22  1994/08/17  18:23:53  markc
23  * Added new classes: Cstring KeyList, KList
24  * Added new function: RPCgetArg
25  * Changed typedefs in machineType.h to #defines
26  *
27  * Revision 1.21  1994/07/28  22:21:26  krisna
28  * changed declaration of xdrIOFunc to conform to prototypes
29  *
30  * Revision 1.20  1994/07/19  18:29:59  markc
31  * Made machineName default to zero as last parameter to RPC_make_arg_list.
32  * Added typecast to malloc call in RPC_make_arg_list.
33  *
34  * Revision 1.19  1994/07/18  19:09:10  hollings
35  * added extra arg to RPC_make_arg_list.
36  *
37  * Revision 1.18  1994/06/02  23:35:15  markc
38  * Modified RPCUser class to support improved error checking for igen.
39  *
40  * Revision 1.17  1994/04/21  23:23:44  hollings
41  * removed paradynd name from make args function.
42  *
43  * Revision 1.16  1994/04/06  22:45:24  markc
44  * Cleaned up rpcUtil.h.  Moved include files to rpcUtil.C where they belonged.
45  *
46  * Revision 1.15  1994/03/31  22:59:04  hollings
47  * added well known port as a paramter to xdrRPC constructor.
48  *
49  * Revision 1.14  1994/03/25  16:07:31  markc
50  * Added option to specify timeout on readReady.
51  *
52  * Revision 1.13  1994/03/20  01:45:23  markc
53  * Changed xdr_Boolean to char rather than int to reflect Boolean change.
54  *
55  * Revision 1.12  1994/03/11  21:01:24  hollings
56  * Changed Boolean from int to char to match X11 convention.
57  *
58  *
59  */
60
61 extern "C" {
62 #include <unistd.h>
63 #include <sys/types.h>
64 #include <sys/socket.h>
65 #include <rpc/types.h>
66 #include <rpc/xdr.h>
67 #include <fcntl.h>
68 }
69
70 #define xdr_Boolean xdr_char
71 typedef XDR *XDRptr;
72 typedef int (*xdrIOFunc)(const void *, char *, int);
73
74 typedef char Boolean;
75
76 extern int RPC_readReady (int fd, int timeout=0);
77
78
79 //
80 // Functions common to server and client side.
81 //
82 class XDRrpc {
83 public:
84   XDRrpc(char *m, char *u, char *p, xdrIOFunc, xdrIOFunc, 
85          char **arg_list=0, int nblock=0, int wellKnownPortFd = 0);
86   XDRrpc(int fd, xdrIOFunc readRoutine, xdrIOFunc writeRoutine, int nblock=0);
87   XDRrpc(int family, int port, int type, char *machine, xdrIOFunc readFunc,
88          xdrIOFunc writeFunc, int nblock=0);
89   ~XDRrpc();
90   inline void setNonBlock() {
91     if (fd >= 0)
92       fcntl (fd, F_SETFL, O_NONBLOCK);
93   }
94   inline void closeConnect() {
95     if (fd >= 0) close(fd); fd = -1;
96   }
97   inline int get_fd() {
98     return fd;
99   }
100   inline int readReady(int timeout=0) {
101     return RPC_readReady (fd, timeout);
102   }
103   inline int getFd() {
104     return fd;
105   }
106   inline int getPid() {
107     return pid;
108   }
109   inline void setPid(int to) {
110     pid = to;
111   }
112   inline XDR *getXdrs() {
113     return __xdrs__;
114   }
115   inline void setDir(xdr_op d) {__xdrs__->x_op = d;}
116  private:
117   XDR *__xdrs__;
118   int fd;
119   int pid;              // pid of child;
120   static int __wellKnownPortFd__;
121 };
122
123 //
124 // common routines that are transport independent.
125 //
126 class RPCBase {
127 public:
128   inline RPCBase(int st=0, int v=0) { err_state = st; versionVerifyDone = v;}
129   // ~RPCBase() { }
130   inline int get_err_state() { return err_state;}
131   inline void clear_err_state() {err_state = 0;}
132   inline int did_error_occur() {return (err_state != 0);}
133   inline int getVersionVerifyDone() { return versionVerifyDone;}
134   inline void setVersionVerifyDone() { versionVerifyDone = 1;}
135   inline void set_err_state(int s) { err_state = s;}
136  private:
137   int versionVerifyDone;
138   int err_state;
139 };
140
141 class THREADrpc {
142 public:
143   inline THREADrpc(int t) { tid = t; }
144   // ~THREADrpc() { }
145   inline void setTid(int id) { tid = id; }
146   inline int getTid() { return tid;}
147
148   // see not on requestingThread, the use of this may be unsafe
149   inline unsigned int getRequestingThread() { return requestingThread; }
150   inline void setRequestingThread(int t) { requestingThread = t;}
151  private:
152   int tid;
153   // these are only to be used by implmentors of thread RPCs.
154   //   the value is only valid during a thread RPC.
155   unsigned int requestingThread;
156 };
157
158 extern int RPC_setup_socket (int *sfd,   // return file descriptor
159                              int family, // AF_INET ...
160                              int type);   // SOCK_STREAM ...
161 extern int xdr_char_PTR (XDR*, char**);
162 extern int RPCprocessCreate(int &pid, const char *hostName, const char *userName,
163                             const char *commandLine, char **arg_list = 0,
164                             int wellKnownPort = 0);
165
166 extern char **RPC_make_arg_list (int family, int type, 
167                                  int port, 
168                                  int flag,
169                                  int firstPVM,
170                                  char *machienName = (char*) 0);
171
172 extern int 
173 RPC_undo_arg_list (int argc, char **arg_list, char **machine, int &family,
174                    int &type, int &well_known_socket, int &flag, int &firstPVM);
175 extern int RPC_getConnect (int fd);
176
177 extern char **RPCgetArg(int &argc, const char *input);
178 #endif