📄 wtx.c
字号:
/* Cleanup the exchange */ wtxExchangeTerminate ((WTX_XID) hWtx->server); hWtx->server = (WTX_XID) NULL; WTX_ERROR_RETURN (hWtx, errCode, WTX_ERROR); }use_pmap: if (wtxExchangeCreate ((WTX_XID) hWtx->server, hWtx->pServerDesc->wpwrKey, usePMap) != WTX_OK) { /* * if the error comes from the wtxExchangeCreate() routine and if * it has to deal with the IP address, then let's try to see if we * can change the IP adapter */ if (wtxExchangeErrGet (hWtx->server) == WTX_ERR_EXCHANGE_NO_SERVER) { /* if there are several adapter, let's try the next one */ oldKey = hWtx->pServerDesc->wpwrKey; while ((tmpKey = wtxRpcKeyIPListUpdate (hWtx->pServerDesc->wpwrKey, ++ipNum)) != NULL) { if (wtxExchangeCreate ((WTX_XID) hWtx->server, tmpKey, usePMap) == WTX_OK) { HWTX regdHWtx; /* wtx handle for registry */ /* this is the right key, save it and update registry */ hWtx->pServerDesc->wpwrKey = tmpKey; free (oldKey); /* init the registry session */ wtxInitialize (®dHWtx); /* update registry entry */ if (wtxUnregister (regdHWtx, hWtx->pServerDesc->wpwrName) != WTX_OK) WTX_ERROR_RETURN (hWtx, regdHWtx->errCode, WTX_ERROR); if ( (pNewDesc = wtxRegister (regdHWtx, hWtx->pServerDesc->wpwrName, hWtx->pServerDesc->wpwrType, tmpKey)) == NULL) { WTX_ERROR_RETURN (hWtx, regdHWtx->errCode, WTX_ERROR); } /* * end the registry session, wtxTerminate should free the * new description, no need to free it manuall. */ wtxTerminate (regdHWtx); goto updated_key; } } /* ok, now try again with the port mapper then ... */ if (!usePMap) { usePMap = TRUE; goto use_pmap; } } /* Record the error code */ errCode = wtxExchangeErrGet ((WTX_XID) hWtx->server); /* free server descriptor */ serverDescFree (hWtx); /* Cleanup the exchange */ wtxExchangeTerminate ((WTX_XID) hWtx->server); hWtx->server = (WTX_XID) NULL; WTX_ERROR_RETURN (hWtx, errCode, WTX_ERROR); }updated_key: memset (&in, 0, sizeof (in)); in.wtxToolDesc.toolName = (char *) toolName;#ifdef HOST#ifdef WIN32 { UINT32 size = sizeof (usrName); if(!GetUserName (usrName, &size)) envUser = NULL; else envUser = usrName; }#else envUser = getenv ("USER");#endif /* WIN32 */ gethostname (hostNameBuf, sizeof (hostNameBuf));#else envUser = sysBootParams.usr; strcpy (hostNameBuf, sysBootParams.targetName);#endif /* HOST */ if (envUser == NULL) envUser = "unknown"; if (hostNameBuf[0] == '\0') strcpy (hostNameBuf, "unknown"); sprintf (userName, "%.24s@%.24s", envUser, hostNameBuf); in.wtxToolDesc.userName = userName; pOut = calloc (1, sizeof (WTX_MSG_TOOL_DESC)); if (pOut == NULL) { /* Close the connection to the server */ wtxExchangeDelete (hWtx->server); /* free server descriptor */ serverDescFree (hWtx); /* Clean up the exchange */ wtxExchangeTerminate (hWtx->server); hWtx->server = NULL; WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, WTX_ERROR); } /* Do the attach call */ callStat = exchange (hWtx, WTX_TOOL_ATTACH, &in, pOut); if (callStat != WTX_ERR_NONE) { /* Close the connection to the server */ wtxExchangeDelete (hWtx->server); /* free server descriptor */ serverDescFree (hWtx); /* Clean up the exchange */ wtxExchangeTerminate (hWtx->server); hWtx->server = NULL; WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR); } /* Set the msgToolId and pToolDesc filed in the HWTX for future use */ hWtx->pToolDesc = &pOut->wtxToolDesc; hWtx->msgToolId.wtxCore.objId = pOut->wtxToolDesc.id; if (wtxFreeAdd (hWtx, (void *) &pOut->wtxToolDesc, NULL, pOut, WTX_TOOL_ATTACH, hWtx->server, WTX_SVR_SERVER) != WTX_OK) { WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), WTX_ERROR); } return (WTX_OK); }/********************************************************************************* wtxToolConnected - check to see if a tool is connected to a target server** This routine checks if the tool represented by <hWtx> is currently* connected to a target server. ** NOTE: If <hWtx> is an invalid handle then FALSE is returned.** RETURNS: TRUE if the tool is connected, FALSE otherwise.** SEE ALSO: wtxErrClear(), wtxErrGet()*/BOOL32 wtxToolConnected ( HWTX hWtx /* WTX API handle */ ) { WTX_CHECK_HANDLE (hWtx, FALSE); return (hWtx->server != NULL); }/********************************************************************************* wtxToolDetach - detach from the target server** This routine detaches from the target server. * The connection status for <hWtx> is cleared and any memory* allocated by the tool attach is freed. ** CLEANUP* This routine cleans all the tools allocated pointers. All items that have been* allocated by `wtx' calls during the wtxToolAttach() are freed. All the* elements are freed calling for the wtxResultFree() routine. This makes* impossible to access data from previous `wtx' calls.** NOTE: Even if the detach fails internally (for example, the server* it is attached to has died), the API still puts the handle into a* detached state and performs all necessary internal cleanup. In this* case the internal error is `not' reported since the tool is no longer* attached and the handle can subsequently be attached to another server.** RETURNS: WTX_OK or WTX_ERROR.** SEE ALSO: WTX_TOOL_DETACH, wtxToolAttach()*/STATUS wtxToolDetach ( HWTX hWtx /* WTX API handle */ ) { WTX_ERROR_T callStat; /* WTX call status */ WTX_MSG_RESULT out; /* WTX result */ WTX_CHECK_HANDLE (hWtx, WTX_ERROR); if (! wtxToolConnected(hWtx)) return (WTX_OK);#ifdef HOST /* close async. notif */ wtxAsyncStop (&hWtx->asyncHandle); hWtx->asyncHandle = NULL;#endif /* HOST */ memset (&out, 0, sizeof (out)); callStat = exchange (hWtx, WTX_TOOL_DETACH, &hWtx->msgToolId, &out); /* Free allocated memory and close neatly the connection to the server */ if (callStat == WTX_ERR_NONE) wtxExchangeFree (hWtx->server, WTX_TOOL_DETACH, &out); /* * free the server descriptor and the strings that were allocated in * wtxToolAttach(). */ serverDescFree (hWtx); toolCleanup(hWtx); /* Actively ignore any errors that may occur */ return (WTX_OK); }/********************************************************************************* wtxInitialize - initialization routine to be called by the WTX client** This routine allocates a handle structure for the tool's use and* does any initialization required for use of the WTX interface. All* subsequent calls by the tool should use the handle returned in <phWtx>.* If WTX_ERROR is returned and the handle <phWtx> is zero, then the* initialization failed because the internal handle structure could* not be allocated. Otherwise use wtxErrMsgGet() to find the cause* of the error.* * RETURNS: WTX_OK or WTX_ERROR if the initialization fails.** ERRORS: * .iP WTX_ERR_API_INVALID_ARG 12* The pointer <phWtx> is NULL.* .iP WTX_ERR_API_MEMALLOC * The handle cannot be allocated.** SEE ALSO: wtxTerminate(), wtxVerify()*/STATUS wtxInitialize ( HWTX * phWtx /* RETURN: handle to use in subsequent API calls */ ) { if (phWtx == NULL) WTX_ERROR_RETURN (NULL, WTX_ERR_API_INVALID_ARG, WTX_ERROR); *phWtx = calloc (1, sizeof (struct _wtx)); if (*phWtx == NULL) WTX_ERROR_RETURN (NULL, WTX_ERR_API_MEMALLOC, WTX_ERROR); /* Set the field that identifies this as a valid handle */ (*phWtx)->self = *phWtx; (*phWtx)->pWtxFreeList = NULL; return (WTX_OK); }/********************************************************************************* wtxTerminate - terminate the use of a WTX client handle** This routine destroys the specified context handle so it may no* longer be used in WTX API calls. If the tool is attached to a* target server, it is first detached. (It is forcibly detached if* errors make a normal detach impossible.) Any memory allocated by * the handle is freed and the handle is invalidated; any subsequent * use causes an abort.** CLEANUP* This routine frees all the `wtx' pointers that have been allocated by `wtx'* calls during the session. Thus, it makes it impossible to address them anymore** RETURNS: WTX_OK or WTX_ERROR.** SEE ALSO: wtxInitialize(), wtxVerify()*/STATUS wtxTerminate ( HWTX hWtx /* WTX API handle */ ) { WTX_CHECK_HANDLE (hWtx, WTX_ERROR); wtxToolDetach (hWtx); /* * 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, wtxResultFreeListTerminate, (int) &hWtx); } sllDelete (hWtx->pWtxFreeList); hWtx->pWtxFreeList = NULL; } if (hWtx->pServerDesc) { wtxResultFree (hWtx, hWtx->pServerDesc); } if (hWtx->pSelfDesc) { wtxResultFree (hWtx, hWtx->pSelfDesc); } if (hWtx->registry) wtxExchangeDelete (hWtx->registry); wtxExchangeTerminate (hWtx->server); wtxExchangeTerminate (hWtx->registry); /* Invalidate this handle in case it is used after terminate */ hWtx->self = NULL; /* Now free up the handle memory */ free (hWtx); return (WTX_OK); }/********************************************************************************* wtxErrSet - set the error code for the handle** This routine sets the error value <errCode> in the handle specified * by <hWtx> so that wtxErrGet() can return <errCode> as the error.** NOTE: Error handlers for the handle are not called. To set the error* code and call the registered error handlers, use wtxErrDispatch().** RETURNS: WTX_OK or WTX_ERROR.** SEE ALSO: wtxErrGet(), wtxErrMsgGet(), wtxErrClear(), wtxErrDispatch().*/STATUS wtxErrSet ( HWTX hWtx, /* WTX API handle */ UINT32 errCode /* error value to set */ ) { WTX_CHECK_HANDLE (hWtx, WTX_ERROR); /* Ensure any allocated strings are freed up */ wtxErrClear (hWtx); hWtx->errCode = errCode; return (WTX_OK); }/********************************************************************************* wtxErrGet - return the last error for a handle** This routine returns the last error that occurred for the <hWtx> handle.* The error code is only valid after an error is reported by one of the* API calls. To check for an error after a series of API calls use * wtxErrClear() to clear the error status at the start and call wtxErrGet()* at the end. ** RETURNS: The last error code or WTX_ERROR if the handle is invalid.** SEE ALSO: wtxErrMsgGet(), wtxErrSet(), wtxErrClear()*/WTX_ERROR_T wtxErrGet ( HWTX hWtx /* WTX API handle */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -