]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - linux/src/api/NameServer.c
Add missing transport header files to Linux install command
[ipc/ipcdev.git] / linux / src / api / NameServer.c
1 /*
2  * Copyright (c) 2012-2014, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*
33  *  ======== NameServer_client.c ========
34  */
35 #include <ti/ipc/Std.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <errno.h>
41 #include <sys/stat.h>
42 #include <sys/types.h>
43 #include <unistd.h>
44 #include <time.h>
45 #include <pthread.h>
47 #include <ti/ipc/NameServer.h>
49 #include <ladclient.h>
50 #include <_lad.h>
52 /* traces in this file are controlled via _NameServer_verbose */
53 Bool _NameServer_verbose = FALSE;
54 #define verbose _NameServer_verbose
56 /*
57  * The NameServer_*() APIs are reproduced here.  These versions are just
58  * front-ends for communicating with the actual NameServer module (currently
59  * implemented as a daemon process ala LAD).
60  */
62 Int NameServer_setup(Void)
63 {
64     Int status;
65     LAD_ClientHandle handle;
66     struct LAD_CommandObj cmd;
67     union LAD_ResponseObj rsp;
69     handle = LAD_findHandle();
70     if (handle == LAD_MAXNUMCLIENTS) {
71         PRINTVERBOSE1(
72           "NameServer_setup: can't find connection to daemon for pid %d\n",
73            getpid())
75         return NameServer_E_RESOURCE;
76     }
78     cmd.cmd = LAD_NAMESERVER_SETUP;
79     cmd.clientId = handle;
81     if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
82         PRINTVERBOSE1(
83           "NameServer_setup: sending LAD command failed, status=%d\n", status)
84         return NameServer_E_FAIL;
85     }
87     if ((status = LAD_getResponse(handle, &rsp)) != LAD_SUCCESS) {
88         PRINTVERBOSE1("NameServer_setup: no LAD response, status=%d\n", status)
89         return(status);
90     }
91     status = rsp.status;
93     PRINTVERBOSE2(
94       "NameServer_setup: got LAD response for client %d, status=%d\n",
95       handle, status)
97     return status;
98 }
100 Int NameServer_destroy(Void)
102     Int status;
103     LAD_ClientHandle handle;
104     struct LAD_CommandObj cmd;
105     union LAD_ResponseObj rsp;
107     PRINTVERBOSE0("NameServer_destroy: entered\n")
109     handle = LAD_findHandle();
110     if (handle == LAD_MAXNUMCLIENTS) {
111         PRINTVERBOSE1(
112           "NameServer_destroy: can't find connection to daemon for pid %d\n",
113           getpid())
115         return NameServer_E_RESOURCE;
116     }
118     cmd.cmd = LAD_NAMESERVER_DESTROY;
119     cmd.clientId = handle;
121     if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
122         PRINTVERBOSE1(
123           "NameServer_destroy: sending LAD command failed, status=%d\n", status)
124         return NameServer_E_FAIL;
125     }
127     if ((status = LAD_getResponse(handle, &rsp)) != LAD_SUCCESS) {
128         PRINTVERBOSE1(
129           "NameServer_destroy: no LAD response, status=%d\n", status)
130         return(status);
131     }
132     status = rsp.status;
134     PRINTVERBOSE2(
135      "NameServer_destroy: got LAD response for client %d, status=%d\n",
136      handle, status)
138     return status;
141 Void NameServer_Params_init(NameServer_Params *params)
143     Int status;
144     LAD_ClientHandle handle;
145     struct LAD_CommandObj cmd;
146     union LAD_ResponseObj rsp;
148     handle = LAD_findHandle();
149     if (handle == LAD_MAXNUMCLIENTS) {
150         PRINTVERBOSE1(
151          "NameServer_Params_init: can't find connection to daemon for pid %d\n",
152          getpid())
154         return;
155     }
157     cmd.cmd = LAD_NAMESERVER_PARAMS_INIT;
158     cmd.clientId = handle;
160     if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
161         PRINTVERBOSE1(
162           "NameServer_Params_init: sending LAD command failed, status=%d\n",
163           status)
164         return;
165     }
167     if ((status = LAD_getResponse(handle, &rsp)) != LAD_SUCCESS) {
168         PRINTVERBOSE1(
169           "NameServer_Params_init: no LAD response, status=%d\n", status)
170         return;
171     }
173     PRINTVERBOSE1("NameServer_Params_init: got LAD response for client %d\n",
174                   handle)
176     memcpy(params, &rsp.params, sizeof(NameServer_Params));
178     return;
181 NameServer_Handle NameServer_create(String name,
182                                     const NameServer_Params *params)
184     Int status;
185     LAD_ClientHandle handle;
186     struct LAD_CommandObj cmd;
187     union LAD_ResponseObj rsp;
189     handle = LAD_findHandle();
190     if (handle == LAD_MAXNUMCLIENTS) {
191         PRINTVERBOSE1(
192           "NameServer_create: can't find connection to daemon for pid %d\n",
193           getpid())
195         return NULL;
196     }
198     cmd.cmd = LAD_NAMESERVER_CREATE;
199     cmd.clientId = handle;
200     strncpy(cmd.args.create.name, name, NameServer_Params_MAXNAMELEN);
201     memcpy(&cmd.args.create.params, params, sizeof(NameServer_Params));
203     if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
204         PRINTVERBOSE1(
205           "NameServer_create: sending LAD command failed, status=%d\n",
206           status)
207         return NULL;
208     }
210     if ((status = LAD_getResponse(handle, &rsp)) != LAD_SUCCESS) {
211         PRINTVERBOSE1("NameServer_create: no LAD response, status=%d\n", status)
212         return NULL;
213     }
215     PRINTVERBOSE1("NameServer_create: got LAD response for client %d\n", handle)
217     return rsp.handle;
220 Ptr NameServer_add(NameServer_Handle nsHandle, String name, Ptr buf,
221                    UInt32 len)
223     Int status;
224     LAD_ClientHandle clHandle;
225     struct LAD_CommandObj cmd;
226     union LAD_ResponseObj rsp;
228     clHandle = LAD_findHandle();
229     if (clHandle == LAD_MAXNUMCLIENTS) {
230         PRINTVERBOSE1(
231           "NameServer_add: can't find connection to daemon for pid %d\n",
232           getpid())
234         return NULL;
235     }
237     cmd.cmd = LAD_NAMESERVER_ADD;
238     cmd.clientId = clHandle;
239     cmd.args.add.handle = nsHandle;
240     strncpy(cmd.args.add.name, name, LAD_MAXENTRYNAMELEN);
241     cmd.args.add.len = len;
243     if (buf != NULL) {
244         memcpy(cmd.args.add.buf, buf, len);
245     }
247     if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
248         PRINTVERBOSE1(
249           "NameServer_add: sending LAD command failed, status=%d\n",
250           status)
251         return NULL;
252     }
254     if ((status = LAD_getResponse(clHandle, &rsp)) != LAD_SUCCESS) {
255         PRINTVERBOSE1(
256            "NameServer_add: no LAD response, status=%d\n", status)
257         return NULL;
258     }
260     PRINTVERBOSE1(
261        "NameServer_add: got LAD response for client %d\n", clHandle)
263     return rsp.entryPtr;
266 Int NameServer_get(NameServer_Handle nsHandle, String name, Ptr buf,
267                    UInt32 * len, UInt16 procId[])
269     Int status;
270     LAD_ClientHandle clHandle;
271     struct LAD_CommandObj cmd;
272     union LAD_ResponseObj rsp;
274     clHandle = LAD_findHandle();
275     if (clHandle == LAD_MAXNUMCLIENTS) {
276         PRINTVERBOSE1(
277           "NameServer_get: can't find connection to daemon for pid %d\n",
278            getpid())
280         return NameServer_E_RESOURCE;
281     }
283     cmd.cmd = LAD_NAMESERVER_GET;
284     cmd.clientId = clHandle;
285     cmd.args.get.handle = nsHandle;
286     strncpy(cmd.args.get.name, name, LAD_MAXENTRYNAMELEN);
287     if (procId != NULL) {
288         memcpy(cmd.args.get.procId, procId,
289                sizeof(UInt16) * MultiProc_MAXPROCESSORS);
290     }
291     else {
292         cmd.args.get.procId[0] = (UInt16)-1;
293     }
295     cmd.args.get.len = *len;
297     if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
298         PRINTVERBOSE1(
299            "NameServer_get: sending LAD command failed, status=%d\n",
300             status)
301         return NameServer_E_FAIL;
302     }
304     if ((status = LAD_getResponse(clHandle, &rsp)) != LAD_SUCCESS) {
305         PRINTVERBOSE1("NameServer_get: no LAD response, status=%d\n",
306                        status)
307         return NameServer_E_FAIL;
308     }
310     *len = rsp.get.len;
311     if (rsp.get.buf != NULL) {
312         memcpy(buf, rsp.get.buf, *len);
313     }
315     status = rsp.status;
317     PRINTVERBOSE1("NameServer_get: got LAD response for client %d\n",
318                    clHandle)
320     return status;
323 Ptr NameServer_addUInt32(NameServer_Handle nsHandle, String name, UInt32 value)
325     Int status;
326     LAD_ClientHandle clHandle;
327     struct LAD_CommandObj cmd;
328     union LAD_ResponseObj rsp;
330     clHandle = LAD_findHandle();
331     if (clHandle == LAD_MAXNUMCLIENTS) {
332         PRINTVERBOSE1(
333           "NameServer_addUInt32: can't find connection to daemon for pid %d\n",
334           getpid())
336         return NULL;
337     }
339     cmd.cmd = LAD_NAMESERVER_ADDUINT32;
340     cmd.clientId = clHandle;
341     cmd.args.addUInt32.handle = nsHandle;
342     strncpy(cmd.args.addUInt32.name, name, LAD_MAXENTRYNAMELEN);
343     cmd.args.addUInt32.val = value;
345     if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
346         PRINTVERBOSE1(
347           "NameServer_addUInt32: sending LAD command failed, status=%d\n",
348           status)
349         return NULL;
350     }
352     if ((status = LAD_getResponse(clHandle, &rsp)) != LAD_SUCCESS) {
353         PRINTVERBOSE1(
354            "NameServer_addUInt32: no LAD response, status=%d\n", status)
355         return NULL;
356     }
358     PRINTVERBOSE1(
359        "NameServer_addUInt32: got LAD response for client %d\n", clHandle)
361     return rsp.entryPtr;
364 Int NameServer_getUInt32(NameServer_Handle nsHandle, String name, Ptr buf,
365                           UInt16 procId[])
367     Int status;
368     LAD_ClientHandle clHandle;
369     UInt32 *val;
370     struct LAD_CommandObj cmd;
371     union LAD_ResponseObj rsp;
373     clHandle = LAD_findHandle();
374     if (clHandle == LAD_MAXNUMCLIENTS) {
375         PRINTVERBOSE1(
376           "NameServer_getUInt32: can't find connection to daemon for pid %d\n",
377            getpid())
379         return NameServer_E_RESOURCE;
380     }
382     cmd.cmd = LAD_NAMESERVER_GETUINT32;
383     cmd.clientId = clHandle;
384     cmd.args.getUInt32.handle = nsHandle;
385     strncpy(cmd.args.getUInt32.name, name, LAD_MAXENTRYNAMELEN);
386     if (procId != NULL) {
387         memcpy(cmd.args.getUInt32.procId, procId,
388                sizeof(UInt16) * MultiProc_MAXPROCESSORS);
389     }
390     else {
391         cmd.args.getUInt32.procId[0] = (UInt16)-1;
392     }
394     if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
395         PRINTVERBOSE1(
396            "NameServer_getUInt32: sending LAD command failed, status=%d\n",
397             status)
398         return NameServer_E_FAIL;
399     }
401     if ((status = LAD_getResponse(clHandle, &rsp)) != LAD_SUCCESS) {
402         PRINTVERBOSE1("NameServer_getUInt32: no LAD response, status=%d\n",
403                        status)
404         return NameServer_E_FAIL;
405     }
407     val = (UInt32 *)buf;
408     *val = rsp.getUInt32.val;
409     status = rsp.status;
411     PRINTVERBOSE1("NameServer_getUInt32: got LAD response for client %d\n",
412                    clHandle)
414     return status;
417 Int NameServer_remove(NameServer_Handle nsHandle, String name)
419     Int status;
420     LAD_ClientHandle clHandle;
421     struct LAD_CommandObj cmd;
422     union LAD_ResponseObj rsp;
424     clHandle = LAD_findHandle();
425     if (clHandle == LAD_MAXNUMCLIENTS) {
426         PRINTVERBOSE1(
427          "NameServer_remove: can't find connection to daemon for pid %d\n",
428          getpid())
430         return NameServer_E_RESOURCE;
431     }
433     cmd.cmd = LAD_NAMESERVER_REMOVE;
434     cmd.clientId = clHandle;
435     cmd.args.remove.handle = nsHandle;
436     strncpy(cmd.args.remove.name, name, LAD_MAXENTRYNAMELEN);
438     if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
439         PRINTVERBOSE1(
440          "NameServer_remove: sending LAD command failed, status=%d\n",
441          status)
442         return NameServer_E_FAIL;
443     }
445     if ((status = LAD_getResponse(clHandle, &rsp)) != LAD_SUCCESS) {
446         PRINTVERBOSE1("NameServer_remove: no LAD response, status=%d\n", status)
447         return NameServer_E_FAIL;
448     }
450     status = rsp.status;
452     PRINTVERBOSE1("NameServer_remove: got LAD response for client %d\n",
453                    clHandle)
455     return status;
458 Int NameServer_removeEntry(NameServer_Handle nsHandle, Ptr entry)
460     Int status;
461     LAD_ClientHandle clHandle;
462     struct LAD_CommandObj cmd;
463     union LAD_ResponseObj rsp;
465     clHandle = LAD_findHandle();
466     if (clHandle == LAD_MAXNUMCLIENTS) {
467         PRINTVERBOSE1(
468          "NameServer_removeEntry: can't find connection to daemon for pid %d\n",
469          getpid())
471         return NameServer_E_RESOURCE;
472     }
474     cmd.cmd = LAD_NAMESERVER_REMOVEENTRY;
475     cmd.clientId = clHandle;
476     cmd.args.removeEntry.handle = nsHandle;
477     cmd.args.removeEntry.entryPtr = entry;
479     if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
480         PRINTVERBOSE1(
481           "NameServer_removeEntry: sending LAD command failed, status=%d\n",
482           status)
483         return NameServer_E_FAIL;
484     }
486     if ((status = LAD_getResponse(clHandle, &rsp)) != LAD_SUCCESS) {
487         PRINTVERBOSE1("NameServer_removeEntry: no LAD response, status=%d\n",
488                        status)
489         return NameServer_E_FAIL;
490     }
492     status = rsp.status;
494     PRINTVERBOSE1("NameServer_removeEntry: got LAD response for client %d\n",
495                    clHandle)
497     return status;
500 Int NameServer_delete(NameServer_Handle *nsHandle)
502     Int status;
503     LAD_ClientHandle clHandle;
504     struct LAD_CommandObj cmd;
505     union LAD_ResponseObj rsp;
507     clHandle = LAD_findHandle();
508     if (clHandle == LAD_MAXNUMCLIENTS) {
509         PRINTVERBOSE1(
510           "NameServer_delete: can't find connection to daemon for pid %d\n",
511           getpid())
513         return NameServer_E_RESOURCE;
514     }
516     cmd.cmd = LAD_NAMESERVER_DELETE;
517     cmd.clientId = clHandle;
518     cmd.args.delete.handle = *nsHandle;
520     if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
521         PRINTVERBOSE1(
522           "NameServer_delete: sending LAD command failed, status=%d\n",
523           status)
524         return NameServer_E_FAIL;
525     }
527     if ((status = LAD_getResponse(clHandle, &rsp)) != LAD_SUCCESS) {
528         PRINTVERBOSE1("NameServer_delete: no LAD response, status=%d\n", status)
529         return NameServer_E_FAIL;
530     }
532     *nsHandle = rsp.delete.handle;
533     status = rsp.status;
535     PRINTVERBOSE1("NameServer_delete: got LAD response for client %d\n",
536                    clHandle)
538     return status;