More clean-ups
[invirt/third/libt4.git] / handle.h
1 #ifndef handle_h
2 #define handle_h
3
4 #include "types.h"
5 #include "rpc/rpc.h"
6
7 // Manage a cache of RPC connections.  Typical usage:
8 //     handle h(dst);
9 //     rpc_protocol::status ret = rpc_protocol::bind_failure;
10 //     if (rpcc *cl = h.safebind())
11 //         ret = cl->call(...);
12 // assuming dst is a string holding the host:port of the RPC server you want to
13 // talk to.
14 //
15 // If the calling program has not contacted dst before, safebind() will create
16 // a new connection, call bind(), and return an rpcc*, or 0 if bind() failed.
17 // if the program has previously contacted dst, safebind() just returns the
18 // previously created rpcc*.  Because safebind() may block, callers should
19 // probably not hold mutexes.
20
21 class handle {
22     private:
23         shared_ptr<class hinfo> h;
24         const string destination_;
25     public:
26         handle(const string & destination);
27         rpcc *safebind();
28         void invalidate();
29 };
30
31 #endif