2 * Copyright (c) 2009 Martin Decky
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <ipc/services.h>
41 #include <loader/loader.h>
45 /** Request for connection to a clonable service. */
53 /** List of clonable-service connection requests. */
56 int clonable_init(void)
58 list_initialize(&cs_req
);
62 /** Return true if @a service is clonable. */
63 bool service_clonable(int service
)
65 return (service
== SERVICE_LOAD
);
68 /** Register clonable service.
70 * @param service Service to be registered.
71 * @param phone Phone to be used for connections to the service.
72 * @param call Pointer to call structure.
75 void register_clonable(sysarg_t service
, sysarg_t phone
, ipc_call_t
*call
,
80 req_link
= list_first(&cs_req
);
81 if (req_link
== NULL
) {
82 /* There was no pending connection request. */
83 printf("%s: Unexpected clonable server.\n", NAME
);
84 ipc_answer_0(callid
, EBUSY
);
88 cs_req_t
*csr
= list_get_instance(req_link
, cs_req_t
, link
);
89 list_remove(req_link
);
91 /* Currently we can only handle a single type of clonable service. */
92 assert(csr
->service
== SERVICE_LOAD
);
94 ipc_answer_0(callid
, EOK
);
96 ipc_forward_fast(csr
->callid
, phone
, IPC_GET_ARG2(csr
->call
),
97 IPC_GET_ARG3(csr
->call
), 0, IPC_FF_NONE
);
103 /** Connect client to clonable service.
105 * @param service Service to be connected to.
106 * @param call Pointer to call structure.
107 * @param callid Call ID of the request.
109 * @return Zero on success or a value from @ref errno.h.
112 void connect_to_clonable(sysarg_t service
, ipc_call_t
*call
,
115 assert(service
== SERVICE_LOAD
);
117 cs_req_t
*csr
= malloc(sizeof(cs_req_t
));
119 ipc_answer_0(callid
, ENOMEM
);
123 /* Spawn a loader. */
124 int rc
= loader_spawn("loader");
128 ipc_answer_0(callid
, rc
);
132 link_initialize(&csr
->link
);
133 csr
->service
= service
;
135 csr
->callid
= callid
;
138 * We can forward the call only after the server we spawned connects
139 * to us. Meanwhile we might need to service more connection requests.
140 * Thus we store the call in a queue.
142 list_append(&csr
->link
, &cs_req
);