⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symsynclib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
    /*     * initialize the synchronized group list : vxWorks symbols are always     * synchronized (group is 1 on target side and 1 on host side).     */    dllInit (&symSyncLst);    dllInit (&symSyncTmpLst);    groupAdd (&symSyncLst, 1, 1);    /* initialize the task access to the RPC package */    rpcTaskInit ();    /* initialize WTX session handle */    if (wtxInitialize (&symSyncHWtx) != WTX_OK)	return (ERROR);        wtxErrHId = wtxErrHandlerAdd (symSyncHWtx,				  (WTX_HANDLER_FUNC)&syncErrHandler, 0);    if (wtxErrHId == NULL)	{	fprintf (stderr,		 "Unable to initialize synchronization task. Giving up.\n");	wtxTerminate (symSyncHWtx);	return (ERROR);	}    /* attach to Target Server */    wtxToolAttach (symSyncHWtx, tgtSvrName, SYM_SYNC_TOOL_NAME);    /* set WTX timeout if necessary */    if (symSyncWtxTimeout != 0)	wtxTimeoutSet (symSyncHWtx, symSyncWtxTimeout);    /* register for events */    wtxRegisterForEvent (symSyncHWtx, regEvtStr);    /* synchronize symbol tables */    symSyncMain (symSyncHWtx);    /* detach from target server */    wtxToolDetach (symSyncHWtx);    /* remove error handler */    wtxErrHandlerRemove (symSyncHWtx, wtxErrHId);    wtxTerminate (symSyncHWtx);    return (OK);    }/******************************************************************************** symSyncMain - main routine** This routine waits for target or host synchronization events and does the* corresponding job.** RETURNS: OK or ERROR.** NOMANUAL*/STATUS symSyncMain     (    HWTX		hWtx    )    {    WTX_EVENT_DESC *	pEvtDesc;			/* event descriptor */    char 		tgtEvtBuffer[SYNC_TGT_EVT_LGTH];    char 		doneEvtBuffer[SYNC_TGT_EVT_LGTH];    symSyncKill = FALSE;    while (!symSyncKill)	{	if (msgQReceive (symSyncMsgQId, tgtEvtBuffer, SYNC_TGT_EVT_LGTH,			 TIMEOUT) != ERROR)	    {#ifdef DEBUG    	    logMsg ("tgt evt: %s\n", (int)tgtEvtBuffer, 0, 0, 0, 0, 0);#endif	    symSyncHostUpdate (hWtx, tgtEvtBuffer, doneEvtBuffer);	    }	else	    {	    if ((pEvtDesc = wtxEventGet (hWtx)) == NULL)		continue;	/* we got a timeout, may be better next time */	    while (strcmp (pEvtDesc->event, "") != 0)	/* no event received */		{		if (strcmp (pEvtDesc->event, "SYNC_STOP") == 0)		    	    {#ifdef DEBUG		    logMsg ("stop event received\n", 0, 0, 0, 0, 0, 0);#endif		    symSyncKill = TRUE;		    break;		    }		else			/* split event string and process it */		    {#ifdef DEBUG 		    logMsg ("tgtsvr evt: %s\n", (int)pEvtDesc->event,0,0,0,0,0);#endif		    symSyncTgtUpdate (hWtx, pEvtDesc->event, doneEvtBuffer);		    wtxEventAdd (hWtx, doneEvtBuffer, 0, NULL);		    }		wtxResultFree (hWtx, pEvtDesc);		if ((pEvtDesc = wtxEventGet (hWtx)) == NULL)		    break;	/* we got a timeout, giving up */		}	    if (pEvtDesc != NULL)		wtxResultFree (hWtx, pEvtDesc);	    }	}    return (OK);    }/******************************************************************************** groupAdd - add a group to a group list.** RETURNS: OK if addition is possible, ERROR otherwise.** NOMANUAL*/STATUS groupAdd    (    DL_LIST *	pList,    UINT16	tgtGroup,    UINT32	hostGroup    )    {    GROUP_NODE *	pToAdd = (GROUP_NODE *) malloc (sizeof (GROUP_NODE));    if (pToAdd)	{	pToAdd->tgtGroup = tgtGroup;	pToAdd->hostGroup = hostGroup;	dllAdd (pList, (DL_NODE *)pToAdd);	return (OK);	}    return (ERROR);    }/******************************************************************************** groupFind - find if a given group is in a group list** This routine is used to know if a module is already synchronized. If its* target or host module's group is in the synchronized group list there is* nothing to do.** RETURNS: a pointer on the GROUP_NODE found or NULL.** NOMANUAL*/GROUP_NODE * groupFind    (    DL_LIST *	pList,    UINT32	group,		/* module's group on host or target side */    FUNCPTR	findRtn		    )    {    GROUP_NODE *	pGroup;    pGroup = (GROUP_NODE *) dllEach (pList, findRtn, (int)group);    return (pGroup);    }/******************************************************************************** groupRemove - remove a group from a list** RETURNS: a pointer on the group node removed or NULL.** NOMANUAL*/GROUP_NODE * groupRemove    (    DL_LIST *	pList,    UINT32	group,    FUNCPTR	findRtn    )    {    GROUP_NODE *	pGroup = groupFind (pList, group, findRtn);    if (pGroup)	dllRemove (pList, (DL_NODE *)pGroup);    return (pGroup);    }/******************************************************************************** syncGroupUpdate - update <symSyncLst> with elements of <symSyncTmpLst>** <symSyncTmpLst> is used as a buffer to indicate when we are bringing* target symbols to host, that target module info were already synchronized* while symbols are not. When every symbols are synchronized then modules * of <symSyncTmpLst> can be considered as synchronized.** RETURNS: N/A.** NOMANUAL*/void syncGroupUpdate ()    {    GROUP_NODE *	pToAdd = (GROUP_NODE *) dllGet (&symSyncTmpLst);    while (pToAdd != NULL)	{	if (groupFind (&symSyncLst, pToAdd->tgtGroup, 			(FUNCPTR)isInTgtGroupList) == NULL)	    dllAdd (&symSyncLst, (DL_NODE *)pToAdd);	else 	    free (pToAdd);	pToAdd = (GROUP_NODE *) DLL_NEXT (pToAdd);	}    }/******************************************************************************** isInHostGroupList - check a given host group is in the list.** RETURNS: TRUE if we should examine next element, FALSE otherwise.** NOMANUAL*/BOOL isInHostGroupList    (    DL_NODE *	pNode,    int		arg    )    {    if (((GROUP_NODE *)pNode)->hostGroup == (UINT32)arg)	return (FALSE);    return (TRUE);    }/******************************************************************************** isInTgtGroupList - check a given target group is in the list.** RETURNS: TRUE if we should examine next element, FALSE otherwise.** NOMANUAL*/BOOL isInTgtGroupList    (    DL_NODE *	pNode,    int		arg    )    {    if (((GROUP_NODE *)pNode)->tgtGroup == arg)	return (FALSE);    return (TRUE);    }/* HOST ----> TARGET *//******************************************************************************** symSyncTgtUpdate - update target symbol table** This routine parses and dispatches the target events received.** RETURNS: OK or ERROR.** NOMANUAL*/STATUS symSyncTgtUpdate    (    HWTX	hWtx,		/* WTX API handle */    char *	evtString,	/* event received */    char *	doneEvt 	/* event sent when sync is done */    )    {    char *		evtType;    char *		info[3];    char *		pLast = NULL;		    STATUS		status = OK;    evtType = strtok_r (evtString, " ", &pLast);    if (strcmp (evtType, OBJ_LOADED_EVT) == 0)	{	/* get the host module Id from the event string */	info[0] = strtok_r (NULL, " ", &pLast);	/* module Id */	info[1] = strtok_r (NULL, " ", &pLast);	/* module name */	status = syncModCTgtUpdate (hWtx, H_STR_TO_L(info[0]));	}    else if (strcmp (evtType, OBJ_UNLOADED_EVT) == 0)	{	/* get the host module group from the event string */	info[0] = strtok_r (NULL, " ", &pLast); /* module id */	info[1] = strtok_r (NULL, " ", &pLast); /* module name */	info[2] = strtok_r (NULL, " ", &pLast); /* module group */	status = syncModDTgtUpdate (hWtx, H_STR_TO_L(info[2]));	}    else if (strcmp (evtType, SYM_ADDED_EVT) == 0)	{	info[1] = strtok_r (NULL, " ", &pLast);		/* symbol name */	status = syncSymAddTgtUpdate (hWtx, info[1]);	}    else if (strcmp (evtType, SYM_REMOVED_EVT) == 0)	{	info[1] = strtok_r (NULL, " ", &pLast);		/* symbol name */	info[0] = strtok_r (NULL, " ", &pLast);		/* symbol type */	status = symSRemove (sysSymTbl, info[1], H_STR_TO_L(info[0]));	}    else 	return (OK);    if (strlen (info[1]) > OBJ_NAME_MAX)	info[1][OBJ_NAME_MAX - 1] = '\0';    sprintf (doneEvt, "SYNC_DONE t %s %s %d", evtType, info[1], status);    return (status);    }/******************************************************************************** syncModCTgtUpdate - update target info when a module is created on host** RETURNS: OK or ERROR** NOMANUAL*/STATUS syncModCTgtUpdate    (    HWTX	hWtx,		/* WTX API handle */    UINT32	id		/* host module id */    )    {    WTX_MODULE_INFO *	pModInfo;	/* host module informations */    MODULE_ID		modId;		/* target module Id */    WTX_SYM_LIST *	pSymList;	/* symbols of the module */    WTX_SYMBOL	*	pSymInfo;    STATUS		status = OK;    /* Get the module info from the host and update target side */    if ((pModInfo = wtxObjModuleInfoGet (hWtx, id)) == NULL)	return (ERROR);    /* check if the module was previously synchronized */    if (groupFind (&symSyncLst, pModInfo->group, isInHostGroupList) != NULL)	{	wtxResultFree (hWtx, pModInfo);	return (OK);	}        /* create the new target module */    if ((modId = syncTgtModInfoFill (pModInfo)) == NULL)	{	wtxResultFree (hWtx, pModInfo);	return (ERROR);	}	    /* get symbols from the tgtsvr and add them in target symTbl */    if ((pSymList = wtxSymListGet (hWtx, NULL, pModInfo->moduleName,				   0, FALSE)) == NULL)	{	/* the module no longer exists on target */	moduleDelete (modId);	wtxResultFree (hWtx, pModInfo);	return (ERROR);	}    pSymInfo = pSymList->pSymbol;    while ((pSymInfo != NULL) && (status == OK))	{	status = symSAdd (sysSymTbl, pSymInfo->name, (char *)pSymInfo->value,			  pSymInfo->type, modId->group);	pSymInfo = pSymInfo->next;	}    /* update synchronized group list */    groupAdd (&symSyncLst, modId->group, pModInfo->group);	    wtxResultFree (hWtx, pSymList);    wtxResultFree (hWtx, pModInfo);    return (status);    }/******************************************************************************** syncModDTgtUpdate - update target info when a module is deleted on host** RETURNS: OK or ERROR** NOMANUAL*/STATUS syncModDTgtUpdate    (    HWTX	hWtx, 		/* WTX API handler */    UINT32	group		/* group (on host) of the deleted module */    )    {    STATUS	status = OK;    MODULE_ID		modId;		/* target module Id */    GROUP_NODE *	pGroup;		/* group node of the module */    /* remove the module from the synchronized group list */	    if ((pGroup = groupRemove (&symSyncLst, group, 			       (FUNCPTR)isInHostGroupList)) == NULL)	return (ERROR);    /* unload the module on target side */    if ((modId = moduleFindByGroup (pGroup->tgtGroup)) != NULL)	status = unldByModuleId (modId, UNLD_SYNC);    free (pGroup);#ifdef DEBUG    if (status == ERROR)	fprintf (stderr, "unload pb\n");#endif    return (status);    }/******************************************************************************** syncSymAddTgtUpdate - update target symbol table when a symbol is added** RETURNS: OK or ERROR** NOMANUAL*/STATUS syncSymAddTgtUpdate    (    HWTX	hWtx,		/* WTX API handle */    char *	symName		/* symbol name */    )    {    GROUP_NODE *	pGroup;		/* group node of the module */    WTX_SYMBOL *	pSymInfo;    UINT16 		tgtGroup;    STATUS 		status = OK;    if ((pSymInfo = wtxSymFind (hWtx, symName, 0, TRUE, 0, 0)) == NULL)	return (ERROR);	    /*      * get the corresponding target group      * the default group number (0) is the same on host and target     */    if ((tgtGroup = pSymInfo->group) != 0)	{	if ((pGroup = groupFind (&symSyncLst, pSymInfo->group,				 (FUNCPTR)isInHostGroupList)) == NULL)	    /* XXX ELP inexistant group set to 0 */	    tgtGroup = 0;		tgtGroup = pGroup->tgtGroup;	}    status = symSAdd (sysSymTbl, pSymInfo->name, (char *)pSymInfo->value,		      pSymInfo->type, tgtGroup);    wtxResultFree (hWtx, pSymInfo);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -