index 84047f01d2bb3e603de43b1cd92d59e4acd366c5..73b43c266182335f37d1a99e91a2162cd2071c66 100644 (file)
/*
- * Copyright (c) 2012, Texas Instruments Incorporated
+ * Copyright (c) 2012-2015 Texas Instruments Incorporated - http://www.ti.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include <ladclient.h>
#include <_lad.h>
-static Bool verbose = FALSE;
-
+/* traces in this file are controlled via _NameServer_verbose */
+Bool _NameServer_verbose = FALSE;
+#define verbose _NameServer_verbose
/*
* The NameServer_*() APIs are reproduced here. These versions are just
return rsp.handle;
}
+Ptr NameServer_add(NameServer_Handle nsHandle, String name, Ptr buf,
+ UInt32 len)
+{
+ Int status;
+ LAD_ClientHandle clHandle;
+ struct LAD_CommandObj cmd;
+ union LAD_ResponseObj rsp;
+
+ clHandle = LAD_findHandle();
+ if (clHandle == LAD_MAXNUMCLIENTS) {
+ PRINTVERBOSE1(
+ "NameServer_add: can't find connection to daemon for pid %d\n",
+ getpid())
+
+ return NULL;
+ }
+
+ cmd.cmd = LAD_NAMESERVER_ADD;
+ cmd.clientId = clHandle;
+ cmd.args.add.handle = nsHandle;
+ strncpy(cmd.args.add.name, name, LAD_MAXENTRYNAMELEN);
+ cmd.args.add.len = len;
+
+ if (buf != NULL) {
+ memcpy(cmd.args.add.buf, buf, len);
+ }
+
+ if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
+ PRINTVERBOSE1(
+ "NameServer_add: sending LAD command failed, status=%d\n",
+ status)
+ return NULL;
+ }
+
+ if ((status = LAD_getResponse(clHandle, &rsp)) != LAD_SUCCESS) {
+ PRINTVERBOSE1(
+ "NameServer_add: no LAD response, status=%d\n", status)
+ return NULL;
+ }
+
+ PRINTVERBOSE1(
+ "NameServer_add: got LAD response for client %d\n", clHandle)
+
+ return rsp.entryPtr;
+}
+
+Int NameServer_get(NameServer_Handle nsHandle, String name, Ptr buf,
+ UInt32 * len, UInt16 procId[])
+{
+ Int status;
+ LAD_ClientHandle clHandle;
+ struct LAD_CommandObj cmd;
+ union LAD_ResponseObj rsp;
+
+ clHandle = LAD_findHandle();
+ if (clHandle == LAD_MAXNUMCLIENTS) {
+ PRINTVERBOSE1(
+ "NameServer_get: can't find connection to daemon for pid %d\n",
+ getpid())
+
+ return NameServer_E_RESOURCE;
+ }
+
+ cmd.cmd = LAD_NAMESERVER_GET;
+ cmd.clientId = clHandle;
+ cmd.args.get.handle = nsHandle;
+ strncpy(cmd.args.get.name, name, LAD_MAXENTRYNAMELEN);
+ if (procId != NULL) {
+ memcpy(cmd.args.get.procId, procId,
+ sizeof(UInt16) * MultiProc_MAXPROCESSORS);
+ }
+ else {
+ cmd.args.get.procId[0] = (UInt16)-1;
+ }
+
+ cmd.args.get.len = *len;
+
+ if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
+ PRINTVERBOSE1(
+ "NameServer_get: sending LAD command failed, status=%d\n",
+ status)
+ return NameServer_E_FAIL;
+ }
+
+ if ((status = LAD_getResponse(clHandle, &rsp)) != LAD_SUCCESS) {
+ PRINTVERBOSE1("NameServer_get: no LAD response, status=%d\n",
+ status)
+ return NameServer_E_FAIL;
+ }
+
+ *len = rsp.get.len;
+ if (rsp.get.buf != NULL) {
+ memcpy(buf, rsp.get.buf, *len);
+ }
+
+ status = rsp.get.status;
+
+ PRINTVERBOSE1("NameServer_get: got LAD response for client %d\n",
+ clHandle)
+
+ return status;
+}
+
Ptr NameServer_addUInt32(NameServer_Handle nsHandle, String name, UInt32 value)
{
Int status;
cmd.cmd = LAD_NAMESERVER_ADDUINT32;
cmd.clientId = clHandle;
cmd.args.addUInt32.handle = nsHandle;
- strncpy(cmd.args.addUInt32.name, name, NameServer_Params_MAXNAMELEN);
+ strncpy(cmd.args.addUInt32.name, name, LAD_MAXENTRYNAMELEN);
cmd.args.addUInt32.val = value;
if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
cmd.cmd = LAD_NAMESERVER_GETUINT32;
cmd.clientId = clHandle;
cmd.args.getUInt32.handle = nsHandle;
- strncpy(cmd.args.getUInt32.name, name, NameServer_Params_MAXNAMELEN);
+ strncpy(cmd.args.getUInt32.name, name, LAD_MAXENTRYNAMELEN);
if (procId != NULL) {
memcpy(cmd.args.getUInt32.procId, procId,
sizeof(UInt16) * MultiProc_MAXPROCESSORS);
val = (UInt32 *)buf;
*val = rsp.getUInt32.val;
- status = rsp.status;
+ status = rsp.getUInt32.status;
PRINTVERBOSE1("NameServer_getUInt32: got LAD response for client %d\n",
clHandle)
return status;
}
+/*
+ * ======== NameServer_getLocal ========
+ */
+Int NameServer_getLocal(NameServer_Handle ns, String name, Ptr buf, UInt32 *len)
+{
+ Int status;
+ LAD_ClientHandle clHandle;
+ struct LAD_CommandObj cmd;
+ union LAD_ResponseObj rsp;
+
+ clHandle = LAD_findHandle();
+
+ if (clHandle == LAD_MAXNUMCLIENTS) {
+ PRINTVERBOSE0("NameServer_getLocal: not connected to LAD\n");
+ return (NameServer_E_RESOURCE);
+ }
+
+ cmd.cmd = LAD_NAMESERVER_GETLOCAL;
+ cmd.clientId = clHandle;
+ cmd.args.getLocal.handle = ns;
+ strncpy(cmd.args.getLocal.name, name, LAD_MAXENTRYNAMELEN);
+ cmd.args.getLocal.len = *len;
+
+ if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
+ PRINTVERBOSE1("NameServer_getLocal: sending LAD command failed, "
+ "status=%d\n", status)
+ return (NameServer_E_FAIL);
+ }
+
+ if ((status = LAD_getResponse(clHandle, &rsp)) != LAD_SUCCESS) {
+ PRINTVERBOSE1("NameServer_getLocal: no LAD response, status=%d\n",
+ status)
+ return (NameServer_E_FAIL);
+ }
+
+ *len = rsp.get.len;
+ if (rsp.get.buf != NULL) {
+ memcpy(buf, rsp.get.buf, *len);
+ }
+
+ status = rsp.get.status;
+
+ PRINTVERBOSE1("NameServer_getLocal: LAD response, status=%d\n", status)
+ return (status);
+}
+
+/*
+ * ======== NameServer_getLocalUInt32 ========
+ */
+Int NameServer_getLocalUInt32(NameServer_Handle ns, String name, Ptr buf)
+{
+ Int status;
+ LAD_ClientHandle clHandle;
+ UInt32 *val;
+ struct LAD_CommandObj cmd;
+ union LAD_ResponseObj rsp;
+
+ clHandle = LAD_findHandle();
+
+ if (clHandle == LAD_MAXNUMCLIENTS) {
+ PRINTVERBOSE0("NameServer_getLocalUInt32: not connected to LAD\n");
+ return (NameServer_E_RESOURCE);
+ }
+
+ cmd.cmd = LAD_NAMESERVER_GETLOCALUINT32;
+ cmd.clientId = clHandle;
+ cmd.args.getLocalUInt32.handle = ns;
+ strncpy(cmd.args.getLocalUInt32.name, name, LAD_MAXENTRYNAMELEN);
+
+ if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
+ PRINTVERBOSE1("NameServer_getLocalUInt32: sending LAD command failed, "
+ "status=%d\n", status)
+ return (NameServer_E_FAIL);
+ }
+
+ if ((status = LAD_getResponse(clHandle, &rsp)) != LAD_SUCCESS) {
+ PRINTVERBOSE1("NameServer_getLocalUInt32: no LAD response, status=%d\n",
+ status)
+ return (NameServer_E_FAIL);
+ }
+
+ val = (UInt32 *)buf;
+ *val = rsp.getUInt32.val;
+ status = rsp.getUInt32.status;
+
+ PRINTVERBOSE1("NameServer_getLocalUInt32: LAD response, status=%d\n",
+ status)
+ return (status);
+}
+
Int NameServer_remove(NameServer_Handle nsHandle, String name)
{
Int status;
cmd.cmd = LAD_NAMESERVER_REMOVE;
cmd.clientId = clHandle;
cmd.args.remove.handle = nsHandle;
- strncpy(cmd.args.remove.name, name, NameServer_Params_MAXNAMELEN);
+ strncpy(cmd.args.remove.name, name, LAD_MAXENTRYNAMELEN);
if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
PRINTVERBOSE1(
cmd.cmd = LAD_NAMESERVER_DELETE;
cmd.clientId = clHandle;
- cmd.args.delete.handle = *nsHandle;
+ cmd.args.nsdelete.handle = *nsHandle;
if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
PRINTVERBOSE1(
return NameServer_E_FAIL;
}
- *nsHandle = rsp.delete.handle;
- status = rsp.status;
+ *nsHandle = rsp.nsdelete.handle;
+ status = rsp.nsdelete.status;
PRINTVERBOSE1("NameServer_delete: got LAD response for client %d\n",
clHandle)
return status;
}
+
+/*
+ * ======== NameServer_attach ========
+ * Internal function.
+ */
+Int NameServer_attach(UInt16 procId)
+{
+ Int status;
+ LAD_ClientHandle clHandle;
+ struct LAD_CommandObj cmd;
+ union LAD_ResponseObj rsp;
+
+ clHandle = LAD_findHandle();
+
+ if (clHandle == LAD_MAXNUMCLIENTS) {
+ PRINTVERBOSE0("NameServer_attach: not connected to LAD\n");
+ return (NameServer_E_RESOURCE);
+ }
+
+ cmd.cmd = LAD_NAMESERVER_ATTACH;
+ cmd.clientId = clHandle;
+ cmd.args.attach.procId = procId;
+
+ if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
+ PRINTVERBOSE1("NameServer_attach: sending LAD command failed, "
+ "status=%d\n", status);
+ return (NameServer_E_FAIL);
+ }
+
+ if ((status = LAD_getResponse(clHandle, &rsp)) != LAD_SUCCESS) {
+ PRINTVERBOSE1("NameServer_attach: no LAD response, status=%d\n",
+ status);
+ return (NameServer_E_FAIL);
+ }
+
+ status = rsp.status;
+ PRINTVERBOSE1("NameServer_attach: LAD response, status=%d\n", status)
+ return (status);
+}
+
+/*
+ * ======== NameServer_detach ========
+ * Internal function.
+ */
+Int NameServer_detach(UInt16 procId)
+{
+ Int status;
+ LAD_ClientHandle clHandle;
+ struct LAD_CommandObj cmd;
+ union LAD_ResponseObj rsp;
+
+ clHandle = LAD_findHandle();
+
+ if (clHandle == LAD_MAXNUMCLIENTS) {
+ PRINTVERBOSE0("NameServer_detach: not connected to LAD\n");
+ return (NameServer_E_RESOURCE);
+ }
+
+ cmd.cmd = LAD_NAMESERVER_DETACH;
+ cmd.clientId = clHandle;
+ cmd.args.detach.procId = procId;
+
+ if ((status = LAD_putCommand(&cmd)) != LAD_SUCCESS) {
+ PRINTVERBOSE1("NameServer_detach: sending LAD command failed, "
+ "status=%d\n", status);
+ return (NameServer_E_FAIL);
+ }
+
+ if ((status = LAD_getResponse(clHandle, &rsp)) != LAD_SUCCESS) {
+ PRINTVERBOSE1("NameServer_detach: no LAD response, status=%d\n",
+ status);
+ return (NameServer_E_FAIL);
+ }
+
+ status = rsp.status;
+ PRINTVERBOSE1("NameServer_detach: LAD response, status=%d\n", status)
+ return (status);
+}