📄 distnetlib.c
字号:
/* distNetLib - distributed objects network layer (VxFusion option) *//* Copyright 1999 - 2002 Wind River Systems, Inc. *//*modification history--------------------01k,18apr02,jws fix SPR74878 (not lock node database properly)01j,23oct01,jws fix compiler warnings (SPR 71117)01i,04oct01,jws final fixes for SPR 3477001h,27sep01,p_r Fixes for SPR#3477001g,24may99,drm added vxfusion prefix to VxFusion related includes01f,23feb99,drm library documentation update01e,22feb99,drm added documentation for library and distNetInput() function01d,12aug98,drm added #include stmt for distObjTypeP.h01c,08aug98,drm added code to set broadcast flag when sending broadcast msgs01b,20may98,drm removed some warning messages by initializing pointers to NULL01a,05sep97,ur written.*//*DESCRIPTIONThis library contains the distributed objects network layer. The network layerputs messages into telegram buffers and reassembles them from telegram buffers. When a message exceeds the space allocated for message data in a telegram, the network layer fragments the message into multiple telegram buffers, and reassembles a single message from multiple telegram buffers. After placing a message into a telegram buffer(s), this layer calls theadapter's send routine and sends a telegram out over thetransport. If the message has to be fragmented into more than one telegram buffer, the adapter send routine is called once for each buffer used.Upon receiving a telegram from a remote node, an adapter must call thislibrary's distNetInput() routine to forward a telegram buffer to VxFusion.AVAILABILITYThis module is distributed as a component of the unbundled distributedmessage queues option, VxFusion.INCLUDE FILES: distNetLib.hSEE ALSO: distIfLib*/#include "vxWorks.h"#if defined (DIST_NET_REPORT) || defined (DIST_DIAGNOSTIC)#include "stdio.h"#endif#include "errnoLib.h"#include "string.h"#include "taskLib.h"#include "semLib.h"#include "netinet/in.h"#include "private/semLibP.h"#include "private/distObjTypeP.h"#include "vxfusion/distLib.h"#include "vxfusion/distIfLib.h"#include "vxfusion/distStatLib.h"#include "vxfusion/private/distNetLibP.h"#include "vxfusion/private/distNodeLibP.h"#include "vxfusion/private/distTBufLibP.h"#include "vxfusion/private/distPktLibP.h"/* defines */#ifndef MAX#define MAX(a, b) (((a) < (b)) ? (b) : (a))#endif#ifndef MIN#define MIN(a, b) (((a) > (b)) ? (b) : (a))#endifDIST_SERV_NODE servTable[DIST_SERV_MAX];/* locals */LOCAL BOOL distNetLibInstalled = FALSE;LOCAL FUNCPTR distNetServiceHook = NULL;/* local prototypes */LOCAL void distNetServTask (DIST_SERV_FUNC servInput, DIST_SERV_NODE *servNode);LOCAL STATUS distNetServCall (int servId, DIST_TBUF_HDR *pDeliver);/***************************************************************************** distNetLibInit - initialize this module (VxFusion option)** This routine currently does nothing.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: N/A* NOMANUAL*/void distNetLibInit (void) { }/***************************************************************************** distNetInit - initialize server table (VxFusion option)** This routine initializes the server table.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: N/A* NOMANUAL*/void distNetInit (void) { int i; bzero ((char *) &servTable[0], sizeof(servTable)); for (i = 0; i < DIST_SERV_MAX; i++) { servTable[i].servTaskPrio = servTable[i].servNetPrio = (-1); } distNetLibInstalled = TRUE; }/***************************************************************************** distNetServAdd - add a service (VxFusion option)** This routine adds a service to the server table and spawns a task to* implement the service.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: OK, if successful.* NOMANUAL*/STATUS distNetServAdd ( int servId, /* id of service to add */ DIST_SERV_FUNC servInput, /* service input function to call */ char * servTaskName, /* name of service task */ int servNetPrio, /* priority of service on the network */ int servTaskPrio, /* priority of service task */ int servTaskStackSz /* stack size for service task */ ) { DIST_SERV_NODE *pServNode = (DIST_SERV_NODE *) &servTable[servId]; int taskPrio; int tid; if (!distNetLibInstalled || servId < 0 || servId > DIST_SERV_MAX - 1) return (ERROR); semBInit (&pServNode->servQLock, SEM_Q_FIFO, SEM_FULL); semBInit (&pServNode->servWait4Jobs, SEM_Q_FIFO, SEM_EMPTY); pServNode->servId = servId; pServNode->servUp = FALSE; pServNode->pServQ = NULL; if (pServNode->servTaskPrio == -1) pServNode->servTaskPrio = servTaskPrio; if (pServNode->servNetPrio == -1) pServNode->servNetPrio = servNetPrio; taskPrio = pServNode->servTaskPrio; tid = taskSpawn (servTaskName, taskPrio, VX_SUPERVISOR_MODE | VX_UNBREAKABLE, servTaskStackSz, (FUNCPTR) distNetServTask, (int) servInput, (int) pServNode, 0, 0, 0, 0, 0, 0, 0, 0); if (tid == ERROR) return (ERROR); pServNode->servTaskId = tid; return (OK); }/***************************************************************************** distNetServTask - service task (VxFusion option)** This is the common entry point for all network service tasks. It* calls the individual service functions.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: N/A* NOMANUAL*/LOCAL void distNetServTask ( DIST_SERV_FUNC servInput, /* function to process input */ DIST_SERV_NODE * pServNode /* server node */ ) { DIST_TBUF_HDR * pDeliver; DIST_NODE_ID nodeSrcId; DIST_STATUS dStatus; FOREVER { semTake (&pServNode->servWait4Jobs, WAIT_FOREVER); while (pServNode->pServQ) { semTake (&pServNode->servQLock, WAIT_FOREVER); DIST_TBUF_HDR_DEQUEUE (pServNode->pServQ, pDeliver); semGive (&pServNode->servQLock); nodeSrcId = pDeliver->tBufHdrSrc; if ((dStatus = servInput (nodeSrcId, pDeliver)) != OK) {#ifdef DIST_NET_REPORT printf ("distNetServTask/#%d: service task returned %d\n", pServNode->servId, dStatus);#endif if (distNetServiceHook) (* distNetServiceHook) (pServNode->servId, dStatus); } /* locking probably not required, but doesn't cost much */ distNodeDbLock (); DIST_TBUF_FREEM (pDeliver); distNodeDbUnlock (); } } }/***************************************************************************** distNetServConfig - configure service (VxFusion option)** This routine is used to change a service's task and network priority.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: OK, if successful.* NOMANUAL*/STATUS distNetServConfig ( int servId, /* ID of service to configure */ int taskPrio, /* new task priority */ int netPrio /* new network priority */ ) { DIST_SERV_NODE * pServNode = (DIST_SERV_NODE *) &servTable[servId]; if (servId >= 0 && servId < DIST_SERV_MAX) { if (netPrio != -1) { if (netPrio < 0 || netPrio > 7) return (ERROR); pServNode->servNetPrio = netPrio; } if (taskPrio != -1) { if (taskPrio < 0 || taskPrio > 255) return (ERROR); pServNode->servTaskPrio = taskPrio; if (DIST_NET_SERV_INST (servId)) return (taskPrioritySet (pServNode->servTaskId, taskPrio)); } return (OK); } return (ERROR); }/***************************************************************************** distNetServUp - change state of service to up (VxFusion option)** This routine marks to state of a service as UP.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: ERROR, if no such service exists.* NOMANUAL*/STATUS distNetServUp ( int servId /* ID of service */ ) { DIST_SERV_NODE * pServNode; if (servId >= 0 && servId < DIST_SERV_MAX && DIST_NET_SERV_INST (servId)) { pServNode = (DIST_SERV_NODE *) &servTable[servId]; pServNode->servUp = TRUE; return (OK); } return (ERROR); }/***************************************************************************** distNetServDown - change state of service to down (VxFusion option)** This routine changes the state of a service to DOWN.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: ERROR, if no such service exists.* NOMANUAL*/STATUS distNetServDown ( int servId /* ID of service */ ) { DIST_SERV_NODE * pServNode; if (servId >= 0 && servId < DIST_SERV_MAX && DIST_NET_SERV_INST (servId)) { pServNode = (DIST_SERV_NODE *) &servTable[servId]; pServNode->servUp = FALSE; return (OK); } return (ERROR); }/***************************************************************************** distNetServCall - call a service with an incoming packet (VxFusion option)** This routine passes incoming data to a service.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: OK, if successful.* NOMANUAL*/LOCAL STATUS distNetServCall ( int servId, /* ID of service */ DIST_TBUF_HDR * pDeliver /* the message */ ) { DIST_SERV_NODE * pServNode; if (servId >= 0 && servId < DIST_SERV_MAX && DIST_NET_SERV_INST (servId)) { pServNode = (DIST_SERV_NODE *) &servTable[servId]; /* * Although the service is not up yet, we return OK and * force an acknowledge for the packet. We have to keep
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -