1 : /*
2 : * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 : // C++ wrapper around C reverse service objects.
8 :
9 : #ifndef NATIVE_CLIENT_SRC_TRUSTED_REVERSE_SERVICE_REVERSE_SOCKET_H_
10 : #define NATIVE_CLIENT_SRC_TRUSTED_REVERSE_SERVICE_REVERSE_SOCKET_H_
11 :
12 : #include "native_client/src/include/nacl_macros.h"
13 :
14 : #include "native_client/src/trusted/simple_service/nacl_simple_rservice.h"
15 :
16 : #include "native_client/src/trusted/threading/nacl_thread_interface.h"
17 :
18 : namespace nacl {
19 :
20 : class DescWrapper;
21 :
22 : // This class is an IMC client that connects to an IMC server but then
23 : // behaves as an SRPC server. The IMC server runs callbacks that
24 : // takes ownership of the connected socket for use as SRPC clients
25 : // (perhaps passing to other threads).
26 :
27 : class ReverseSocket {
28 : public:
29 :
30 : // Ctor takes ownership of conn_cap. Both handlers and
31 : // server_instance_data is shared with the caller and is expected to
32 : // have lifetimes that are not shorter than the constructed
33 : // ReverseSocket.
34 : ReverseSocket(nacl::DescWrapper* conn_cap,
35 : NaClSrpcHandlerDesc const* handlers,
36 : NaClThreadIfFactoryFunction thread_factory_fn,
37 2 : void* thread_factory_data)
38 : : conn_cap_(conn_cap),
39 : handlers_(handlers),
40 : thread_factory_fn_(thread_factory_fn),
41 : thread_factory_data_(thread_factory_data),
42 2 : rev_service_(NULL) {}
43 :
44 : ~ReverseSocket(); // dtor will delete conn_cap
45 :
46 : bool StartServiceCb(void (*exit_cb)(void *server_instance_data,
47 : int server_loop_ret),
48 : void *server_instance_data);
49 :
50 : /* StartService just invokes StartServiceCb with exit_cb boudn to NULL */
51 : bool StartService(void* server_instance_data);
52 :
53 : private:
54 : NACL_DISALLOW_COPY_AND_ASSIGN(ReverseSocket);
55 :
56 : nacl::DescWrapper* conn_cap_;
57 : NaClSrpcHandlerDesc const* handlers_;
58 :
59 : NaClThreadIfFactoryFunction thread_factory_fn_;
60 : void* thread_factory_data_;
61 : NaClSimpleRevService* rev_service_;
62 : };
63 : } // namespace nacl
64 :
65 : #endif
|