wtx.c
上传用户:nvosite88
上传日期:2007-01-17
资源大小:4983k
文件大小:300k
- case WTX_EVENT_SYM_REMOVED:
- return WTX_EVT_SYM_REMOVED;
- case WTX_EVENT_OBJ_LOADED:
- return WTX_EVT_OBJ_LOADED;
- case WTX_EVENT_OBJ_UNLOADED:
- return WTX_EVT_OBJ_UNLOADED;
- case WTX_EVENT_CTX_START:
- return WTX_EVT_CTX_START;
- case WTX_EVENT_CTX_EXIT:
- return WTX_EVT_CTX_EXIT;
- case WTX_EVENT_EXCEPTION:
- return WTX_EVT_EXCEPTION;
- case WTX_EVENT_VIO_WRITE:
- return WTX_EVT_VIO_WRITE;
- case WTX_EVENT_TOOL_ATTACH:
- return WTX_EVT_TOOL_ATTACH;
- case WTX_EVENT_TOOL_DETACH:
- return WTX_EVT_TOOL_DETACH;
- case WTX_EVENT_TOOL_MSG:
- return WTX_EVT_TOOL_MSG;
- case WTX_EVENT_TEXT_ACCESS:
- return WTX_EVT_TEXT_ACCESS;
- case WTX_EVENT_DATA_ACCESS:
- return WTX_EVT_DATA_ACCESS;
- case WTX_EVENT_CALL_RETURN:
- return WTX_EVT_CALL_RETURN;
- case WTX_EVENT_USER:
- return WTX_EVT_USER;
- case WTX_EVENT_NONE:
- return WTX_EVT_NONE;
- case WTX_EVENT_HW_BP:
- return WTX_EVT_HW_BP;
- case WTX_EVENT_OTHER:
- return WTX_EVT_OTHER;
- case WTX_EVENT_INVALID:
- return WTX_EVT_INVALID;
- case WTX_EVENT_TS_KILLED:
- return WTX_EVT_TS_KILLED;
- case WTX_EVENT_EVTPT_ADDED:
- return WTX_EVT_EVTPT_ADDED;
- case WTX_EVENT_EVTPT_DELETED:
- return WTX_EVT_EVTPT_DELETED;
- default:
- return WTX_EVT_UNKNOWN;
- }
- return WTX_EVT_UNKNOWN;
- }
- /******************************************************************************
- *
- * wtxServiceAdd - add a new service to the agent
- *
- * This command adds a new service to the target server. The service is
- * provided in WDB- and WTX-level object modules. The WDB object module is
- * downloaded to the target, and the WTX object module is dynamically linked
- * to the target server.
- *
- * The <wtxInProcName> and <wtxOutProcName> arguments are the names of
- * known structure filter procedures used to exchange data with the new
- * service.
- *
- * <wtxObjFile> is the name of a dynamically loadable library file that
- * contain the WTX service routine, the service initialization routine, and
- * XDR filters code for the service input and output parameters.
- *
- * Upon success the service number to be used for future requests to the newly
- * added service is returned in <mySvcNumber>.
- *
- * Example:
- * .CS
- *
- * /@
- * * Add a WTX service called mySvc and get the service number in
- * * mySvcNumber.
- * @/
- *
- * if (wtxServiceAdd
- * (
- * wtxh, /@ our tool handle @/
- * &mySvcNumber, /@ where to return service num. @/
- * NULL, NULL, NULL, NULL, /@ no WDB items @/
- * "mySvc.so", /@ new service DLL @/
- * "mySvcName", /@ service routine name @/
- * "xdr_WTX_MY_SVC_IN_PARAM", /@ input param XDR filter @/
- * "xdr_WTX_MY_SVC_OUT_PARAM" /@ output param XDR filter @/
- * ) != OK)
- * {
- * printf("Error: cannot add mySvc service:%sn",wtxErrMsgGet(wtxh));
- * wtxTerminate (wtxh); /@ terminate tool connection @/
- * exit(0);
- * }
- *
- * ...
- *
- * /@ get our client handle in order to call the newly added service @/
- *
- * pClient = (CLIENT *) wtxh->server->transport;
- *
- * /@ set client call timeout @/
- *
- * timeout.tv_sec = 10;
- * timeout.tv_usec = 0;
- *
- * /@ Call the newly added service @/
- *
- * rpcStat = clnt_call (
- * pClient, /@ client handle @/
- * mySvcNumber, /@ service number @/
- * xdr_WTX_MY_SVC_IN_PARAM, /@ request XDR filter @/
- * (char *) pIn, /@ ptr to input data @/
- * xdr_WTX_MY_SVC_OUT_PARAM, /@ reply XDR filter @/
- * (char *) pOut, /@ ptr to result @/
- * timeout /@ request timeout value @/
- * );
- *
- * .CE
- *
- * WARNING: In the Tornado 1.0 release, wtxServiceAdd() can only add WTX
- * services that do not require an additional WDB service. The <wdbSvcNum>,
- * <wdbName>, <wdbObjFile> and <wdbSvcInitRtn> parameters must be set to NULL.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_SERVICE_ADD
- */
- STATUS wtxServiceAdd
- (
- HWTX hWtx, /* WTX API handle */
- UINT32 * wtxSvcNum, /* where to return WTX RPC service number */
- UINT32 wdbSvcNum, /* WDB RPC service number */
- char * wdbName, /* WDB service name */
- char * wdbObjFile, /* WDB service object module */
- char * wdbSvcInitRtn, /* WDB svc initialization routine name */
- char * wtxObjFile, /* WTX xdr/service DLL file */
- char * wtxName, /* WTX service routine name */
- char * wtxInProcName, /* WTX service input xdr procedure name */
- char * wtxOutProcName /* WTX service output xdr procedure name */
- )
- {
- WTX_MSG_SERVICE_DESC in; /* exch input desc */
- WTX_MSG_RESULT out; /* exch result desc */
- WTX_ERROR_T callStat; /* exch error code */
- STATUS status = WTX_ERROR; /* returned status */
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- /* first of all, check that all the WTX given parameters are not NULL */
- if ( (wtxObjFile == NULL) || (wtxName == NULL) || (wtxInProcName == NULL) ||
- (wtxOutProcName == NULL))
- {
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- }
- /* clean in and out items */
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.pWtxServiceDesc = (WTX_WTX_SERVICE_DESC *)
- malloc (sizeof (WTX_WTX_SERVICE_DESC));
- if (in.pWtxServiceDesc == NULL)
- {
- wtxErrSet (hWtx, WTX_ERR_API_MEMALLOC);
- goto error1;
- }
- /*
- * allocate memory for the WDB service desc only if one of the WDB
- * parameters is not NULL
- */
- if ( (wdbSvcNum != 0) || (wdbName != NULL) || (wdbObjFile != NULL) ||
- (wdbSvcInitRtn != NULL))
- {
- in.pWdbServiceDesc = (WTX_WDB_SERVICE_DESC *)
- malloc (sizeof (WTX_WDB_SERVICE_DESC));
- if (in.pWdbServiceDesc == NULL)
- {
- wtxErrSet (hWtx, WTX_ERR_API_MEMALLOC);
- goto error2;
- }
- /* initialize the WDB service description */
- in.pWdbServiceDesc->rpcNum = wdbSvcNum;
- in.pWdbServiceDesc->name = wdbName;
- in.pWdbServiceDesc->svcObjFile = wdbObjFile;
- in.pWdbServiceDesc->initRtnName = wdbSvcInitRtn;
- }
- in.pWtxServiceDesc->svcObjFile = wtxObjFile;
- in.pWtxServiceDesc->svcProcName = wtxName;
- in.pWtxServiceDesc->inProcName = wtxInProcName;
- in.pWtxServiceDesc->outProcName = wtxOutProcName;
- callStat = exchange (hWtx, WTX_SERVICE_ADD, &in, &out);
- if (callStat != WTX_ERR_NONE)
- {
- wtxErrSet (hWtx, callStat);
- goto error3;
- }
- status = WTX_OK;
- *wtxSvcNum = out.val.value_u.v_uint32;
- wtxExchangeFree (hWtx->server, WTX_SERVICE_ADD, &out);
- error3:
- /* free the input descriptions */
- if (in.pWdbServiceDesc != NULL)
- free (in.pWdbServiceDesc);
- error2:
- if (in.pWtxServiceDesc != NULL)
- free (in.pWtxServiceDesc);
- error1:
- return status;
- }
- /******************************************************************************
- *
- * wtxSymAdd - add a symbol with the given name, value, and type
- *
- * This routine adds a new symbol with the specified name, value, and type to
- * the target server symbol table.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_SYM_ADD, wtxSymFind(), wtxSymListGet(), wtxSymRemove()
- */
- STATUS wtxSymAdd
- (
- HWTX hWtx, /* WTX API handle */
- const char * name, /* name of symbol to add */
- TGT_ADDR_T value, /* value of symbol to add */
- UINT8 type /* type of symbol to add */
- )
- {
- WTX_MSG_SYMBOL_DESC in; /* input to WTX call */
- WTX_MSG_RESULT out;
- UINT32 result;
- WTX_ERROR_T callStat; /* client status */
-
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.symbol.name = (char *) name;
- in.symbol.value = value;
- in.symbol.type = type;
- callStat = exchange (hWtx, WTX_SYM_ADD, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- result = out.val.value_u.v_uint32;
- wtxExchangeFree (hWtx->server, WTX_SYM_ADD, &out);
- return (result);
- }
- /******************************************************************************
- *
- * wtxSymAddWithGroup - add a symbol with the given name, value, type and group
- *
- * This routine adds a new symbol with the specified name, value, type and
- * group to the target server symbol table.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_SYM_ADD, wtxSymFind(), wtxSymListGet(), wtxSymRemove()
- */
- STATUS wtxSymAddWithGroup
- (
- HWTX hWtx, /* WTX API handle */
- const char * name, /* name of symbol to add */
- TGT_ADDR_T value, /* value of symbol to add */
- UINT8 type, /* type of symbol to add */
- UINT16 group /* group of symbol to add */
- )
- {
- WTX_MSG_SYMBOL_DESC in; /* input to WTX call */
- WTX_MSG_RESULT out;
- UINT32 result;
- WTX_ERROR_T callStat; /* client status */
-
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.symbol.name = (char *) name;
- in.symbol.value = value;
- in.symbol.type = type;
- in.symbol.group = group;
- callStat = exchange (hWtx, WTX_SYM_ADD, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- result = out.val.value_u.v_uint32;
- wtxExchangeFree (hWtx->server, WTX_SYM_ADD, &out);
- return (result);
- }
- /*******************************************************************************
- *
- * wtxSymFind - find information on a symbol given its name or value
- *
- * This routine searches for a symbol which matches the supplied
- * search criteria. If <symName> is non-NULL, the search is for a symbol
- * whose name matches <symName>. If <symName> is NULL, the
- * search is for one with value <symValue>. When searching by name,
- * the <exactName> flag is used to control whether the name must exactly
- * match <symName> or only partially. In both value and name searches,
- * a symbol type <symType> can be supplied to further refine the search.
- * Valid symbol types are defined in a_out.h. To prevent the type being
- * considered in the search set <typeMask> to 0.
- *
- * The result of the search is a pointer to a symbol which
- * must be freed by the user calling wtxResultFree().
- *
- * EXPAND ../../../include/wtxmsg.h WTX_SYMBOL
- *
- * RETURNS: A pointer to the symbol or NULL on error.
- *
- * SEE ALSO: WTX_SYM_FIND, wtxResultFree().
- */
- WTX_SYMBOL * wtxSymFind
- (
- HWTX hWtx, /* WTX API handle */
- const char * symName, /* name of symbol */
- TGT_ADDR_T symValue, /* value of symbol */
- BOOL32 exactName, /* must match name exactly */
- UINT8 symType, /* type of symbol */
- UINT8 typeMask /* mask to select type bits */
- )
- {
- WTX_MSG_SYMBOL_DESC in; /* input to WTX call */
- WTX_MSG_SYMBOL_DESC * pOut; /* result pointer */
- WTX_ERROR_T callStat; /* client status */
-
- WTX_CHECK_CONNECTED (hWtx, NULL);
- pOut = calloc (1, sizeof (WTX_MSG_SYMBOL_DESC));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- memset (&in, 0, sizeof (in));
- in.symbol.name = (char *) symName;
- in.symbol.exactName = exactName;
- in.symbol.value = symValue;
- in.symbol.type = symType;
- in.symbol.typeMask = typeMask;
- callStat = exchange (hWtx, WTX_SYM_FIND, &in, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut); /* Free allocated message */
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- /* add pointer to the wtxResultFree () list */
- if (wtxFreeAdd (hWtx, (void *) &pOut->symbol, NULL, pOut, WTX_SYM_FIND,
- hWtx->server, WTX_SVR_SERVER) != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return (&pOut->symbol);
- }
- /*******************************************************************************
- *
- * wtxSymListGet - get a list of symbols matching the given search criteria
- *
- * This routine gets a list of symbols matching given search criteria.
- * <substring> is a symbol substring to match and <value> is a target symbol
- * address value to search around. Either <string> or <value> should be set
- * to a non-NULL value, but not both. In addition, if <listUnknown> is set to
- * TRUE then only unknown symbols are listed and <substring> and <value> are
- * ignored. If <moduleName> is non-NULL, it specifies the module to search.
- * Even if no symbols match the search parameters, the pointer returned is
- * not NULL. It points to a WTX_SYM_LIST with a NULL `pSymbol' field.
- *
- * The return value must be freed by the caller using wtxResultFree().
- *
- * EXPAND ../../../include/wtxmsg.h WTX_SYM_LIST
- *
- * EXPAND ../../../include/wtxmsg.h WTX_SYMBOL
- *
- * NOTE : The symbols allocated by wtxSymListGet() should be freed by caller.
- *
- * RETURNS: A pointer to a list of symbols or NULL on error.
- *
- * SEE ALSO: WTX_SYM_LIST_GET, wtxResultFree()
- */
- WTX_SYM_LIST * wtxSymListGet
- (
- HWTX hWtx, /* WTX API handle */
- const char * substring, /* Symbol name substring to match */
- const char * moduleName, /* Module name to search in */
- TGT_ADDR_T value, /* Symbol value to match */
- BOOL32 listUnknown /* List unknown symbols only flag */
- )
- {
- return (wtxSymListByModuleNameGet (hWtx, substring, moduleName,
- value, listUnknown));
- }
- /*******************************************************************************
- *
- * wtxSymListByModuleIdGet - get a list of symbols given a module Id
- *
- * This routine gets a list of symbols matching given search criteria.
- * <substring> is a symbol substring to match and <value> is a target symbol
- * address value to search around. Either <string> or <value> should be set
- * to a non-NULL value, but not both. In addition, if <listUnknown> is set to
- * TRUE then only unknown symbols are listed and <substring> and <value> are
- * ignored. If <moduleId> is non-zero, it specifies the module to search.
- * Even if no symbols match the search parameters, the pointer returned is
- * not NULL. It points to a WTX_SYM_LIST with a NULL `pSymbol' field.
- *
- * The return value must be freed by the caller using wtxResultFree().
- *
- * EXPAND ../../../include/wtxmsg.h WTX_SYM_LIST
- *
- * EXPAND ../../../include/wtxmsg.h WTX_SYMBOL
- *
- * NOTE : The symbols allocated by wtxSymListGet() should be freed by caller.
- *
- * RETURNS: A pointer to a list of symbols or NULL on error.
- *
- * SEE ALSO: WTX_SYM_LIST_GET, wtxSymListGet(), wtxSymListByModuleNameGet(),
- * wtxResultFree()
- */
- WTX_SYM_LIST * wtxSymListByModuleIdGet
- (
- HWTX hWtx, /* WTX API handle */
- const char * substring, /* Symbol name substring to match */
- UINT32 moduleId, /* Module Id to search in */
- TGT_ADDR_T value, /* Symbol value to match */
- BOOL32 listUnknown /* List unknown symbols only flag */
- )
- {
- WTX_MSG_SYM_MATCH_DESC in; /* query parameters */
- WTX_MSG_SYM_LIST * pOut; /* output message */
- WTX_MSG_SYM_LIST out; /* local message */
- WTX_SYMBOL * firstSym = NULL;/* first symbol of list */
- WTX_SYMBOL * lastSym; /* last symbol of list */
- WTX_SYMBOL * newSymbol; /* new symbol in list */
- WTX_SYMBOL * precSymbol = NULL;/* preceding symbol in list */
- WTX_ERROR_T callStat; /* exchange result */
- STATUS status; /* wtxResultFree() status */
- int stringLength; /* string length for calloc */
-
- WTX_CHECK_CONNECTED (hWtx, NULL); /* checking fot connection */
- /* checking for variables incompatibility */
- if ( (value != 0) && ( (substring != NULL) || (moduleId != 0)))
- {
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, NULL);
- }
- if ( (listUnknown && (moduleId == 0)) ||
- (listUnknown && (substring != NULL)) ||
- (listUnknown && (value != 0)))
- {
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, NULL);
- }
- /* list get parameters initialization */
- memset (&in, 0, sizeof (in));
- in.wtxCore.objId = hWtx->msgToolId.wtxCore.objId;
- in.symTblId = 0; /* Use default target symbol table */
- in.matchString = (substring != NULL);
- in.adrs = value;
- in.stringToMatch = (char *) substring;
- in.byModuleName = FALSE;
- in.module.moduleId = moduleId;
- in.listUnknownSym = listUnknown;
- in.giveMeNext = FALSE;
- pOut = (WTX_MSG_SYM_LIST *)calloc (1, sizeof (WTX_MSG_SYM_LIST));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- lastSym = NULL;
- do
- {
- memset (&out, 0, sizeof (out)); /* Zero output */
- /* call for target server routine */
- callStat = exchange (hWtx, WTX_SYM_LIST_GET, &in, &out);
- if (callStat != WTX_ERR_NONE)
- {
- pOut->symList.pSymbol = firstSym;
- wtxSymListFree (&pOut->symList);
- free (pOut);
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- lastSym = out.symList.pSymbol;
- if ((firstSym == NULL) && (lastSym != NULL)) /* first query */
- {
- if ((newSymbol = (WTX_SYMBOL *) calloc (1, sizeof (WTX_SYMBOL)))
- == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- *newSymbol = *lastSym;
- if (lastSym->name != NULL)
- {
- stringLength = strlen (lastSym->name);
- if ((newSymbol->name = (char *)calloc (stringLength + 1,
- sizeof (char))) == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- strcpy (newSymbol->name, lastSym->name);
- }
- if (lastSym->moduleName != NULL)
- {
- stringLength = (int) strlen (lastSym->moduleName);
- if ( (newSymbol->moduleName = (char *)calloc (stringLength + 1,
- sizeof (char)))
- == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- strcpy (newSymbol->moduleName, lastSym->moduleName);
- }
- firstSym = newSymbol;
- precSymbol = newSymbol;
- lastSym = lastSym->next;
- }
- while (lastSym != NULL)
- {
- newSymbol = (WTX_SYMBOL *)calloc (1, sizeof (WTX_SYMBOL));
- /* this should copy all fields, even a NULL for next */
- *newSymbol = *lastSym;
- /* allocating memory for string fields, then copy them */
- if (lastSym->name != NULL)
- {
- stringLength = strlen (lastSym->name);
- if ((newSymbol->name = (char *)calloc (stringLength + 1,
- sizeof (char))) == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- strcpy (newSymbol->name, lastSym->name);
- }
- if (lastSym->moduleName != NULL)
- {
- stringLength = (int) strlen (lastSym->moduleName);
- if ( (newSymbol->moduleName = (char *)calloc (stringLength + 1,
- sizeof (char)))
- == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- strcpy (newSymbol->moduleName, lastSym->moduleName);
- }
- /* updating local symbol list */
- precSymbol->next = newSymbol;
- precSymbol = precSymbol->next;
- lastSym = lastSym->next;
- }
- /* Ensure next time around, if any gets the remainng symbols */
- in.giveMeNext = out.moreToCome;
- wtxExchangeFree (hWtx->server, WTX_SYM_LIST_GET, &out);
- } while (in.giveMeNext);
- /* Set up pOut so that it can be freed by wtxResultFree() */
- pOut->wtxCore.protVersion = (UINT32) pOut;
- pOut->wtxCore.objId = WTX_SYM_LIST_GET;
-
- /* Then set the symbol pointer to the first symbol in the list */
- pOut->symList.pSymbol = firstSym;
-
- /* add the pointer description to the list of pointer to free */
- if ( (status = wtxFreeAdd (hWtx, (void *) &pOut->symList,
- (FUNCPTR) wtxSymListFree, pOut, 0, NULL,
- WTX_SVR_NONE)) != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return &pOut->symList;
- }
- /*******************************************************************************
- *
- * wtxSymListByModuleNameGet - get a list of symbols given a module name
- *
- * This routine gets a list of symbols matching given search criteria.
- * <substring> is a symbol substring to match and <value> is a target symbol
- * address value to search around. Either <string> or <value> should be set
- * to a non-NULL value, but not both. In addition, if <listUnknown> is set to
- * TRUE then only unknown symbols are listed and <substring> and <value> are
- * ignored. If <moduleName> is non-NULL, it specifies the module to search.
- * Even if no symbols match the search parameters, the pointer returned is
- * not NULL. It points to a WTX_SYM_LIST with a NULL `pSymbol' field.
- *
- * The return value must be freed by the caller using wtxResultFree().
- *
- * EXPAND ../../../include/wtxmsg.h WTX_SYM_LIST
- *
- * EXPAND ../../../include/wtxmsg.h WTX_SYMBOL
- *
- * NOTE : The symbols allocated by wtxSymListGet() should be freed by caller.
- *
- * RETURNS: A pointer to a list of symbols or NULL on error.
- *
- * SEE ALSO: WTX_SYM_LIST_GET, wtxSymListGet(), wtxSymListByModuleIdGet(),
- * wtxResultFree()
- */
- WTX_SYM_LIST * wtxSymListByModuleNameGet
- (
- HWTX hWtx, /* WTX API handle */
- const char * substring, /* Symbol name substring to match */
- const char * moduleName, /* Module name to search in */
- TGT_ADDR_T value, /* Symbol value to match */
- BOOL32 listUnknown /* List unknown symbols only flag */
- )
- {
- WTX_MSG_SYM_MATCH_DESC in; /* query parameters */
- WTX_MSG_SYM_LIST * pOut; /* output message */
- WTX_MSG_SYM_LIST out; /* local message */
- WTX_SYMBOL * firstSym = NULL; /* first sym of list */
- WTX_SYMBOL * lastSym; /* last sym of list */
- WTX_SYMBOL * newSymbol; /* new symbol in list */
- WTX_SYMBOL * precSymbol = NULL; /* prev sym in list */
- WTX_ERROR_T callStat; /* exchange result */
- STATUS status = WTX_ERROR; /* routine status */
- int stringLength; /* str len for calloc */
-
- WTX_CHECK_CONNECTED (hWtx, NULL); /* checking fot connection */
- /* checking for variables incompatibility */
- if ((value != 0) && ((substring != NULL) || (moduleName != NULL)))
- {
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, NULL);
- }
- if ( (listUnknown && (moduleName == NULL)) ||
- (listUnknown && (substring != NULL)) ||
- (listUnknown && (value != 0)))
- {
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, NULL);
- }
- /* list get parameters initialization */
- memset (&in, 0, sizeof (in));
- in.wtxCore.objId = hWtx->msgToolId.wtxCore.objId;
- in.symTblId = 0; /* Use default target symbol table */
- in.matchString = (substring != NULL);
- in.adrs = value;
- in.stringToMatch = (char *) substring;
- in.byModuleName = TRUE;
- in.module.moduleName = (char *) moduleName;
- in.listUnknownSym = listUnknown;
- in.giveMeNext = FALSE;
- pOut = (WTX_MSG_SYM_LIST *)calloc (1, sizeof (WTX_MSG_SYM_LIST));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- lastSym = NULL;
- do
- {
- memset (&out, 0, sizeof (out)); /* Zero output */
- /* call for target server routine */
- callStat = exchange (hWtx, WTX_SYM_LIST_GET, &in, &out);
- if (callStat != WTX_ERR_NONE)
- {
- pOut->symList.pSymbol = firstSym;
- wtxSymListFree (&pOut->symList);
- free (pOut);
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- lastSym = out.symList.pSymbol;
- if ( (firstSym == NULL) && (lastSym != NULL)) /* first query */
- {
- if ( (newSymbol = (WTX_SYMBOL *)calloc (1, sizeof (WTX_SYMBOL)))
- == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- *newSymbol = *lastSym;
- if (lastSym->name != NULL)
- {
- stringLength = strlen (lastSym->name);
- if ( (newSymbol->name = (char *)calloc (stringLength + 1,
- sizeof (char))) == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- strcpy (newSymbol->name, lastSym->name);
- }
- if (lastSym->moduleName != NULL)
- {
- stringLength = (int) strlen (lastSym->moduleName);
- if ( (newSymbol->moduleName = (char *)calloc (stringLength + 1,
- sizeof (char)))
- == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- strcpy (newSymbol->moduleName, lastSym->moduleName);
- }
- firstSym = newSymbol;
- precSymbol = newSymbol;
- lastSym = lastSym->next;
- }
- while (lastSym != NULL)
- {
- newSymbol = (WTX_SYMBOL *)calloc (1, sizeof (WTX_SYMBOL));
- /* this should copy all fields, even a NULL for next */
- *newSymbol = *lastSym;
- /* allocating mempry for string fields, then copy them */
- if (lastSym->name != NULL)
- {
- stringLength = strlen (lastSym->name);
- if ( (newSymbol->name = (char *)calloc (stringLength + 1,
- sizeof (char))) == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- strcpy (newSymbol->name, lastSym->name);
- }
- if (lastSym->moduleName != NULL)
- {
- stringLength = (int) strlen (lastSym->moduleName);
- if ( (newSymbol->moduleName = (char *)calloc (stringLength + 1,
- sizeof (char)))
- == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- strcpy (newSymbol->moduleName, lastSym->moduleName);
- }
- /* updating local symbol list */
- precSymbol->next = newSymbol;
- precSymbol = precSymbol->next;
- lastSym = lastSym->next;
- }
- /* Ensure next time around, if any gets the remainng symbols */
- in.giveMeNext = out.moreToCome;
- wtxExchangeFree (hWtx->server, WTX_SYM_LIST_GET, &out);
- } while (in.giveMeNext);
- /* Set up pOut so that it can be freed by wtxResultFree() */
- pOut->wtxCore.protVersion = (UINT32) pOut;
- pOut->wtxCore.objId = WTX_SYM_LIST_GET;
-
- /* Then set the symbol pointer to the first symbol in the list */
- pOut->symList.pSymbol = firstSym;
- /* add pointer to the wtxResultFree(0 list */
- if ( (status = wtxFreeAdd (hWtx, (void *) &pOut->symList,
- (FUNCPTR) wtxSymListFree, pOut, 0, NULL,
- WTX_SVR_NONE)) != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return &pOut->symList;
- }
- /*******************************************************************************
- *
- * wtxSymRemove - remove a symbol from the default target server symbol table
- *
- * This routine removes a symbol from the default target server symbol table.
- * <symName> and <symType> identify the symbol to remove.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_SYM_REMOVE, wtxSymAdd(), wtxSymFind(), wtxSymListGet()
- */
- STATUS wtxSymRemove
- (
- HWTX hWtx, /* WTX API handle */
- const char *symName, /* Name of symbol to remove */
- UINT8 symType /* Type of symbol to remove */
- )
- {
- WTX_MSG_SYMBOL_DESC in; /* input to WTX call */
- WTX_MSG_RESULT out; /* result pointer */
- WTX_ERROR_T callStat; /* client status */
-
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.symbol.name = (char *) symName;
- in.symbol.type = symType;
- callStat = exchange (hWtx, WTX_SYM_REMOVE, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_SYM_REMOVE, &out);
- return WTX_OK;
- }
- /*******************************************************************************
- *
- * wtxSymTblInfoGet - return information about the target server symbol table
- *
- * This routine queries the target server to find out information about its
- * symbol table. The return value must be freed by the caller using
- * wtxResultFree().
- *
- * EXPAND ../../../include/wtxmsg.h WTX_SYM_TBL_INFO
- *
- * RETURNS: A pointer to the target server symbol-table information structure
- * or NULL on error.
- *
- * SEE ALSO: WTX_SYM_TBL_INFO_GET
- */
- WTX_SYM_TBL_INFO * wtxSymTblInfoGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_MSG_SYM_TBL_INFO * pOut;
- WTX_ERROR_T callStat;
- WTX_CHECK_CONNECTED (hWtx, NULL);
- pOut = calloc (1, sizeof (WTX_MSG_SYM_TBL_INFO));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- callStat = exchange (hWtx, WTX_SYM_TBL_INFO_GET, &hWtx->msgToolId, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut);
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- /* add pointer to the wtxResultFree () list */
- if (wtxFreeAdd (hWtx, (void *) &pOut->symTblId, NULL, pOut,
- WTX_SYM_TBL_INFO_GET, hWtx->server, WTX_SVR_SERVER)
- != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return ((WTX_SYM_TBL_INFO *) &(pOut->symTblId));
- }
- /*******************************************************************************
- *
- * wtxTargetReset - reset the target
- *
- * This routine resets the target as if it was manually rebooted.
- * The target server restarts itself and if the reboot is successful,
- * it reconnects to the target. If the call is successful a target
- * reset event, TGT_RESET, is generated and sent to all clients
- * registered to receive them.
- *
- * NOTE: The client making the request must reconnect to the target
- * server as restarting the server causes the server connection to
- * be broken.
- *
- * RETURNS: WTX_OK or WTX_ERROR on failure.
- *
- * SEE ALSO: WTX_TARGET_RESET
- */
- STATUS wtxTargetReset
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&out, 0, sizeof (out));
- callStat = exchange (hWtx, WTX_TARGET_RESET, &hWtx->msgToolId, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_TARGET_RESET, &out);
- return (WTX_OK);
- }
- /******************************************************************************
- *
- * wtxTsNameGet - get the full name of the currently attached target server
- *
- * This routine returns the full name of the target server to which the
- * handle <hWtx> is attached (if any). The string is an internal one and
- * must not be freed by the caller.
- *
- * RETURNS: The target server name string or NULL if not connected.
- */
- const char * wtxTsNameGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_CHECK_HANDLE (hWtx, NULL);
- if (wtxToolConnected (hWtx))
- return hWtx->pServerDesc->wpwrName;
- else
- return NULL;
- }
- /*******************************************************************************
- *
- * wtxTargetRtTypeGet - get the target-runtime-type information
- *
- * This routine returns a numeric value indicating the runtime type
- * as returned by the target agent.
- *
- * RETURNS: The runtime type code as a INT32 or WTX_ERROR on error.
- */
- INT32 wtxTargetRtTypeGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- if (hWtx->pTsInfo == NULL && wtxTsInfoGet (hWtx) == NULL)
- /* Error has already been dispatched, just return WTX_ERROR */
- return WTX_ERROR;
-
- return hWtx->pTsInfo->tgtInfo.rtInfo.rtType;
- }
- /*******************************************************************************
- *
- * wtxTargetRtVersionGet - get the target-runtime-version information
- *
- * This routine returns a string containing the version information for
- * the runtime of the current target. The return value is a pointer to the
- * string in temporary memory; the string must be copied if its value is to be
- * stored.
- *
- * RETURNS: The version string or NULL on error.
- */
- const char * wtxTargetRtVersionGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, NULL);
- if (hWtx->pTsInfo == NULL && wtxTsInfoGet (hWtx) == NULL)
- /* Error has already been dispatched, just return NULL */
- return NULL;
-
- return hWtx->pTsInfo->tgtInfo.rtInfo.rtVersion;
- }
- /*******************************************************************************
- *
- * wtxTargetCpuTypeGet - get the target CPU type code
- *
- * This routine returns a numeric value indicating the type of the CPU
- * as returned by the target agent.
- *
- * RETURNS: The CPU type code as a INT32 or WTX_ERROR on error.
- */
- INT32 wtxTargetCpuTypeGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- if (hWtx->pTsInfo == NULL && wtxTsInfoGet (hWtx) == NULL)
- /* Error has already been dispatched, just return WTX_ERROR */
- return WTX_ERROR;
-
- return hWtx->pTsInfo->tgtInfo.rtInfo.cpuType;
- }
- /*******************************************************************************
- *
- * wtxTargetHasFppGet - check if the target has a floating point processor
- *
- * This routine returns a boolean indicating whether the current target has a
- * floating point processor available. Errors must be detected using
- * wtxErrClear() and wtxErrGet().
- *
- * RETURNS: TRUE if it has a floating point processor or FALSE if not or if
- * there was an error.
- */
- BOOL32 wtxTargetHasFppGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, FALSE);
- if (hWtx->pTsInfo == NULL && wtxTsInfoGet (hWtx) == NULL)
- /* Error has already been dispatched, just return WTX_ERROR */
- return FALSE;
-
- return ((hWtx->pTsInfo->tgtInfo.rtInfo.hasCoprocessor & WTX_FPP_MASK) >>
- WTX_FPP_BITSHIFT);
- }
- /*******************************************************************************
- *
- * wtxTargetHasAltivecGet - check if the target has an altivec unit
- *
- * This routine returns a boolean indicating whether the current target has a
- * altivec coprocessor available. Errors must be detected using
- * wtxErrClear() and wtxErrGet().
- *
- * RETURNS: TRUE if it has an Altivec unit or FALSE if not or if
- * there was an error.
- */
- BOOL32 wtxTargetHasAltivecGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, FALSE);
- if (hWtx->pTsInfo == NULL && wtxTsInfoGet (hWtx) == NULL)
- /* Error has already been dispatched, just return WTX_ERROR */
- return FALSE;
-
- return ((hWtx->pTsInfo->tgtInfo.rtInfo.hasCoprocessor & WTX_ALTIVEC_MASK) >>
- WTX_ALTIVEC_BITSHIFT);
- }
- /*******************************************************************************
- *
- * wtxTargetHasDspGet - check if the target has a DSP unit
- *
- * This routine returns a boolean indicating whether the current target has a
- * DSP coprocessor available. Errors must be detected using
- * wtxErrClear() and wtxErrGet().
- *
- * RETURNS: TRUE if it has an DSP unit or FALSE if not or if
- * there was an error.
- */
- BOOL32 wtxTargetHasDspGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, FALSE);
- if (hWtx->pTsInfo == NULL && wtxTsInfoGet (hWtx) == NULL)
- /* Error has already been dispatched, just return WTX_ERROR */
- return FALSE;
-
- return (hWtx->pTsInfo->tgtInfo.rtInfo.hasCoprocessor & WTX_DSP_MASK) >> WTX_DSP_BITSHIFT;
- }
- /*******************************************************************************
- *
- * wtxTargetEndianGet - get the endianness of the target CPU
- *
- * This routine returns WTX_ENDIAN_BIG if the target has a CPU that uses
- * big-endian byte storage ordering (the most significant byte first) or
- * WTX_ENDIAN_LITTLE if it uses little-endian ordering (the least significant
- * byte first). If an error occurs, the routine returns WTX_ENDIAN_UNKNOWN.
- *
- * EXPAND ../../../include/wtx.h WTX_ENDIAN_T
- *
- * RETURNS: The CPU endian value or WTX_ENDIAN_UNKNOWN.
- */
- WTX_ENDIAN_T wtxTargetEndianGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, WTX_ENDIAN_UNKNOWN);
- if (hWtx->pTsInfo == NULL && wtxTsInfoGet (hWtx) == NULL)
- /* Error has already been dispatched, just return error value */
- return WTX_ENDIAN_UNKNOWN;
-
- switch (hWtx->pTsInfo->tgtInfo.rtInfo.endian)
- {
- case 1234:
- return WTX_ENDIAN_BIG;
- case 4321:
- return WTX_ENDIAN_LITTLE;
- default:
- return WTX_ENDIAN_UNKNOWN;
- }
- }
- /*******************************************************************************
- *
- * wtxTargetBootlineGet - get the target bootline information string
- *
- * This routine returns a string containing the target bootline. The
- * return value is a pointer to the string in temporary memory; the string
- * must be copied if it is to be stored.
- *
- * RETURNS: The bootline string or NULL on error.
- */
- const char * wtxTargetBootlineGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, NULL);
- if (hWtx->pTsInfo == NULL && wtxTsInfoGet (hWtx) == NULL)
- /* Error has already been dispatched, just return NULL */
- return NULL;
-
- return hWtx->pTsInfo->tgtInfo.rtInfo.bootline;
- }
- /*******************************************************************************
- *
- * wtxTargetBspNameGet - get the target board-support-package name string
- *
- * This routine returns a string containing the board-support-package name for
- * the runtime of the current target. The return value is a pointer to
- * the string in temporary memory; the string must be copied if it is to be
- * stored.
- *
- * RETURNS: The BSP name string or NULL on error.
- */
- const char * wtxTargetBspNameGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, NULL);
- if (hWtx->pTsInfo == NULL && wtxTsInfoGet (hWtx) == NULL)
- /* Error has already been dispatched, just return NULL */
- return NULL;
-
- return hWtx->pTsInfo->tgtInfo.rtInfo.bspName;
- }
- /*******************************************************************************
- *
- * wtxToolNameGet - return the name of the current tool
- *
- * This function gets a string representing the name of the current tool.
- * The return value is a pointer to the string in temporary memory; the string
- * must be copied if it is to be stored.
- *
- * RETURNS: The tool name string or NULL on error.
- */
- char * wtxToolNameGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, NULL);
- if (hWtx->pToolDesc != NULL)
- return hWtx->pToolDesc->toolName;
- else
- return NULL;
- }
- /******************************************************************************
- *
- * wtxTsVersionGet - return the Tornado version
- *
- * This function gets a string representing the Tornado version.
- * The return value is a pointer to temporary memory and must be copied if it is
- * to be stored.
- *
- * RETURNS: A pointer to the Tornado version string or NULL on error.
- */
- char * wtxTsVersionGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, NULL);
- if (hWtx->pTsInfo == NULL && wtxTsInfoGet (hWtx) == NULL)
- /* Error has already been dispatched, just return NULL */
- return NULL;
- return hWtx->pTsInfo->version;
- }
- /******************************************************************************
- *
- * wtxTsKill - kill the target server
- *
- * This routine kills the target server. The client detaches from the
- * target server at this time. Another attachment can subsequently be
- * made.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_OBJ_KILL, wtxToolAttach()
- */
- STATUS wtxTsKill
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_ERROR_T callStat; /* WTX RPC status */
- WTX_MSG_KILL_DESC in; /* WTX kill message */
- WTX_MSG_RESULT out; /* WTX result message */
-
- WTX_CHECK_CONNECTED (hWtx, 0);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.request = WTX_OBJ_KILL_DESTROY;
- callStat = exchange (hWtx, WTX_OBJ_KILL, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_OBJ_KILL, &out);
- toolCleanup(hWtx);
- return (WTX_OK);
- }
- /******************************************************************************
- *
- * wtxTsRestart - restart the target server
- *
- * This routine restarts the target server. The client detaches from the
- * target server at this time. Another attachment can subsequently be
- * made.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_OBJ_KILL, wtxToolAttach()
- */
- STATUS wtxTsRestart
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_ERROR_T callStat; /* WTX RPC status */
- WTX_MSG_KILL_DESC in; /* WTX kill message */
- WTX_MSG_RESULT out; /* WTX result message */
-
- WTX_CHECK_CONNECTED (hWtx, 0);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.request = WTX_OBJ_KILL_RESTART;
- callStat = exchange (hWtx, WTX_OBJ_KILL, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_OBJ_KILL, &out);
- toolCleanup(hWtx);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxUnregisterForEvent - ask the target server to not send events matching
- * a regexp
- *
- * This routine registers which events are unwanted. Usually, if we want to
- * filter events notification we have to give the regular expression to
- * WTX_REGISTER_FOR_EVENT. A more simple way to do this is to be registered
- * for all the events and to be registered for only those which are unwanted.
- *
- * RETURNS: WTX_OK or WTX_ERROR if exchange failed
- *
- * SEE ALSO: WTX_UNREGISTER_FOR_EVENT, wtxRegisterForEvent(), wtxEventGet(),
- * wtxEventListGet().
- */
- STATUS wtxUnregisterForEvent
- (
- HWTX hWtx, /* WTX API handle */
- char * regExp /* Regular expression to select events */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_EVENT_REG_DESC in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&out, 0, sizeof (out));
- memset (&in, 0, sizeof (in));
- in.evtRegExp = (char *) regExp;
- callStat = exchange (hWtx, WTX_UNREGISTER_FOR_EVENT, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_UNREGISTER_FOR_EVENT, &out);
- return (WTX_OK);
- }
- /******************************************************************************
- *
- * wtxFuncCall - call a function on the target
- *
- * This routine calls the function identified by WTX_CONTEXT_DESC.
- *
- * EXPAND ../../../include/wtx.h WTX_CONTEXT_DESC
- *
- * Execution starts at `entry', with up to 10 integer arguments specified in
- * the array `args[]'. The return type is specified by setting `returnType'
- * to WTX_RETURN_TYPE_INT or WTX_RETURN_TYPE_DOUBLE.
- *
- * NOTE: Because calling a function creates a task context on the target
- * system, it cannot be used when the target agent is in external mode.
- *
- * ERRORS:
- * .iP WTX_ERR_API_INVALID_ARG 12
- * <pContextDesc> is invalid.
- *
- * RETURNS: The ID of the function call or WTX_ERROR. When the called
- * function terminates, a CALL_RETURN event is generated which
- * references this ID and contains the return value.
- *
- * SEE ALSO: WTX_FUNC_CALL, wtxEventGet(), wtxDirectCall(),
- * .I API Reference Manual: WTX Protocol WTX_FUNC_CALL
- */
- WTX_CONTEXT_ID_T wtxFuncCall
- (
- HWTX hWtx, /* WTX API handle */
- WTX_CONTEXT_DESC * pContextDesc /* pointer to call descriptor */
- )
- {
- WTX_ERROR_T callStat; /* status of RPC */
- WTX_MSG_CONTEXT_DESC in; /* params to WTX call */
- WTX_MSG_RESULT out; /* result of WTX call */
- WTX_CONTEXT_ID_T callId;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- if (pContextDesc == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- /* Fill in the context create descriptor message. */
- /*
- * XXX - must have WTX_CONTEXT_DESC fields identical to those
- * WTX_MSG_CONTEXT_DESC from contextType onwards. Awaits change to
- * message definitions on wtxmsg.h so this hack will go away.
- */
- memcpy (&in.contextType, pContextDesc, sizeof (WTX_CONTEXT_DESC));
-
- callStat = exchange (hWtx, WTX_FUNC_CALL, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- callId = out.val.value_u.v_uint32;
- wtxExchangeFree (hWtx->server, WTX_FUNC_CALL, &out);
- return callId;
- }
- /******************************************************************************
- *
- * wtxDirectCall - call a function on the target within the agent
- *
- * This routine calls the function at <entry>, with up to 10 integer
- * arguments <arg0>... <arg9>, in the context of the target agent.
- *
- * The return value of the function called on the target is returned at
- * the address pointed to by <pRetVal>.
- *
- * NOTE: The called function is executed within the target agent allowing
- * tools to call functions when the agent is running in both task and external
- * mode. This service should only be used to call simple functions that
- * return immediately in order to avoid locking access to the target for other
- * tools. It is preferable to use wtxFuncCall() to call functions that may take
- * longer to return. If the function called from wtxDirectCall() gets an
- * exception, the agent stops and communication with the target board is
- * lost.
- *
- * CAVEAT: This service cannot be used to call functions that return a double.
- *
- * RETURNS: WTX_OK or WTX_ERROR if cannot call the function or if <pRetVal>
- * is NULL.
- *
- * SEE ALSO: WTX_DIRECT_CALL, wtxFuncCall()
- */
- STATUS wtxDirectCall
- (
- HWTX hWtx, /* WTX API handle */
- TGT_ADDR_T entry, /* function address */
- void * pRetVal, /* pointer to return value */
- TGT_ARG_T arg0, /* function arguments */
- TGT_ARG_T arg1,
- TGT_ARG_T arg2,
- TGT_ARG_T arg3,
- TGT_ARG_T arg4,
- TGT_ARG_T arg5,
- TGT_ARG_T arg6,
- TGT_ARG_T arg7,
- TGT_ARG_T arg8,
- TGT_ARG_T arg9
- )
- {
- WTX_ERROR_T callStat; /* status of RPC */
- WTX_MSG_CONTEXT_DESC in; /* params to WTX call */
- WTX_MSG_RESULT out; /* result of WTX call */
- /* check for invalid parameter */
- if (pRetVal == NULL)
- return (WTX_ERROR);
- /* check tool connection */
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- /* Fill in the context create descriptor message */
- in.entry = entry;
- in.args[0] = arg0;
- in.args[1] = arg1;
- in.args[2] = arg2;
- in.args[3] = arg3;
- in.args[4] = arg4;
- in.args[5] = arg5;
- in.args[6] = arg6;
- in.args[7] = arg7;
- in.args[8] = arg8;
- in.args[9] = arg9;
-
- /* perform the call */
- callStat = exchange (hWtx, WTX_DIRECT_CALL, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- /* set target function return value */
- *(UINT32 *)pRetVal = out.val.value_u.v_uint32;
- wtxExchangeFree (hWtx->server, WTX_DIRECT_CALL, &out);
- return WTX_OK;
- }
- /*******************************************************************************
- *
- * wtxTsInfoGet - get information about the target server, target, and its link
- *
- * This routine queries the target server to find out information about
- * the currently connected target and target server. The result is a pointer
- * to internal memory that must not be freed by the user. The value in
- * memory may change after any subsequent WTX API calls so it must be copied
- * if the values are to be saved.
- *
- * EXPAND ../../../include/wtx.h WTX_TS_INFO
- *
- * where WTX_TGT_LINK_DESC is:
- *
- * EXPAND ../../../include/wtxmsg.h WTX_TGT_LINK_DESC
- *
- * and WTX_TGT_INFO is:
- *
- * EXPAND ../../../include/wtxmsg.h WTX_TGT_INFO
- *
- * WTX_TOOL_DESC is:
- *
- * EXPAND ../../../include/wtxmsg.h WTX_TOOL_DESC
- *
- * with WTX_AGENT_INFO:
- *
- * EXPAND ../../../include/wtxmsg.h WTX_AGENT_INFO
- *
- * and WTX_RT_INFO:
- *
- * EXPAND ../../../include/wtxmsg.h WTX_RT_INFO
- *
- * NOTE: This call actively queries the target server for information.
- * Each successful call returns the latest information.
- *
- * RETURNS: A pointer to the target server information structure or NULL on
- * error.
- *
- * SEE ALSO: WTX_TS_INFO_GET
- */
- WTX_TS_INFO * wtxTsInfoGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_MSG_TS_INFO * pOut;
- WTX_ERROR_T callStat; /* WTX status */
- UINT32 infoMsgVer = WTX_TS_INFO_GET_V2;
- WTX_CHECK_CONNECTED (hWtx, NULL);
- pOut = calloc (1, sizeof (WTX_MSG_TS_INFO));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- /*
- * For description of WTX_TS_INFO_GET_V1 vs WTX_TS_INFO_GET_V2
- * and the two calls to exchange(), see comments in wtxmsg.h
- */
- callStat = exchange (hWtx, infoMsgVer, &hWtx->msgToolId, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- infoMsgVer = WTX_TS_INFO_GET_V1;
- callStat = exchange (hWtx, infoMsgVer, &hWtx->msgToolId, pOut);
- }
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut); /* Free allocated message */
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- /* Free the old target server info stored in the handle */
- if (hWtx->pTsInfo != NULL)
- {
- wtxResultFree (hWtx, hWtx->pTsInfo);
- }
- hWtx->pTsInfo = (WTX_TS_INFO *) &pOut->tgtLinkDesc;
- /* add pointer to the wtxResultFree () list */
- if (wtxFreeAdd (hWtx, (void *) &pOut->tgtLinkDesc, NULL,
- pOut, infoMsgVer, hWtx->server, WTX_SVR_SERVER)
- != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return (hWtx->pTsInfo);
- }
- /*******************************************************************************
- *
- * wtxTsLock - lock the connected target server for exclusive access
- *
- * This routine locks the target server that the client is connected to
- * so it can only be used by this user and no others. Other clients
- * already connected can continue to use the target server
- * until they disconnect. When a target server is locked the only
- * operations another user may perform are connecting, getting the
- * target server information, and disconnecting.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_TS_LOCK, wtxTsUnlock()
- */
- STATUS wtxTsLock
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_ERROR_T callStat; /* WTX status */
- WTX_MSG_TS_LOCK in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.lockType = 0; /* ??? Is the lock type documented anywhere ??? */
- callStat = exchange (hWtx, WTX_TS_LOCK, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_TS_LOCK, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxTsTimedLock - lock the connected target server a limited time
- *
- * This routine locks the target server that the client is connected to so it
- * can only be used by this user and no others. Other clients already connected
- * can continue to use the target server until they disconnect. When a target
- * server is locked the only operations another user may perform are connecting,
- * getting the target server information, and disconnecting.
- *
- * The target server may be locked indefinitely (<seconds> = WTX_LOCK_FOREVER),
- * otherwise if the target server must be locked only for a fixed time, then the
- * duration must be set in <seconds>.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_TS_LOCK, wtxTsLock(), wtxTsUnlock()
- */
- STATUS wtxTsTimedLock
- (
- HWTX hWtx, /* WTX API handle */
- UINT32 seconds /* duration of lock */
- )
- {
- WTX_ERROR_T callStat; /* WTX status */
- WTX_MSG_TS_LOCK in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- if (seconds > 0)
- in.lockType = seconds;
- else
- in.lockType = 0;
- callStat = exchange (hWtx, WTX_TS_LOCK, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_TS_LOCK, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxTsUnlock - unlock the connected target server
- *
- * This routine unlocks the target server that the client is connected to
- * so it can be accessed by any user on its access list. The unlock will
- * only succeed if it is being unlocked by the same user that locked it.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_TS_UNLOCK, wtxTsLock()
- */
- STATUS wtxTsUnlock
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_ERROR_T callStat; /* WTX status */
- WTX_MSG_TS_UNLOCK in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.force = FALSE; /* ??? Is this documented anywhere ??? */
- callStat = exchange (hWtx, WTX_TS_UNLOCK, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_TS_UNLOCK, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxVerify - verify that a WTX handle is valid for use
- *
- * This routine returns WTX_OK if the WTX handle <hWtx> is valid. If an
- * invalid handle is passed to a WTX routine, the error
- * WTX_ERR_API_INVALID_HANDLE occurs. A handle that has been released using
- * wtxTerminate() is invalid.
- *
- * RETURNS: TRUE if the handle is valid or FALSE if not.
- *
- * SEE ALSO: wtxInitialize(), wtxTerminate()
- */
- BOOL32 wtxVerify
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- return (hWtx != NULL && hWtx->self == hWtx);
- }
- /*******************************************************************************
- *
- * wtxVioChanGet - get a virtual I/O channel number
- *
- * This routine returns a free virtual I/O channel number to be
- * used for redirection of target I/O to the host. The returned
- * channel number is an INT32 between 1 and 255. (Channel 0 is
- * reserved for the default console.) When no longer required, the
- * channel number is released using wtxVioChanRelease().
- *
- * RETURNS: The new channel number or WTX_ERROR on failure.
- *
- * SEE ALSO: WTX_VIO_CHAN_GET, wtxVioChanRelease()
- */
- INT32 wtxVioChanGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_RESULT out;
- INT32 result;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&out, 0, sizeof (out));
- callStat = exchange (hWtx, WTX_VIO_CHAN_GET, &hWtx->msgToolId, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- result = out.val.value_u.v_int32;
- wtxExchangeFree (hWtx->server, WTX_VIO_CHAN_GET, &out);
- return result;
- }
- /*******************************************************************************
- *
- * wtxVioChanRelease - release a virtual I/O channel
- *
- * This request releases a virtual I/O channel number previously obtained
- * using wtxVioChanGet() and returns it to the free-channel-number pool of
- * the target server. Valid channel numbers are in the range 1 to 255.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_VIO_CHAN_RELEASE, wtxVioChanGet()
- */
- STATUS wtxVioChanRelease
- (
- HWTX hWtx, /* WTX API handle */
- INT32 channel /* the channel number to release */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_PARAM in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.param.valueType = V_INT32;
- in.param.value_u.v_int32 = channel;
- callStat = exchange (hWtx, WTX_VIO_CHAN_RELEASE, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_VIO_CHAN_RELEASE, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxVioCtl - perform a control operation on a virtual I/O channel
- *
- * This routine performs the special I/O operation specified by <request>
- * on the virtual I/O channel <channel>. An operation-specific
- * parameter is supplied to the operation by <arg>.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_VIO_CTL, wtxVioChanGet()
- */
- STATUS wtxVioCtl
- (
- HWTX hWtx, /* WTX API handle */
- INT32 channel, /* channel to do control operation on */
- UINT32 request, /* control operation to perform */
- UINT32 arg /* arg for call */
- )
- {
- WTX_ERROR_T callStat; /* WTX status */
- WTX_MSG_VIO_CTL_DESC in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.channel = channel;
- in.request = request;
- in.arg = arg;
- callStat = exchange (hWtx, WTX_VIO_CTL, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_VIO_CTL, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxVioFileList - list the files managed by the target server
- *
- * This routine returns a list of all the target-server-managed files along
- * with information about each file including its name, state, and associated
- * virtual I/O channel redirection. The result is a pointer to a pointer to
- * the first item in a linked list of file descriptors. It must be freed by
- * the caller using wtxResultFree(). If the list is empty (no files are
- * managed by the target server), the result points to a NULL value.
- *
- * EXPAND ../../../include/wtxmsg.h WTX_VIO_FILE_DESC
- *
- * RETURNS: A pointer to a pointer to the file list or NULL on error.
- *
- * SEE ALSO: WTX_VIO_FILE_LIST, wtxFileOpen(), wtxFileClose()
- */
- WTX_VIO_FILE_DESC ** wtxVioFileList
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_VIO_FILE_LIST * pOut;
- WTX_CHECK_CONNECTED (hWtx, NULL);
- pOut = calloc (1, sizeof (WTX_MSG_VIO_FILE_LIST));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- callStat = exchange (hWtx, WTX_VIO_FILE_LIST, &hWtx->msgToolId, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut); /* Free allocated message */
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- /* add pointer to the wtxResultFree() list */
- if (wtxFreeAdd (hWtx, (void *) &pOut->pVioFileList, NULL, pOut,
- WTX_VIO_FILE_LIST, hWtx->server, WTX_SVR_SERVER) != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return &pOut->pVioFileList;
- }
- /*******************************************************************************
- *
- * wtxVioWrite - write data to a VIO channel
- *
- * This routine writes at most <numBytes> of data starting at <pData>
- * to the virtual I/O channel number <channel>. The buffer size is 512 bytes;
- * if <numBytes> is greater than 512, the extra bytes are discarded.
- *
- * RETURNS: The number of bytes actually written or WTX_ERROR.
- *
- * SEE ALSO: WTX_VIO_WRITE, wtxEventGet(), wtxVioChanGet()
- */
- UINT32 wtxVioWrite
- (
- HWTX hWtx, /* WTX API handle */
- INT32 channel, /* channel to write to */
- void * pData, /* pointer to data to write */
- UINT32 numBytes /* number of bytes of data to write */
- )
- {
- WTX_ERROR_T callStat; /* WTX status */
- WTX_MSG_VIO_COPY_DESC in;
- WTX_MSG_RESULT out;
- UINT32 bytesWritten;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.channel = channel;
- in.maxBytes = numBytes;
- in.baseAddr = pData;
- callStat = exchange (hWtx, WTX_VIO_WRITE, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- bytesWritten = out.val.value_u.v_uint32;
- wtxExchangeFree (hWtx->server, WTX_VIO_WRITE, &out);
- return bytesWritten;
- }
- /*******************************************************************************
- *
- * wtxTargetAttach - reattach to the target
- *
- * This routine reattaches the client to a target that has been disconnected
- * or for which the target server is waiting to connect.
- *
- * RETURNS: WTX_OK if the target is successfully attached or WTX_ERROR
- * if the target is still unavailable.
- *
- * SEE ALSO: WTX_TARGET_ATTACH
- */
- STATUS wtxTargetAttach
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&out, 0, sizeof (out));
- callStat = exchange (hWtx, WTX_TARGET_ATTACH, &hWtx->msgToolId, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_TARGET_ATTACH, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxProbe - probe to see if the registry service is running
- *
- * This routine returns WTX_OK if the registry service is running. Otherwise
- * it returns WTX_ERROR.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- */
- STATUS wtxProbe
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_ERROR_T callStat;
- WTX_CHECK_HANDLE (hWtx, WTX_ERROR);
- if (registryConnect (hWtx) != WTX_OK)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_REGISTRY_UNREACHABLE, WTX_ERROR);
- callStat = wtxExchange (hWtx->registry, NULLPROC, NULL, NULL);
- /* close registry connection now since we don't need it anymore */
- registryDisconnect (hWtx);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxRegister - register the target server with the Tornado registry service
- *
- * This routine registers the named target server with the WTX registry daemon.
- * If the specified name does not conflict with any other registered server,
- * the registry allocates, initializes, and adds a WTX descriptor structure
- * containing a unique RPC program number to its internal tables. If
- * specified, <name> must be unique for the whole system, and by convention
- * it is a legal C identifier. If <name> is NULL, a unique name is allocated
- * by the registry and returned to the caller. Only one server can be
- * registered per WTX handle.
- *
- * The return value is a pointer to internal data and must not be freed
- * by the user.
- *
- * EXPAND ../../../include/wtxtypes.h WTX_DESC
- *
- * RETURNS: A pointer to a WTX_DESC or NULL if the registration failed.
- *
- * ERRORS:
- * .iP WTX_ERR_API_SERVICE_ALREADY_REGISTERED 12
- * The server has already registered itself.
- * .iP WTX_ERR_API_REGISTRY_UNREACHABLE
- * The registry service is not reachable (in other words, the registry
- * daemon is not running).
- * .iP WTX_ERR_API_MEMALLOC
- * There are insufficient resources to allocate a new WTX descriptor for
- * the server.
- * .iP WTX_ERR_REGISTRY_NAME_CLASH
- * Name already exists in Tornado registry database.
- *
- * SEE ALSO: WTX_REGISTER, wtxUnregister(), wtxInfo()
- */
- WTX_DESC * wtxRegister
- (
- HWTX hWtx, /* WTX API handle */
- const char * name, /* service name, NULL to be named */
- const char * type, /* service type, NULL for unspecified */
- const char * key /* unique service key */
- )
- {
- WTX_DESC * pDesc = NULL; /* copy of the retrned description */
- WTX_ERROR_T callStat;
- WTX_MSG_SVR_DESC in;
- WTX_MSG_SVR_DESC * pOut;
- if (hWtx->pSelfDesc != NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_SERVICE_ALREADY_REGISTERED, NULL);
- if (registryConnect (hWtx) != WTX_OK)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_REGISTRY_UNREACHABLE, NULL);
- /* allocate a new descriptor */
- pOut = calloc (1, sizeof (WTX_MSG_SVR_DESC));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- /* fill in our particulars */
- memset (&in, 0, sizeof (in));
- in.wtxSvrDesc.wpwrName = (char *) name; /* send our name */
- in.wtxSvrDesc.wpwrType = (char *) type; /* send our type */
- in.wtxSvrDesc.wpwrKey = (char *) key; /* send our key */
- callStat = exchange (hWtx, WTX_REGISTER, &in, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut); /* free allocated message */
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- /*
- * let's copy the returned structure field by field and add it to the
- * wtxResultFree List
- */
- if ((pDesc = wtxDescDuplicate ( hWtx, (WTX_DESC *) &pOut->wtxSvrDesc))
- == NULL)
- {
- wtxExchangeFree (hWtx->registry, WTX_REGISTER, pOut);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- }
- /* add pointer description to the wtxResultFree() list */
- if (wtxFreeAdd (hWtx, (void *) pDesc, (FUNCPTR) wtxDescFree,
- NULL, 0, NULL, WTX_SVR_NONE)!= WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- /* close registry connection now since we don't need it anymore */
- wtxExchangeFree (hWtx->registry, WTX_REGISTER, pOut);
- free (pOut);
- registryDisconnect (hWtx);
- hWtx->pSelfDesc = pDesc;
- return (pDesc);
- }
- /*******************************************************************************
- *
- * wtxDescFree - frees a WTX_DESC structure ans all its fields
- *
- * This routine frees the given WTX_DESC, and all the fields it contains.
- *
- * RETURN: N/A
- *
- * ERRNO: N/A
- *
- */
- LOCAL void wtxDescFree
- (
- WTX_DESC * pDescToFree /* WTX_DESC pointer to free */
- )
- {
- if (pDescToFree == NULL)
- goto error;
- if (pDescToFree->wpwrName != NULL)
- free (pDescToFree->wpwrName);
- if (pDescToFree->wpwrType != NULL)
- free (pDescToFree->wpwrType);
- if (pDescToFree->wpwrKey != NULL)
- free (pDescToFree->wpwrKey);
- free (pDescToFree);
- error:
- return;
- }
- /*******************************************************************************
- *
- * wtxUnregister - unregister the server with the Tornado registry
- *
- * This routine removes the specified descriptor from the Tornado-registry
- * internal table. The name of the server is no longer reserved. Passing
- * NULL for <name> means unregister the server already registered against
- * the handle <hWtx> using wtxRegister().
- *
- * RETURNS: WTX_OK or WTX_ERROR if the server could not be unregistered.
- *
- * ERRORS:
- * .iP WTX_ERR_API_SERVICE_NOT_REGISTERED 12
- * The server is trying to unregister itself when it has not registered or
- * has already unregistered.
- * .iP WTX_ERR_API_REGISTRY_UNREACHABLE
- * The registry service is not reachable (in other words, the registry
- * daemon is not running).
- *
- * SEE ALSO: WTX_UNREGISTER, wtxRegister()
- */
- STATUS wtxUnregister
- (
- HWTX hWtx, /* WTX API handle */
- const char *name /* service to unregister, NULL for self */
- )
- {
- WTX_MSG_PARAM in;
- WTX_MSG_RESULT out;
- WTX_ERROR_T callStat;
-
- if ((name == NULL) && /* self? */
- (hWtx->pSelfDesc == NULL ||
- (name = hWtx->pSelfDesc->wpwrName) == NULL))
- /* Unregistering self when not registered */
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_SERVICE_NOT_REGISTERED, WTX_ERROR);
- if (registryConnect (hWtx) != WTX_OK)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_REGISTRY_UNREACHABLE, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- in.param.valueType = V_PCHAR;
- in.param.value_u.v_pchar = (char *) name;
- memset (&out, 0, sizeof (out));
- callStat = exchange (hWtx, WTX_UNREGISTER, &in, &out);
- /* close registry connection now since we don't need it anymore */
- registryDisconnect (hWtx);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- /* if unregistering ourself, destroy our descriptor */
- if (hWtx->pSelfDesc &&
- hWtx->pSelfDesc->wpwrName &&
- STREQ (hWtx->pSelfDesc->wpwrName, name))
- {
- wtxResultFree (hWtx, hWtx->pSelfDesc);
- hWtx->pSelfDesc = NULL;
- }
- wtxExchangeFree (hWtx->registry, WTX_UNREGISTER, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxInfo - allocate and return a descriptor for the named service
- *
- * This routine allocates and fills in a descriptor corresponding to the
- * named service. This routine always queries the WTX registry daemon for
- * the named service and allocates and fills a WTX descriptor structure with
- * the results. The descriptor must be deallocated with wtxResultFree()
- * when it is no longer needed. Passing NULL for <name> means to get
- * information on the server already registered against the handle <hWtx>
- * using wtxRegister().
- *
- * EXPAND ../../../include/wtxtypes.h WTX_DESC
- *
- * RETURNS: A pointer to a WTX_DESC or NULL if the service could not be found.
- *
- * ERRORS:
- * .iP WTX_ERR_API_SERVICE_NOT_REGISTERED 12
- * <name> is NULL and no service is registered against the handle.
- * .iP WTX_ERR_API_REGISTRY_UNREACHABLE
- * The registry service is not reachable (in other words, the registry daemon
- * is not running).
- *
- * SEE ALSO: WTX_INFO_GET, wtxInfoQ()
- */
- WTX_DESC * wtxInfo
- (
- HWTX hWtx, /* WTX API handle */
- const char * name /* service name to lookup */
- )
- {
- WTX_MSG_SVR_DESC * pOut; /* exchange returned value */
- WTX_MSG_PARAM in; /* input parameters desc */
- WTX_ERROR_T callStat; /* exchange result values */
- if ((name == NULL) && /* self? */
- (hWtx->pSelfDesc == NULL ||
- (name = hWtx->pSelfDesc->wpwrName) == NULL))
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_SERVICE_NOT_REGISTERED, NULL);
- if (registryConnect (hWtx) != WTX_OK)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_REGISTRY_UNREACHABLE, NULL);
- /* allocate and initialize registry response */
- pOut = (WTX_MSG_SVR_DESC *) calloc (1, sizeof (WTX_MSG_SVR_DESC));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- memset (&in, 0, sizeof (in));
- in.param.valueType = V_PCHAR;
- in.param.value_u.v_pchar = (char *) name;
- /* ask daemon for information */
- callStat = exchange (hWtx, WTX_INFO_GET, &in, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut); /* Free allocated message */
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- /* add pointer to the wtxResultFree() list */
- if (wtxFreeAdd (hWtx, (void *) &pOut->wtxSvrDesc, NULL, pOut, WTX_INFO_GET,
- hWtx->registry, WTX_SVR_REGISTRY) != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return ( (WTX_DESC *) &pOut->wtxSvrDesc);
- }
- /*******************************************************************************
- *
- * wtxDescDuplicate - duplicates a WTX_DESC structure
- *
- * This routine just duplicates a WTX_DESC structure and all the fields it
- * contains.
- *
- * RETURNS: a pointer on the duplicated WTX_DESC
- *
- * ERRNO:
- * .iP
- * WTX_ERR_API_MEMALLOC
- * .lE
- */
- LOCAL WTX_DESC * wtxDescDuplicate
- (
- HWTX hWtx, /* current WTX session handler */
- WTX_DESC * pDesc /* WTX_DESC to duplicate */
- )
- {
- WTX_DESC * pDuplicate = NULL; /* duplicated WTX_DESC pointer */
- /* allocate the WTX_DESC itself */
- if ( (pDuplicate = (WTX_DESC *) calloc (1, sizeof (WTX_DESC))) == NULL)
- {
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- }
- /* item name memory allocation */
- if ((pDesc->wpwrName != NULL) &&
- ((pDuplicate->wpwrName = strdup (pDesc->wpwrName)) == NULL))
- {
- free (pDuplicate);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- }
- /* item type memory allocation */
- if ((pDesc->wpwrType != NULL) &&
- ((pDuplicate->wpwrType = strdup (pDesc->wpwrType)) == NULL))
- {
- free (pDuplicate->wpwrName);
- free (pDuplicate);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- }
- /* item key memory allocation */
- if ((pDesc->wpwrKey != NULL) &&
- ((pDuplicate->wpwrKey = strdup (pDesc->wpwrKey)) == NULL))
- {
- free (pDuplicate->wpwrType);
- free (pDuplicate->wpwrName);
- free (pDuplicate);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- }
- return (pDuplicate);
- }
- /*******************************************************************************
- *
- * wtxInfoQ - return a list of all services registered with the Tornado registry
- *
- * This routine provides the caller with a table of descriptors corresponding
- * to all services registered with the Tornado registry. An unsorted table
- * of descriptors is allocated and returned. There is no guarantee that
- * the table is valid by the time it is inspected. Services may come and go
- * at any time.
- *
- * EXPAND ../../../include/wtxtypes.h WTX_DESC_Q
- *
- * The table of descriptors should be deallocated with wtxResultFree().
- *
- * RETURNS: A pointer to a table of descriptors or NULL if error.
- *
- * ERRORS:
- * .iP WTX_ERR_API_REGISTRY_UNREACHABLE 12
- * The registry service is not reachable (in other words, the registry
- * daemon is not running).
- * .iP WTX_ERR_API_MEMALLOC
- * There are insufficient resources to allocate the WTX_DESC_Q structure for
- * the result value.
- * .iP WTX_ERR_REGISTRY_BAD_PATTERN
- * One of the given patterns (<namePattern>, <typePattern> or <keyPattern>) is
- * not a valid regular expression.
- * .iP WTX_ERR_REGISTRY_NAME_NOT_FOUND
- * Info required is not in the registry database.
- *
- * SEE ALSO: WTX_INFO_Q_GET, wtxInfo()
- */
- WTX_DESC_Q * wtxInfoQ
- (
- HWTX hWtx, /* WTX API handle */
- const char * namePattern, /* regexp to match svc name */
- const char * typePattern, /* regexp to match svc type */
- const char * keyPattern /* regexp to match svc key */
- )
- {
- WTX_MSG_WTXREGD_PATTERN in; /* input pattern desc */
- WTX_MSG_SVR_DESC_Q * pOut = NULL; /* output message */
- WTX_ERROR_T callStat; /* exchange result values */
- if (registryConnect (hWtx) != WTX_OK)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_REGISTRY_UNREACHABLE, NULL);
- /* allocate and initialize registry response */
- pOut = calloc (1, sizeof (WTX_MSG_SVR_DESC_Q));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- /* fill in patterns for query */
- in.name = (char *) namePattern;
- in.type = (char *) typePattern;
- in.key = (char *) keyPattern;
- /* get list of registered services */
- callStat = exchange (hWtx, WTX_INFO_Q_GET, &in, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut);
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- if (wtxFreeAdd (hWtx, (void *) &pOut->wtxSvrDescQ, NULL, pOut,
- WTX_INFO_Q_GET, hWtx->registry, WTX_SVR_REGISTRY) != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return ( (WTX_DESC_Q *) &pOut->wtxSvrDescQ);
- }
- /*******************************************************************************
- *
- * wtxEach - call a routine to examine each WTX-registered service
- *
- * This routine calls a user-supplied routine to examine each WTX-registered
- * service; it calls the specified routine once for each service. The
- * routine should be declared as follows:
- *
- * .CS
- * BOOL32 routine
- * (
- * WTX_DESC_Q * pDesc, /@ entry name @/
- * int arg /@ arbitrary user-supplied arg @/
- * )
- * .CE
- *
- * The user-supplied routine should return TRUE if wtxEach() is
- * to continue calling it for each entry, or FALSE if it is
- * done and wtxEach() can exit.
- *
- * Note that all descriptors are deallocated upon exit.
- *
- * RETURNS: WTX_OK or WTX_ERROR if the table of descriptors could not be
- * obtained.
- *
- * ERRORS:
- * .iP WTX_ERR_API_REGISTRY_UNREACHABLE 12
- * The registry service is not reachable (in other words, the registry daemon
- * is not running).
- * .iP WTX_ERR_API_MEMALLOC
- * There are insufficient resources to allocate the WTX_DESC_Q structure for
- * the result value.
- *
- * SEE ALSO: wtxInfoQ()
- */
- STATUS wtxEach
- (
- HWTX hWtx, /* WTX API handle */
- const char *namePattern, /* regular expression to match svc name */
- const char *typePattern, /* regular expression to match svc type */
- const char *keyPattern, /* regular expression to match svc key */
- FUNCPTR routine, /* func to call for each svc entry */
- void * routineArg /* arbitrary user-supplied arg */
- )
- {
- WTX_DESC_Q * pWtxDescQ;
- WTX_DESC_Q * pDescQ;
- pWtxDescQ = wtxInfoQ (hWtx, namePattern, typePattern, keyPattern);
- if (pWtxDescQ == NULL)
- /* Note: error has already been dispatched so just return */
- return WTX_ERROR;
- pDescQ = pWtxDescQ;
- /* traverse descriptor queue and call the routine */
- while (pDescQ != NULL)
- {
- if (!((* routine) (pDescQ, routineArg)))
- break;
- pDescQ = (WTX_DESC_Q *) pWtxDescQ->pNext;
- }
- wtxResultFree (hWtx, pWtxDescQ);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxTimeoutSet - set the timeout for completion of WTX calls
- *
- * This routine changes the timeout value for making WTX API calls.
- * When a call takes longer than the value specified by <msec> (in
- * milliseconds), the call aborts with an error status and the
- * error code is set to WTX_ERR_API_REQUEST_TIMED_OUT.
- *
- * NOTE: The timeout for WTX registry calls is unaffected.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: wtxTimeoutGet()
- */
- STATUS wtxTimeoutSet
- (
- HWTX hWtx, /* WTX API handle */
- UINT32 msec /* New timeout value in milliseconds */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- if (wtxExchangeControl (hWtx->server,
- WTX_EXCHANGE_CTL_TIMEOUT_SET, &msec) == WTX_OK)
- return WTX_OK;
- else
- WTX_ERROR_RETURN (hWtx, wtxExchangeErrGet (hWtx->server), WTX_ERROR);
- }
- /*******************************************************************************
- *
- * wtxTimeoutGet - get the current timeout for completion of WTX calls
- *
- * This routine gets the current timeout value for making WTX API calls.
- * The value is returned in the UINT32 pointed to by <pMsec>.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: wtxTimeoutSet()
- */
- STATUS wtxTimeoutGet
- (
- HWTX hWtx, /* WTX API handle */
- UINT32 * pMsec /* Pointer to timeout value in milliseconds */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- if (pMsec == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- if (wtxExchangeControl (hWtx->server,
- WTX_EXCHANGE_CTL_TIMEOUT_GET, pMsec) == WTX_OK)
- return WTX_OK;
- else
- WTX_ERROR_RETURN (hWtx, wtxExchangeErrGet (hWtx->server), WTX_ERROR);
- }
- /*******************************************************************************
- *
- * exchange - wrapper for calling exchange mechanism
- *
- * This routine performs a WTX call selecting the correct exchange handle
- * and doing some additional error checking.
- *
- * RETURNS: WTX_ERR_NONE or error code
- *
- * NOMANUAL
- */
- LOCAL WTX_ERROR_T exchange
- (
- HWTX hWtx, /* handle to use for exchange */
- UINT32 svcNum, /* service number to call */
- void * pIn, /* pointer to in (argument) data */
- void * pOut /* pointer to out (result) data */
- )
- {
- WTX_ERROR_T retVal; /* value to return */
- STATUS status; /* status of exchange call */
- WTX_XID xid; /* exchange handle to use for call */
- /* Figure out which exchange handle to use based on the API service num */
- switch (svcNum)
- {
- case WTX_REGISTER:
- case WTX_UNREGISTER:
- case WTX_INFO_GET:
- case WTX_INFO_Q_GET:
- xid = hWtx->registry;
- break;
- default:
- xid = hWtx->server;
- break;
- }
- /* Fill in the objId field required by some API requests */
- ((WTX_MSG_DUMMY *) pIn)->wtxCore.objId = hWtx->msgToolId.wtxCore.objId;
- /* Do the call */
- status = wtxExchange (xid, svcNum, pIn, pOut);
- /*
- * Stamp the result with the service number so that it can be freed
- * by the free function without knowing its object type. The protVersion
- * field is used to store the address of the result to help identify
- * (not foolproof but fairly good) bogus pointers passed to free.
- */
- if (status == WTX_OK)
- {
- ((WTX_MSG_DUMMY *) pOut)->wtxCore.objId = svcNum;
- ((WTX_MSG_DUMMY *) pOut)->wtxCore.protVersion = (UINT32) pOut;
- return WTX_ERR_NONE;
- }
- /* Analyze the result and see if it requires any special action */
- switch (wtxExchangeErrGet (xid))
- {
- case WTX_ERR_EXCHANGE_TRANSPORT_DISCONNECT:
- /*
- * This exchange transport mechanism has broken down and
- * disconnected us. The error is reported to the caller as
- * WTX_ERR_API_TOOL_DISCONECTED or
- * WTX_ERR_API_REGISTRY_UNREACHABLE (depending on the
- * connection) so the user can tell there is no point in
- * making further calls (which would return
- * WTX_ERR_API_NOT_CONNECTED
- */
- if (xid == hWtx->registry)
- {
- wtxExchangeDelete (xid);
- wtxExchangeTerminate (xid);
- hWtx->registry = NULL;
- retVal = WTX_ERR_API_REGISTRY_UNREACHABLE;
- }
- else
- {
- toolCleanup (hWtx);
- retVal = WTX_ERR_API_TOOL_DISCONNECTED;
- }
- break;
- case WTX_ERR_EXCHANGE_TIMEOUT:
- retVal = WTX_ERR_API_REQUEST_TIMED_OUT;
- break;
- case WTX_ERR_EXCHANGE:
- case WTX_ERR_EXCHANGE_INVALID_HANDLE:
- case WTX_ERR_EXCHANGE_DATA:
- case WTX_ERR_EXCHANGE_MEMALLOC:
- case WTX_ERR_EXCHANGE_NO_SERVER:
- case WTX_ERR_EXCHANGE_INVALID_ARG:
- case WTX_ERR_EXCHANGE_MARSHALPTR:
- case WTX_ERR_EXCHANGE_BAD_KEY:
- case WTX_ERR_EXCHANGE_REQUEST_UNSUPPORTED:
- case WTX_ERR_EXCHANGE_TRANSPORT_UNSUPPORTED:
- case WTX_ERR_EXCHANGE_TRANSPORT_ERROR:
- case WTX_ERR_EXCHANGE_NO_TRANSPORT:
- retVal = WTX_ERR_API_REQUEST_FAILED;
- break;
- default:
- /* some other API error - return error unchanged */
- retVal = wtxExchangeErrGet (xid);
- break;
- }
- return retVal;
- }
- /*******************************************************************************
- *
- * registryConnect - wrapper for setting up registry exchange
- *
- * This routine tries to set up the exchange handle for the registry
- * and connect to the registry service.
- *
- * RETURNS: WTX_ERR_NONE or error code
- *
- * NOMANUAL
- */
- LOCAL WTX_ERROR_T registryConnect
- (
- HWTX hWtx /* handle to connect to registry */
- )
- {
- BOOL usePMap = FALSE; /* use portmapper to connect ? */
- WTX_CHECK_HANDLE (hWtx, WTX_ERR_API_INVALID_HANDLE);
- if ((WTX_XID) hWtx->registry != NULL)
- return WTX_OK;
- /* first initialise the connection */
- if (wtxExchangeInitialize ((WTX_XID *) &hWtx->registry) != WTX_OK ||
- wtxExchangeInstall ((WTX_XID) hWtx->registry,
- wtxRpcExchangeCreate,
- wtxRpcExchangeDelete,
- wtxRpcExchange,
- wtxRpcExchangeFree,
- wtxRpcExchangeControl) != WTX_OK)
- {
- wtxExchangeTerminate ((WTX_XID) hWtx->registry);
- hWtx->registry = (WTX_XID) NULL;
- return WTX_ERROR;
- }
- /* now create th connection */
- use_pmap:
- if (wtxExchangeCreate ((WTX_XID) hWtx->registry, NULL, usePMap) != WTX_OK)
- {
- if (! usePMap)
- {
- /* well, let's try with the port mapper ... */
- usePMap = TRUE;
- goto use_pmap;
- }
- wtxExchangeTerminate ((WTX_XID) hWtx->registry);
- hWtx->registry = (WTX_XID) NULL;
- return WTX_ERROR;
- }
- return WTX_OK;
- }
- /*******************************************************************************
- *
- * registryDisconnect - wrapper for closing registry exchange
- *
- * This routine terminates the exchange handle for the registry
- * and clears the registry field in the WTX handle.
- *
- * RETURNS: WTX_ERR_NONE or error code
- *
- * NOMANUAL
- */
- LOCAL void registryDisconnect
- (
- HWTX hWtx /* handle to disconnect registry */
- )
- {
- if (hWtx->registry == NULL) /* check if not already disconnected */
- return;
- wtxExchangeDelete (hWtx->registry); /* close registry connection */
- wtxExchangeTerminate (hWtx->registry); /* cleanup */
- hWtx->registry = NULL; /* clear handle */
- return;
- }
- /*******************************************************************************
- *
- * toolCleanup - do the cleanups necessary when a tool detaches
- *
- * RETURNS: N/A
- *
- * NOMANUAL
- */
- LOCAL void toolCleanup
- (
- HWTX hWtx /* handle to connect to server */
- )
- {
- if (hWtx == NULL)
- return;
- /* Free up the target server info before deleting the exchange handle */
- if (hWtx->pTsInfo)
- {
- wtxResultFree (hWtx, hWtx->pTsInfo);
- hWtx->pTsInfo = NULL;
- }
- /* Free Target tool name */
- if (hWtx->targetToolName != NULL)
- {
- free (hWtx->targetToolName);
- hWtx->targetToolName = 0;
- }
- /* Free up the tool descriptor */
- if (hWtx->pToolDesc)
- {
- wtxResultFree (hWtx, hWtx->pToolDesc);
- hWtx->pToolDesc = NULL;
- }
- /*
- * as we exit the WTX session, all the pointers from the wtxResultFree()
- * pointers list should be freed.
- */
- if (hWtx->pWtxFreeList != NULL)
- {
- if (sllCount (hWtx->pWtxFreeList) > 0)
- {
- sllEach (hWtx->pWtxFreeList, wtxResultFreeServerListTerminate,
- (int) &hWtx);
- }
- /* don't delete the free list, it has to be done in wtxTerminate() */
- }
- if (hWtx->server != NULL)
- {
- wtxExchangeDelete (hWtx->server);
- wtxExchangeTerminate (hWtx->server);
- }
- hWtx->server = NULL;
- }
- /*******************************************************************************
- *
- * serverDescFree - de-allocate server descriptor
- *
- * RETURNS: N/A
- *
- * NOMANUAL
- */
- LOCAL void serverDescFree
- (
- HWTX hWtx /* handle to connect to server */
- )
- {
- if ((hWtx != NULL) && (hWtx->pServerDesc != NULL))
- {
- free (hWtx->pServerDesc->wpwrName);
- free (hWtx->pServerDesc->wpwrKey);
- free (hWtx->pServerDesc->wpwrType);
- free (hWtx->pServerDesc);
- hWtx->pServerDesc = NULL;
- }
- }
- #ifndef HOST
- /*******************************************************************************
- *
- * stringDup - duplicates a sting
- *
- * This routine just duplicates a string, an strdup() call can not be made as far
- * as the target has no strdup(), and wtx.c should be compiled on both host and
- * target sides.
- *
- * RETURNS: A char pointer to the allocated/ duplicated string
- *
- * ERRORS:
- * .iP
- * WTX_ERR_API_MEM_ALLOC
- * .LE
- *
- */
- LOCAL char * stringDup
- (
- const char * strToDup /* string to duplicate */
- )
- {
- char * duplicatedStr = NULL; /* duplicated string */
- if (strToDup == NULL)
- goto error;
- if ( (duplicatedStr = (char *) calloc (strlen (strToDup) + 1,
- sizeof (char))) == NULL)
- {
- goto error;
- }
- if ( strcpy (duplicatedStr, strToDup) == NULL)
- {
- free (duplicatedStr);
- duplicatedStr = NULL;
- }
- error:
- return (duplicatedStr);
- }
- #endif /* ! HOST */
- /******************************************************************************
- *
- * wtxToolIdGet - return the tool identifier of the current tool
- *
- * This function returns the tool identifier associated with the given
- * handle <hWtx>.
- *
- * RETURNS: The tool identifier or WTX_ERROR on error.
- */
- UINT32 wtxToolIdGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_CHECK_CONNECTED (hWtx, 0);
- if (hWtx->pToolDesc != NULL)
- return (hWtx->pToolDesc->id);
- else
- return (WTX_ERROR);
- }
- /*******************************************************************************
- *
- * wtxMemDisassemble - get disassembled instructions matching the given address
- *
- * This routine gets a list of disassembled instructions matching given address.
- * <startAddr> indicates where to begin disassembly, while <nInst> fixes the
- * number of instructions to disassemble.
- *
- * If <endAddr> is set, <nInst> has no matter, and only instructions between
- * <startAddr> and <endAddr> are returned.
- *
- * Formatting options are <printAddr> to print instruction's address,
- * <printOpcodes> to print instruction's opcodes, and <hexAddr> to turn off the
- * "symbolic + offset" address representation.
- *
- * The returned structure is a WTX_DASM_INST_LIST described below :
- *
- * EXPAND ../../../include/wtxmsg.h WTX_DASM_INST_LIST
- *
- * Each disassembled instruction has the following format :
- *
- * .CS
- * {<symbolName>} <size> {<address>} {<opcodes>} {<disassembledInstruction>}
- * .CE
- *
- * The <symbolname> value is set to the symbol name corresponding to the current
- * address, or to {} if no symbol name matches current instruction address.
- *
- * <size> represents the instruction size in bytes of memory
- *
- * <address> field is set only if `prependAddress' is set to TRUE. Else an empty
- * list member is returned : {}
- *
- * <opcodes> of disassembled instructions are returned if the `prependOpcode',
- * else an empty list member is returned : {}.
- *
- * The <disassembledInstruction> member is also quoted into curled braces to
- * be easier to reach. The disassembled instruction contains the instruction
- * mnemonic and adress, registers, ... as displayed by the board disassembler.
- *
- * NOTE :
- * All the fields are always returned, even if empty, so a disassembled
- * instruction always have the same number of members whatever are the options.
- *
- * NOTE : The instruction list allocated by wtxMemDisassemble should be freed by
- * caller with wtxResultFree().
- *
- * RETURNS: A pointer to a list of disassembled instructions or NULL on error.
- *
- * EXAMPLES:
- *
- * Getting disassembled instuctions from address 12345 to address 15432, with
- * instruction's address and instruction's opcode prepended :
- *
- * .CS
- * startAddress = 12345; /@ first instruction's address @/
- * endAddress = 15432; /@ last instruction's address @/
- * nInst = 0; /@ unhandled when endAddress is set @/
- * prependAddress = TRUE; /@ instruction's address prepended @/
- * prependOpcode = TRUE; /@ opcodes joined to instruction @/
- * hexAddr = FALSE; /@ "symbolic + offset" mode turned on @/
- *
- * pWtxDasmInstList = wtxMemDisassemble (hWtx, startAddress, nInst, endAddress,
- * prependAddress, prependOpcode,
- * hexAddr);
- * ...
- *
- * wtxResultFree (hWtx, pWtxDasmInstList);
- * .CE
- *
- * Getting 25 instructions, starting from address 54321. Address in disassembled
- * instruction are only hexadecimal (not represented by a symbol name + offset).
- * No instruction's addresses, no opcodes.
- *
- * .CS
- * startAddress = 54321; /@ first instruction's address @/
- * endAddress = 0; /@ get a known number of instructions @/
- * nInst = 25; /@ get 25 disassembled instructions @/
- * prependAddress = FALSE; /@ don't join addresses @/
- * prependOpcode = FALSE; /@ don't join opcodes @/
- * hexAddr = TRUE; /@ "symbolic + offset" mode turned off @/
- *
- * pWtxDasmInstList = wtxMemDisassemble (hWtx, startAddress, nInst, endAddress,
- * prependAddress, prependOpcode,
- * hexAddr);
- * ...
- *
- * wtxResultFree (hWtx, pWtxDasmInstList);
- * .CE
- *
- * SEE ALSO: WTX_MEM_DISASSEMBLE, wtxSymListGet(), wtxResultFree().
- */
- WTX_DASM_INST_LIST * wtxMemDisassemble
- (
- HWTX hWtx, /* WTX API handle */
- TGT_ADDR_T startAddr, /* Inst address to match */
- UINT32 nInst, /* number of instructions to get */
- TGT_ADDR_T endAddr, /* Last address to match */
- BOOL32 printAddr, /* if instruction's address appended */
- BOOL32 printOpcodes, /* if instruction's opcodes appended */
- BOOL32 hexAddr /* for hex adress representation */
- )
- {
- WTX_MSG_DASM_DESC in; /* disassembling parameters */
- WTX_MSG_DASM_INST_LIST * pOut; /* disassembled message */
- WTX_MSG_DASM_INST_LIST out; /* local disassembled message */
- WTX_ERROR_T callStat; /* error message */
- UINT32 listSize = 0; /* list size in bytes */
- char * instList = NULL;/* list of instructions */
- BOOL32 firstExchange; /* first exchange indicator */
- /* check for connection */
- WTX_CHECK_CONNECTED (hWtx, NULL);
- pOut = (WTX_MSG_DASM_INST_LIST *)calloc (1, sizeof(WTX_MSG_DASM_INST_LIST));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- /* initialize disassembling parameters */
- memset (&in, 0, sizeof (in));
- in.wtxCore.objId = hWtx->msgToolId.wtxCore.objId;
- in.startAddr = startAddr;
- in.endAddr = endAddr;
- if ((endAddr == 0) && (nInst == 0))
- in.nInst = N_DASM_INST_DEFAULT;
- else
- in.nInst = nInst;
- in.printAddr = printAddr;
- in.printOpcodes = printOpcodes;
- in.hexAddr = hexAddr;
- in.giveMeNext = FALSE;
- firstExchange = TRUE;
- do
- {
- memset (&out, 0, sizeof (out));
- /* call for target server routines */
- callStat = exchange (hWtx, WTX_MEM_DISASSEMBLE, &in, &out);
- if (callStat != WTX_ERR_NONE)
- {
- if (instList != NULL)
- free (instList);
- free (pOut);
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- /* copy first part of message */
-
- if (firstExchange)
- {
- listSize = out.instList.listSize;
- instList = (char *) calloc (listSize + 1, sizeof (char));
- firstExchange = FALSE;
- }
- strcat (instList, out.instList.pInst);
- /* ensure next message is to come */
- in.giveMeNext = out.moreToCome;
- wtxExchangeFree (hWtx->server, WTX_MEM_DISASSEMBLE, &out);
- } while (in.giveMeNext);
- /* Set up pOut so that it can be freed by wtxResultFree() */
- pOut->wtxCore.protVersion = (UINT32) pOut;
- pOut->wtxCore.objId = WTX_MEM_DISASSEMBLE;
-
- /* set the disassembled instructions data */
- pOut->instList.pInst = (char *)calloc (listSize + 1, sizeof (char));
- strcpy (pOut->instList.pInst, instList);
- pOut->instList.nextInst = out.instList.nextInst;
- pOut->instList.listSize = out.instList.listSize;
- free (instList);
- /* add pointer to the wtxResultFree() list */
- if (wtxFreeAdd (hWtx, (void *) &pOut->instList,
- (FUNCPTR) wtxMemDisassembleFree, pOut, 0, NULL,
- WTX_SVR_NONE) != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return (&pOut->instList);
- }
- /*******************************************************************************
- *
- * wtxMemDisassembleFree - frees memory allocated by wtxMemDisassemble()
- *
- * As wtxMemDisasssmble() routine is not stateless, it allocates memory, and the
- * RPC buffers are not holding the disassembled lists. This routine frees the
- * memory allocated by the (sucessive ?) cals to wtxMemDisassemble without
- * calling to the RPC stuff.
- *
- * RETURNS: WTX_OK or WTX_ERROR if free operation failed
- *
- * NOMANUAL
- */
- LOCAL STATUS wtxMemDisassembleFree
- (
- WTX_DASM_INST_LIST * pDasmInstList /* disassembled list to free */
- )
- {
- if (pDasmInstList->pInst != NULL)
- free (pDasmInstList->pInst);
- return (WTX_OK);
- }
- #ifdef HOST
- /*******************************************************************************
- *
- * wtxAsyncEventGet - get an event from the asynchronous event list
- *
- * When the asynchronous event notification is started without user defined
- * function, the only way to get events is to use wtxAsyncEventGet.
- * This routine polls the asynchronous event list for any events sent
- * to this client tool. It only returns one event at a time. The event
- * descriptor returned is a string containing the primary event data,
- * a length count of additional binary data and a pointer to the
- * additional data. The memory allocated for the event-descriptor
- * result must be freed by the user using wtxAsyncResultFree().
- *
- * NOTE: If the asynchronous event notification is started with a user defined
- * function, then wtxAsyncEventGet() will always return a NULL pointer.
- *
- * EXPAND ../../../include/wtxmsg.h WTX_EVENT_DESC
- *
- * RETURN: A pointer to the descriptor for the event received or NULL.
- *
- * SEE ALSO: wtxAsyncNotifyEnable(), wtxAsyncNotifyDisable(), wtxAsyncResultFree(), wtxEventGet()
- */
- WTX_EVENT_DESC * wtxAsyncEventGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_EVENT_DESC * pEventList = NULL;
- /* check for connection */
- WTX_CHECK_CONNECTED (hWtx, NULL);
- pEventList = (wtxAsyncEventDescGet(hWtx->asyncHandle));
- /* XXX - pai:
- * Note that if this mod is accepted, it changes the API
- * and breaks code which uses this routine as documented
- * in the comment header. Expect runtime errors if the
- * following mod is compiled in.
- *
- * /@ add pointer to the wtxResultFree() list @/
- *
- * if (pEventList != NULL)
- * {
- * if (wtxFreeAdd (hWtx, (void *) pEventList,
- * (FUNCPTR) wtxAsyncResultFree_2, NULL, 0, NULL,
- * WTX_SVR_NONE) != WTX_OK)
- * {
- * WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- * }
- * }
- */
- return (pEventList);
- }
- /*******************************************************************************
- *
- * wtxAsyncResultFree - free memory used by a wtxAsyncEventGet() call result
- *
- * This routine frees the memory allocated for the result of a
- * wtxAsyncEventGet() call. eventDesc must point to the WTX_EVENT_DESC
- * structure that was returned by wtxAsyncEventGet() call.
- *
- * NOTE: result should be freed calling wtxResultFree() routine
- *
- * RETURNS: WTX_OK
- *
- * SEE ALSO: wtxAsyncEventGet(), wtxAsyncNotifyEnable(), wtxAsyncNotifyDisable()
- */
-
- STATUS wtxAsyncResultFree
- (
- HWTX hWtx,
- WTX_EVENT_DESC * eventDesc /* pointer to structure to free */
- )
- {
- /* if eventDesc is NULL: nothing to free */
- if (eventDesc != NULL)
- {
- /* is there additional data to free */
- if (eventDesc->addlDataLen != 0)
- free (eventDesc->addlData);
- free (eventDesc->event);
- free (eventDesc);
- }
- return (WTX_OK);
- }
- #if 0
- /* XXX : fle : for SRP#67326 */
- /*******************************************************************************
- *
- * wtxAsyncResultFree_2 - free memory used by a wtxAsyncEventGet() call result
- *
- * This routine is the routine that should be used by wtxResultFree(). It is
- * different from the wtxAsyncResultFree which was also using an hWtx WTX
- * handler.
- *
- * This routine frees the memory allocated for the result of a
- * wtxAsyncEventGet() call. eventDesc must point to the WTX_EVENT_DESC
- * structure that was returned by wtxAsyncEventGet() call.
- *
- * RETURNS: WTX_OK
- *
- * SEE ALSO: wtxAsyncEventGet(), wtxAsyncNotifyEnable(), wtxAsyncNotifyDisable()
- * wtxResultFree()
- *
- * NOMANUAL
- */
-
- LOCAL STATUS wtxAsyncResultFree_2
- (
- WTX_EVENT_DESC * eventDesc /* pointer to structure to free */
- )
- {
- /* if eventDesc is NULL: nothing to free */
- if (eventDesc != NULL)
- {
- /* is there additional data to free */
- if (eventDesc->addlDataLen != 0)
- free (eventDesc->addlData);
- free (eventDesc->event);
- free (eventDesc);
- }
- return (WTX_OK);
- }
- #endif /* 0 */
- #endif /* HOST */
- #ifdef HOST
- /*******************************************************************************
- *
- * wtxDefaultDemanglerStyle - appropriate demangling style for target tool
- *
- * This routine returns an appropriate demangling style based on the current
- * target tool. For example if the kernel was built with the Diab toolchain,
- * the routine returns DMGL_STYLE_DIAB. If the target is not connected,
- * or the tool is not recognized, the routine defaults to returning the GNU
- * demangling style (DMGL_STYLE_GNU).
- *
- * Typically this routine will be used in conjunction with the demangle
- * function:
- *
- * .CS
- * dmgl = demangle(symbolName, wtxDefaultDemanglerStyle(hWtx), demangleMode);
- * .CE
- *
- * RETURNS: a DEMANGLER_STYLE
- *
- * ERRORS: N/A
- *
- * INCLUDE FILES: demangle.h
- */
- DEMANGLER_STYLE wtxDefaultDemanglerStyle
- (
- HWTX hWtx
- )
- {
- const char * tool = wtxTargetToolFamilyGet(hWtx);
- if (tool)
- {
- if (strcmp(tool, "diab") == 0)
- return DMGL_STYLE_DIAB;
- /* add additional tools here */
- }
- /* default to GNU */
- return DMGL_STYLE_GNU;
- }
- /*******************************************************************************
- *
- * wtxTargetToolFamilyGet - extract the tool family (e.g. "gnu" or "diab")
- *
- * RETURNS: a string
- *
- * ERRORS: N/A
- *
- */
- const char * wtxTargetToolFamilyGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- static const char * toolFamilies[] =
- {
- "gnu",
- "diab"
- };
- int i; /* index into toolFamilies */
- const char * result = "gnu";
- const char * tool = wtxTargetToolNameGet(hWtx);
- /* fixme; we should query the target for TOOL_FAMILY
- * rather than relying on the tool being "gnu" or "diab" */
- for (i = 0; i != sizeof(toolFamilies) / sizeof(const char *); ++i)
- {
- if (strstr(tool, toolFamilies[i]))
- {
- result = toolFamilies[i];
- break;
- }
- }
- return result;
- }
- #endif /* HOST */