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

📄 main.h

📁 基于UNIX的中间件编程,只能运行于UNIX操作系统
💻 H
字号:
/**********************************************************main.h:the main header file		zhoushijie		2000/3/9**********************************************************/#include <pthread.h>#include "include.h"#include "queue.h"#include "shm.h"/*--------------------------------------------  define the log level constant--------------------------------------------*/#define L_Initialize		00#define L_Info				10#define L_System			11#define L_Error				12#define L_Warning			13#define L_Debug				14#define L_Unknown			15#define L_Success			16#define L_End				17/*--------------------------------------------  define the operation code constant--------------------------------------------*/#define Add_Entry_Record	000001#define Add_Exit_Record		000002#define Add_Shift_Record	000003#define Add_Device_Record	000004#define Get_Network_Status	000005#define Define_User_Info	000006#define Ic_Query			000007/*--------------------------------------------  define the networking status constant--------------------------------------------*/#define Network_On			1#define Network_Off			0/*--------------------------------------------  define the transmition type constant--------------------------------------------*/#define Flag_File_Transmit		0#define Flag_Message_Transmit	1/*-------------------------------------------------------------------define the max QUEUE LENGTH ------used to init the messagestructure-------------------------------------------------------------------*/#define MAXRECORD 500/*----------------------------------------------define the max client count----------------------------------------------*/#define MAXCLIENTCOUNT 100/*--------------------------------define the ini file and log file--------------------------------*/#ifndef LOGFILE#define LOGFILE "log.txt"#endif#ifndef PROCESSINIFILE#define PROCESSINIFILE "process.ini"#endif#define PROCESSKINDNUM	10#define MAXPROCESSNUM	100#ifndef SOCKET#define SOCKET int#endif#ifndef INIFILE#define INIFILE "NnDev.ini"#endif/*--------------------------------------define the default protocol name-------------------------------------*/#define DEFAULT_PROTO SOCK_DGRAMtypedef struct{	char UserID[6];	char PassWord[9];	char IP[16];	int LocalLevef;		unsigned short MYMAINPORT;	unsigned short MYSECONDPORT;	unsigned short APPPORT;}LOCALHOSTINFO;/*------------------------------------------------------the thread structure------------------------------------------------------*/typedef struct ThreadStructure{	char Name[20];	unsigned long TID;	char Status[10];}THREADSTRUCTURE;/*------------------------------------------------------the process structure------------------------------------------------------*/typedef struct ProcessStructure{	char Name[20];	unsigned long PID;	char Status[10];}PROCESSSTRUCTURE;typedef struct {	char Testtype[4];	char Date[9];		char Time[7];		char Legal;	#define M_OK 0#define M_FAIL 1}TestPacket;typedef struct{	LOCALHOSTINFO node;	int status;#define M_CONNED 0#define M_CLOSED 1	int type;#define M_LOCAL 0#define M_PARENT 1#define M_CHILD 2	int Duration;} NODE;/*------------------------------------------- log record data structure-------------------------------------------*/typedef struct{	int		log_level;	char	PackType[5];	char	log_date[11];	char	log_time[9];	char	log_event[50];	char	log_cause[150];} WSLOGDATA;typedef struct{	int RemoteID;	int RemoteLevef;	char RemoteIP[126];	unsigned short RemotePort;	unsigned short Rem_testPort;} RemoteName;typedef struct {	int RemoteID;	int RemoteLevef;	int RemoteStatus;}TestResult;/*-----------------------------------------------------define the max sn structure-----------------------------------------------------*/typedef struct{	char Destination[30];	long MaxSN;}MAXSN;/*-----------------------------------------------------define the max try count of sending to set MAXSN to 0-----------------------------------------------------*/#define TRYCOUNT 10/*------------------------------------------the return value of the application-------------------------------------------*/typedef struct {	int flag;	int partionnumbers;		char packettype[3];	char  ID[11];	char requesttype[3];	char oprcode[6];	int socketno;			char  source[30];	char  destination[30];		unsigned int appport;	char  middledest[30];	int breakof;	char preserve[200];	int errorno;	char errorcause[150];	int timer;}TID;/*#define PDULEN	sizeof(PDUPacket)#define M_DATALENG			128typedef struct 			{	char PDUType[5];#define N_PDU_REQ			"0200" #define N_PDU_REP			"0210" #define N_PDU_CON			"0220"#define F_PDU_REQ			"0400"#define F_PDU_REP			"0410"#define F_PDU_CON			"0420"#define M_PDU_REQ			"0800"#define M_PDU_REP			"0810"#define M_PDU_CON			"0820"	int PDULen;	UINT sn; 	LOCALHOSTINFO src;	LOCALHOSTINFO transient;	LOCALHOSTINFO dest;	char buff[M_DATALENG];}PDUPacket;*//*---------------------------------------  declare the functions---------------------------------------*/int InitOutputSharedMem();int InitInputSharedMem();char *WriteOutputSharedMem(int PartionNumber,char *content);char *ReadInputSharedMem(int PartionNumber);char *ReadOutputSharedMem(int PartionNumber);char *WriteInputSharedMem(int PartionNumber,char *content);int sm_SendNotWait(SOCKET Ssock,SOCKET Qsock,char * buf, struct sockaddr_in from,int from_len,struct sockaddr_in to,int to_len,int PacketType);int sm_SendWait(SOCKET Ssock,SOCKET Qsock,char *buf,struct sockaddr_in from,int from_len,struct sockaddr_in to,int to_len,int PacketType);void *SM_LocalThread(void * arg);char *FormateManageMsg(char *packettype,char *requesttype,char *buf);int SendSetMaxSNMessage(SOCKET Ssock,struct sockaddr_in fsin,int alen);int SetMaxSN(MAXSN  SN[],long MaxClientCount,char *source,long sn);char *SeparateHostName(char *string,char *sepstring,char returnstring[]);int InsertQueue(Queue *Sourceq,Queue *Destq,MESSAGESTRUCTURE m_struct[],int RecordCount);int InitUsedQueueFromDB(Queue *q,int count);void RecordThreadStatus(THREADSTRUCTURE Tread[],int i,char *name,char *status,unsigned long TID);void VisitQueueNode(QueueEntry entry);int InitMessageQueue();int SendClearQueueMsg(SOCKET sock,struct sockaddr_in fsin,int alen,char *buf);int  CallApplication(MESSAGESTRUCTURE m_struct);int IsMaxSN(MAXSN MaxSN[],long MaxClientCount ,char *source ,char *sn );int AddMaxSN(MAXSN SN[], long MaxClientCount,char *source,long sn);char *FormateHostName(char destination[],char *host);int  FormatePacket(MESSAGESTRUCTURE m_struct,char *msg);void *QueueThread(void *arg);void *LocalThread(void * arg);void *NetworkThread(void *arg);int SendNotWait(SOCKET Msock,SOCKET Ssock,SOCKET Qsock,char * buf, struct sockaddr_in from,int from_len,struct sockaddr_in to,int to_len,int PacketType);int SendWait(SOCKET Msock,SOCKET Ssock,SOCKET Qsock,char *buf,struct sockaddr_in from,int from_len,struct sockaddr_in to,int to_len,int PacketType);int  SeparatePacket(char *buf,MESSAGESTRUCTURE *m_struct);WSLOGDATA SetLogContent(int Log_Level,char *Log_Envent,char *Log_Cause);char *Readprofile(char *m_file,char m_section[],char m_key[]);int  Writeprofile(char *m_file,char m_section[],char m_key[],char m_keyvalue[]);int writeLog(WSLOGDATA *);int Init();void replacechar(char *m_sourstr,int m_reschar,int m_deschar);void FormateTestPacket(char *,char *);unsigned long GetRecordID(void);int ReceiveMsg(SOCKET insock, char *Buffer,int size,struct sockaddr_in *m_from,int* m_fromlen);int SendMsg(SOCKET outsock, char *Buffer,int size,struct sockaddr_in m_from,int m_fromlen);int WriteMessage(SOCKET outsock, char *Buffer,int size,struct sockaddr_in m_from,int m_fromlen);int InitProcessData(char *filename,int ProcessNum[],char ProcessName[][100]);int ReadAndEcho(SOCKET insock, char *Buffer,int size,struct sockaddr_in *m_from,int *m_fromlen);struct tm * getlocaldatetime(void);void SetTime(char * m_centertime);void cmp_time(char *mz_buffer);void *Timer(void *);void itoa(int num,char *str,int method);DWORD GetTickCount();/*-------------------------------------------Following is the API declare-------------------------------------------*/ TID OpenConn(char *dest,char *oprcode); TID CloseConn(char *dest,char *oprcode,SOCKET sock); TID SendMesaseg(int flag,char *buf,int bussize,char *filename); TID RecieveMessaeg(int flag,char *buf,int bufsize,char *filename); TID CallMessaeg(int flag,char *sbuf,int sbufsize,char *sfilename,char *rbuf,int rbufsize,char *rfilename); /*-----------------------------------------------------define the global variables-----------------------------------------------------*//*the timer packet */TestPacket m_testpac;/*the remote server or client information*/RemoteName remote_ser[4];/*the local host information*/LOCALHOSTINFO myname;TestResult ser_testres[4];NODE mynode1;struct sockaddr_in dest_addr;int beginrate=0;char m_content[500];int m_repeat=0;/*the application's transaction ID*/long TransactionID;/*the queue thread socket number*/char QueueMsg[20];/*the app socket number*/char AppSocket[20];/*the current network status,1--on,0--down*/int NetworkStatus;/*the queue thread sleep time values */int SleepTimeValue;/*the timer thread sleep time values*/int TimerSleepTimeValue;/*the source's maximum request No stored on the server*/MAXSN MaxSN[MAXCLIENTCOUNT];/*the data structure between middleware and middleware*/MESSAGESTRUCTURE m_struct;/*THE  FREEQUEUE*/Queue FREEQUEUE;/*THE USEDQUEUE*/Queue USEDQUEUE;/*the queue thread socket */SOCKET QueueSock;/*the thread structure*/THREADSTRUCTURE Tread[5];/*the local database's table name*/char m_tablename[15];/*/the max queue lenght*/int MAXQUEUELEN;/*-------------------------------------------------------the partion index description table-------------------------------------------------------*/struct sm_Index O_Index,I_Index;/*------------------------------------------------------the block description table------------------------------------------------------*/struct sm_Block O_Block[O_PARTIONNUMBERS+1][O_MAXBLOCKS+1];struct sm_Block I_Block[I_PARTIONNUMBERS+1][I_MAXBLOCKS+1];/*----------------------------------------------------the global mapping file handle---------------------------------------------------*/HANDLE O_MapHandle,I_MapHandle;/*------------------------------------------------------the mapping file start address------------------------------------------------------*/char *O_StartAddress,*I_StartAddress;/*------------------------------------------------------the 0 block of the mapping file address------------------------------------------------------*/char *O_SuperNode,*I_SuperNode;/*------------------------------------------------------the start address of every block------------------------------------------------------*/char *O_Pointer[O_PARTIONNUMBERS],*I_Pointer[I_PARTIONNUMBERS];HANDLE O_SemaphoreHandle[O_PARTIONS],I_SemaphoreHandle[I_PARTIONS];

⌨️ 快捷键说明

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