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.
7 #ifndef NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_NAME_SERVICE_NAME_SERVICE_H_
8 #define NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_NAME_SERVICE_NAME_SERVICE_H_
10 #include "native_client/src/include/nacl_base.h"
11 #include "native_client/src/include/portability.h"
13 /* Get NACL_NAME_SERVICE_CONNECTION_MAX. */
14 #include "native_client/src/public/name_service.h"
16 #include "native_client/src/trusted/desc/nacl_desc_base.h"
18 #include "native_client/src/trusted/simple_service/nacl_simple_service.h"
19 #include "native_client/src/trusted/simple_service/nacl_simple_ltd_service.h"
21 #include "native_client/src/trusted/threading/nacl_thread_interface.h"
26 * NaClStartNameService should only be called once, and also serves
27 * as a module initializer.
29 * This function creates a bound socket / socket address pair, and
30 * spawns a thread that accepts connections on the bound socket and
31 * services requests on the resultant connections. A maximum number
32 * of connections is defined, since well-behaving programs should not
33 * need more than one (absent excessive opaque layering/abstractions)
34 * name service lookup connection.
36 * The socket address NaClDescConnCap is returned, to be entered into
37 * the NaClApp's open file table at a well-known location.
40 struct NaClNameServiceEntry; /* fwd */
42 struct NaClNameService {
43 struct NaClSimpleLtdService base NACL_IS_REFCOUNT_SUBCLASS;
47 * |mu| protects the service entries hanging off of |head|.
49 struct NaClNameServiceEntry *head;
52 int NaClNameServiceCtor(struct NaClNameService *self,
53 NaClThreadIfFactoryFunction thread_factory_fn,
54 void *thread_factory_data);
56 int NaClNameServiceCreateDescEntry(
57 struct NaClNameService *self,
60 struct NaClDesc *new_desc); /* takes ownership of ref */
62 typedef int (*NaClNameServiceFactoryFn_t)(void *factory_state,
65 struct NaClDesc **out);
67 int NaClNameServiceCreateFactoryEntry(
68 struct NaClNameService *self,
71 * If a |name| corresponding to a factory is overwritten,
72 * references to the factory and its state is just dropped/lost
73 * after invoking the factory with a NULL for the |out| argument;
74 * the factory function should decrement reference counts as
75 * appropriate and clean up when this occurs.
77 NaClNameServiceFactoryFn_t factory_fn,
80 int NaClNameServiceResolveName(
81 struct NaClNameService *self,
84 struct NaClDesc **out);
86 int NaClNameServiceDeleteName(struct NaClNameService *nnsp,
89 size_t NaClNameServiceEnumerate(struct NaClNameService *nnsp,
93 struct NaClNameServiceVtbl {
94 struct NaClSimpleServiceVtbl vbase;
96 * The following functions return 0 for success, and non-zero to
97 * indicate the reason for failure. The set of possible failures is
98 * in src/public/name_service.h.
100 * They don't really have to be virtual, but this makes it easier to
101 * subclass and modify later, should the need occur.
103 int (*CreateDescEntry)(
104 struct NaClNameService *self,
107 struct NaClDesc *new_desc); /* takes ownership of ref */
108 int (*CreateFactoryEntry)(
109 struct NaClNameService *self,
111 NaClNameServiceFactoryFn_t factory_fn,
112 void *factory_state);
114 struct NaClNameService *self,
117 struct NaClDesc **out);
119 struct NaClNameService *self,
123 extern struct NaClNameServiceVtbl kNaClNameServiceVtbl;
125 void NaClNameServiceLaunch(struct NaClNameService *self);
130 /* NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_NAME_SERVICE_NAME_SERVICE_H_ */