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

📄 rpccore.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 5 页
字号:
/* rpcCore.c - Remote Procedure Call (RPC) backend library *//* Copyright 1995-1998 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01o,24mar98,dbt  added support for WDB_CONTEXT_STATUS_GET service.01n,05mar98,c_c  Added bkendDsaEnable routine.01m,02mar98,pcn  WTX 2: finish to print the banner log file in rpcCoreInit.01l,21jan98,c_c  DLLized Target Server implementation.		 Removed EXT_FUNC refs.01k,22oct96,elp  replaced restartTargetServer setting by a call to TGT_RESTART()		 (SPR# 6943).01j,05jul96,p_m	 added tgtOps.tgtModeGetRtn init (SPR# 6200).01i,28jun96,c_s  just include <fcntl.h>; this is more portable.01h,14jun96,elp	 RPC_PROG_UNAVAILABLE means that target is connected to another		 tgtsvr (SPR# 4898). 01g,21mar96,pad  now rpcCoreClntCall() clears the evtPending flag when no more		 events are pending an rpcCoreEvtPendingClear() has been made		 a no-op routine (SPR #6203).01f,16jan96,elp  WIN32 DLL external functions are called through pointers.01e,04jan96,p_m  passed RPC error code to bkendLog() (SPR# 4629).		 added missing WIN32 history.		 cleanup rpcCoreModeSet().01d,09sep95,wmd  added call to RestartTargetServer() for WIN32.01c,01sep95,p_m  took care of MTU in rpcCoreVIOWrite() (SPR# 4778).01b,08jun95,tpr  added WDB_ERR_NO_AGENT_PROC error code, RPC_CANTDECODERES and		 RPC_CANTDECODEARGS in rpcCoreClntCall().		 reworked seqNumber and added getpid().01a,31may95,tpr	 derived from wdbrpc.c version 02k.*//*DESCRIPTIONThis file is a target server backend using the RPC mechanism to dialog witha WDB target agent. This backend is the default backend attached when the userstart the target server without specifying a backend. It's also attached whenthe target server is started with the option -a followed by "wdbrpc".The communication protocol used is UDP/IP. To increase the reliability of thisprotocol a simple mechanism of timeout and re-sending is implemented. When aservice is called a timer (implemented in the RPC client mechanism) isalso started. If the timeout arrived before the service has replied then therequest is re-sent. The number of time a same request can be re-sent is limited.When this limit is reached and the service call fails one more in timeout thelink is declared as broken. The default timeout value is handled by WDB_TIMEOUTbut this value can be changed by the user. He must start the target server withthe option -Bt followed by a number. This number is the timeout value to use(in second). The user can also modify the maxinum number of time that a samerequest can be re-sent. In this case the option -Br must be used. The default value of this option is handled by WDB_MAX_RESEND.The TCP/IP was not used because it requests timer. This feature is not alwaysavailable on all target boards. Moreover the implementation of this protocolrequer more memory space as the UDP protocol. As the WDB target agent mustbe the smallest possible the UDP protocol is the obligatory choise.This backend file handles all functions that a target serveur backend request.The diagram below gives the function link. The wdbRpcClntCall () isthe root function. It allows to call any WDB service and performs the linkreliability control as describe before. This function is called by 7 functions:5 are backend functions and 2 are internal to this backend. This 2 functions(wdbRpcCallRStatus() and wdbRpcCallStatus()) are used by the otherbackend functions that don't call wdbRpcClntCall() directly. They allow tocall a WDB service but this service must return either a RESULT_STATUS (forwdbRpcCallRStatus()) or a STATUS (for wdbRpcCallStatus()). rpcCoreMemChecksum               rpcCoreMemWrite               rpcCoreMemFill        |______________                  |______________________________|                       |                                |rpcCoreContextCreate   |                                |   rpcCoreMemWriteMany        |______________|                 |______________|_______________|                       |                                |rpcCoreVIOWrite        |      rpcCoreMemWriteManyInts   |    rpcCoreContextKill        |______________|                 |______________|_______________|                       |                                |rpcCoreEventpointAdd   |       rpcCoreContextSuspend    |  rpcCoreContextResume        |______________|                 |______________|_______________|                       |                                |rpcCoreFuncCall        |         rpcCoreContextCont     |    rpcCoreContextStep        |______________|                 |______________|_______________|                       |                                |rpcCoreDirectCall      |      rpcCoreEventpointDelete   |        rpcCoreRegsSet        |______________|                 |______________|_______________|                       |                                |                       |                                |               rpcCoreCallRStatus              rpcCoreCallStatus                       |________________________________|                                        |                                        |           rpcCoreGopherEval                                        |                    |rpcCoreTgtConnect     rpcCoreMemRead    |   rpcCoreRegsGet   |  rpcCoreVIORead        |_____________________|__________|__________|_________|_________|                                        |                                  rpcCoreClntCall*//* includes */#include <stdio.h>#include <netdb.h>#ifdef WIN32#include <process.h>#else#include <unistd.h>#endif#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <rpc/rpc.h>#include <sys/time.h>#include <fcntl.h>#include "tgtlib.h"#include "tgtsvr.h"#include "tssvcmgt.h"#include "host.h"#include "wdb.h"#include "wdbP.h"#include "wpwrutil.h"#include "bkendlib.h"#include "bkendlog.h"/* locals */LOCAL CLIENT *		pWdbClnt;		    /* target client */LOCAL xdrproc_t		lastOutProc;		    /* last xdr fct used */LOCAL char *		lastOutStruct;		    /* last struct received */LOCAL BOOL		evtPending;		    /* target evt pending */LOCAL u_int		maxNumResend;		    /* max nb of re-send */LOCAL u_int		defaultTimeout;		    /* default timeout */LOCAL u_int		rpcCoreMtu;		    /* max transfert unit */LOCAL BOOL		rpcCoreSvcAdded = FALSE;    /* WDB service added */LOCAL u_short		seqNumber;		    /* sequence number */LOCAL u_int		processId;		    /* tgt server process ID *//* forward declarations */LOCAL BOOL	dsaEnabled = FALSE;	/* dynamically scalable agent enable */LOCAL STATUS	(* pTsWdbKnownSvcAdd)(u_int);	/* pointer on the add routine */LOCAL UINT32	rpcCoreTgtConnect (WDB_TGT_INFO *);LOCAL UINT32	rpcCoreMemChecksum (WDB_MEM_REGION *, UINT32 *);LOCAL UINT32	rpcCoreMemRead (WDB_MEM_REGION *, WDB_MEM_XFER *);LOCAL UINT32	rpcCoreMemWrite (WDB_MEM_XFER *);LOCAL UINT32	rpcCoreMemFill (WDB_MEM_REGION *);LOCAL UINT32	rpcCoreMemProtect (WDB_MEM_REGION *);/* XXX TPRLOCAL UINT32	rpcCoreMemWriteMany (MANY_DATA *);LOCAL UINT32	rpcCoreMemWriteManyInts (MANY_INTS *);*/LOCAL UINT32	rpcCoreMemMove (WDB_MEM_REGION *);LOCAL UINT32	rpcCoreMemScan (WDB_MEM_SCAN_DESC *, TGT_ADDR_T *);LOCAL UINT32	rpcCoreCacheTextUpdate (WDB_MEM_REGION *);LOCAL UINT32	rpcCoreContextCreate (WDB_CTX_CREATE_DESC *, UINT32 *);LOCAL UINT32	rpcCoreContextKill (WDB_CTX *);LOCAL UINT32	rpcCoreContextSuspend (WDB_CTX *);LOCAL UINT32	rpcCoreContextResume (WDB_CTX *);LOCAL UINT32	rpcCoreContextCont (WDB_CTX *);LOCAL UINT32	rpcCoreContextStep (WDB_CTX_STEP_DESC *);LOCAL UINT32	rpcCoreRegsGet (WDB_REG_READ_DESC *, WDB_MEM_XFER *);LOCAL UINT32	rpcCoreRegsSet (WDB_REG_WRITE_DESC *);LOCAL UINT32	rpcCoreVIOWrite (WDB_MEM_XFER *, UINT32 *);LOCAL UINT32	rpcCoreEventpointAdd (WDB_EVTPT_ADD_DESC *, UINT32 *);LOCAL UINT32	rpcCoreEventpointDelete (WDB_EVTPT_DEL_DESC *);LOCAL UINT32	rpcCoreModeSet (u_int *);LOCAL UINT32	rpcCoreModeGet (u_int *);LOCAL UINT32	rpcCoreEventGet (WDB_EVT_DATA *);LOCAL UINT32	rpcCoreFuncCall (WDB_CTX_CREATE_DESC *, UINT32 *);LOCAL UINT32	rpcCoreDirectCall (WDB_CTX_CREATE_DESC *, UINT32 *);LOCAL UINT32	rpcCoreGopherEval (WDB_STRING_T *, WDB_MEM_XFER *);LOCAL BOOL  	rpcCoreEvtPending (void);LOCAL void  	rpcCoreEvtPendingClear (void);LOCAL UINT32	rpcCoreClntCall (u_long, xdrproc_t, char *,					xdrproc_t, char *);LOCAL BOOL	rpcCoreFreeResultArgs (void);LOCAL UINT32	rpcCoreTgtDisconnect (void);LOCAL UINT32	rpcCoreContextStatusGet (WDB_CTX * pWdbContext,						    UINT32 * pCtxStatus);/********************************************************************************* bkendDsaEnable - enable the Dynamic scalable Agent** this routine enables the dsa capability and gives the routine to use to* add a service into the target server list.**/void bkendDsaEnable    (    STATUS	(* svcAddRtn)(u_int)    )    {    dsaEnabled = TRUE;    pTsWdbKnownSvcAdd = svcAddRtn;    }/********************************************************************************* rpcCoreInit - initialize the rpc core interface** This function is called by the target server when it wants to attach this* backend. Five input arguments are accepted:* <tgtName> is a pointer to a string that handles either the name or the* internet address (in dotted-decimal * format) of the target board. ** <logName> is a pointer to a string that handles the file name to log the WDB* request. If this pointer is the NULL pointer no log are requested. The log* file name is given by the user when the target server is started with the* option -Bd.** <timeout> is the time out duration to use for the communication with the* WDB target agent. This input argument is set when the target server is* started with the option -Bt. Otherwise set to zero.** <recallNum> is the maximun number of time that a request is re-sent before* to admit the communication link is broken. Set when the target server is* started with the option -Br, otherwise reset to zero.** <pTgtOps> is a pointer to TGT_OPS structure (defines in tgtlib.h file).* This structure handles function pointers used by the target server to call* a backend function. The backend attachment is performed by filling this* structure with the backend function address. ** This function initializes the backend. It creates the backend client, resets* the udp datagram sequence number and fills the TGT_OPS structure with* the information describing the backend and returns a pointer to this * structure.** CAVEAT: its name is built from the file name concatenated with the string*         "Init". This is compulsory.* * RETURNS: TRUE if the backend is properly initialized, otherwise FALSE.*/STATUS rpcCoreInit    (    CLIENT *	pClnt,		/* backend client pointer */    u_int	timeout,	/* the default timeout value in second */    u_int	recallNum,	/* nb of time a request is send before timeout*/    TGT_OPS *	pTgtOps		/* backend function */    )    {    /* Finish to print the banner in the log file (procNum = 0) */     bkendLog (0, timeout, NULL, 0, 0, (int) recallNum);     /* save the CLIENT structure pointer */    pWdbClnt = pClnt;    /*     * set the time out value to either the default value or the value     * given by the user if the target server is started with the option -Bt.     */    defaultTimeout = timeout;    /*     * set the maximun number of time that a request will be re-sent before     * to consider the link is broken. The value set is either the     * default value or the value given by the user when the target server is     * started with the option -Br.     */    maxNumResend = recallNum;    /* reset the sequence number */    seqNumber = 0;    /* get process id */#ifndef WIN32    processId = getpid () << 16;#else    processId = _getpid () << 16;#endif /* WIN32 */    /* signal the target agent is not connected yet */     pTgtOps->tgtConnected = FALSE;    /* reset the target event pending flag */    evtPending = FALSE;    /*     * get the file descriptor of the client socket. This socket file desciptor     * will be used by the WDB target agent to wake up the target server in     * order to notify event detections. A message with 1 Byte is sent by the     * WDB target agent.     */    pTgtOps->tgtEventFd			= * (int *) pWdbClnt->cl_private;    /*     * fill the TGT_OPS structure with the backend functions available.     * When this function is called the target server fills the <pTgtOps>     * input parameter with the address of a TGT_OPS structure. This     * structure is used by the target server to call a function in this     * backend.     */    pTgtOps->tgtConnectRtn		= rpcCoreTgtConnect;    pTgtOps->tgtDisconnectRtn		= rpcCoreTgtDisconnect;    pTgtOps->tgtModeSetRtn		= rpcCoreModeSet;    pTgtOps->tgtModeGetRtn		= rpcCoreModeGet;    pTgtOps->freeResultArgsRtn		= rpcCoreFreeResultArgs;    pTgtOps->memChecksumRtn		= rpcCoreMemChecksum;    pTgtOps->memReadRtn			= rpcCoreMemRead;    pTgtOps->memWriteRtn		= rpcCoreMemWrite;    pTgtOps->memFillRtn			= rpcCoreMemFill;    pTgtOps->memProtectRtn		= rpcCoreMemProtect;#if 0 /* XXX Tpr to remove when available */    pTgtOps->memWriteManyRtn		= rpcCoreMemWriteMany;    pTgtOps->memWriteManyIntsRtn	= rpcCoreMemWriteManyInts;#endif     pTgtOps->memTxtUpdateRtn		= rpcCoreCacheTextUpdate;    pTgtOps->memMoveRtn			= rpcCoreMemMove;    pTgtOps->memScanRtn			= rpcCoreMemScan;    pTgtOps->contextCreateRtn		= rpcCoreContextCreate;    pTgtOps->contextKillRtn		= rpcCoreContextKill;    pTgtOps->contextSuspendRtn		= rpcCoreContextSuspend;    pTgtOps->contextResumeRtn		= rpcCoreContextResume;    pTgtOps->regsGetRtn			= rpcCoreRegsGet;    pTgtOps->regsSetRtn			= rpcCoreRegsSet;    pTgtOps->vioWriteRtn		= rpcCoreVIOWrite;    pTgtOps->evtptAddRtn		= rpcCoreEventpointAdd;    pTgtOps->evtptDeleteRtn		= rpcCoreEventpointDelete;    pTgtOps->eventGetRtn		= rpcCoreEventGet;    pTgtOps->contextContRtn		= rpcCoreContextCont;    pTgtOps->contextStepRtn		= rpcCoreContextStep;    pTgtOps->funcCallRtn		= rpcCoreFuncCall;    pTgtOps->directCallRtn		= rpcCoreDirectCall;    pTgtOps->gopherEvalRtn		= rpcCoreGopherEval;    pTgtOps->bkendEvtPendingRtn		= rpcCoreEvtPending;    pTgtOps->bkendEvtPendingClearRtn	= rpcCoreEvtPendingClear;    pTgtOps->contextStatusGetRtn	= rpcCoreContextStatusGet;    return (OK);    }/********************************************************************************* rpcCoreTgtConnect - connect the target agent** This function is called by the target server when the backend attachment has * succeeded. By asking the WDB_TARGET_CONNECT service via the backend client,* this function performs the targer agent connection. The TGT_INFO structure* returned (defined in the wdbtypes.h file) handles target board information* (cpu, memory size, ...).* * If the WDB_TARGET_CONNECT service or the RPC request fails the errCode field* of the TGT_INFO structure returned will handle the error number.* * RETURNS: Always a pointer to a TGT_INFO structure.*/LOCAL UINT32 rpcCoreTgtConnect    (

⌨️ 快捷键说明

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