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

📄 eventlist.cpp

📁 SNMP++程序源码 for ll .8snmp++2_8.tar.Z 嵌入式linux环境下的SNMP开发代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*===================================================================  Copyright (c) 1999  Hewlett-Packard Company  ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.  Permission to use, copy, modify, distribute and/or sell this software  and/or its documentation is hereby granted without fee. User agrees  to display the above copyright notice and this license notice in all  copies of the software and any documentation of the software. User  agrees to assume all liability for the use of the software; Hewlett-Packard  makes no representations about the suitability of this software for any  purpose. It is provided "AS-IS without warranty of any kind,either express  or implied. User hereby grants a royalty-free license to any and all  derivatives based upon this software code base.      E V E N T L I S T . C P P      CEventList  CLASS DEFINITION      COPYRIGHT HEWLETT PACKARD COMPANY 1999      INFORMATION NETWORKS DIVISION      NETWORK MANAGEMENT SECTION      VERSION:        $Revision: 1.17 $      DESIGN:        Tom Murray      AUTHOR:        Tom Murray      DATE:        Sept 12, 1999      LANGUAGE:        ANSI C++      OPERATING SYSTEMS:        DOS/WINDOWS 3.1        BSD UNIX      DESCRIPTION:        Queue for holding all event sources (snmp messages, user        defined input sources, user defined timeouts, etc)      COMPILER DIRECTIVES:        UNIX - For UNIX build      CHANGE HISTORY:=====================================================================*/char event_list_version[]="$Header: eventlist.cpp,v 1.17 97/03/25 21:26:59 hmgr Exp $";extern "C" {#include <values.h>}// For debuggin cout's#include <iostream.h>//-----[ includes ]----------------------------------------------------//----[ snmp++ includes ]----------------------------------------------#include "eventlist.h"		// queue for holding all event sources#include "msgqueue.h"		// queue for holding snmp event sources#include "userdefined.h"        // queue for holding user defined event sources#include "usertimeout.h"        // queue for holding user defined timeouts#include "notifyqueue.h"	// queue for holding trap callbacks#include "msec.h"		// class for handling time in msecs//--------[ globals ]---------------------------------------------------CEventList eventList;		// holds all event sources#ifdef SNMPX11XtAppContext global_app_context = CONTEXT_NOT_SET;XtIntervalId global_interval_id = TIMER_NOT_SET;msec global_next_timeout;#endif // SNMPX11//--------[ forwards ]--------------------------------------------------//--------[ externs ]---------------------------------------------------#ifdef WU_APPextern "C" {#define PeekMessage PeekMessageA#define DispatchMessage DispatchMessageA// MS-Windows types neededtypedef int BOOL;typedef unsigned short WORD;typedef unsigned long DWORD;typedef void*  HWND;typedef unsigned int UINT;typedef UINT WPARAM;typedef long LPARAM;#define MAKELONG(a,b) ((long)(((WORD)(a))|((DWORD)((WORD)(b)))<<16))typedef struct tagPOINT{   long x;   long y;} POINT;WORD app_hinst;typedef struct tagMSG {   HWND hWnd;   UINT message;   WPARAM wParam;   LPARAM lParam;   DWORD time;   POINT pt;} MSG,*LPMSG;#define PM_NOREMOVE 0x0000#define PM_REMOVE 0x0001// prototypes for MS-Windows message pump callsBOOL PeekMessage( LPMSG lpMsg, HWND hWnd, UINT wMFMin, UINT wMFMAX, UINT wRMsg);BOOL TranslateMessage( const MSG *lpmsg);BOOL DispatchMessage( const MSG *lpmsg);}#endif//-------[ blocking MS-Windows Message Pump ]-------// Pumping messages allows other windows messages// to be processed.int yield_pump(){#ifdef WU_APP  MSG msg;  while ( PeekMessage( &msg,NULL,0,0,PM_NOREMOVE))  {    // else peek, xlate, and dispatch it    PeekMessage( &msg, NULL,0,0,PM_REMOVE);    if ( msg.message == SNMP_SHUTDOWN_MSG ) return SNMP_CLASS_SHUTDOWN;    TranslateMessage( &msg);    DispatchMessage( &msg);  }#endif//--------[ X Motif yield pump ]------------------------// yield for use with X motif only// no blocking yield implemented at this time#ifdef X_MOTIF#endif  return SNMP_CLASS_SUCCESS;}//---------[ Process Pending Events ]-------------------------------// Pull all available events out of their sockets - do not blockint SNMPProcessPendingEvents(){  int maxfds;  fd_set readfds;  fd_set writefds;  fd_set exceptfds;  int nfound = 0;  struct timeval fd_timeout;  msec now;  int status;  // do not allow select to block  fd_timeout.tv_sec = 0;  fd_timeout.tv_usec = 0;  do {    // Set up Select    eventList.GetFdSets(maxfds, readfds, writefds, exceptfds);#ifdef _XPG4_EXTENDED    nfound = select(maxfds, &readfds, &writefds, &exceptfds, &fd_timeout);#else // _XPG4_EXTENDED    nfound = select(maxfds, (int *)&readfds, (int *)&writefds,		    (int *)&exceptfds, &fd_timeout);#endif // _XPG4_EXTENDED    now.refresh();    if (nfound > 0) {      status = eventList.HandleEvents(maxfds, readfds, writefds, exceptfds);      // TM should we do anything with bad status?    } // found something on select  } while (nfound > 0);  // go through the message queue and resend any messages  // which are past the timeout.  status = eventList.DoRetries(now);  return status;}//---------[ Process Events ]------------------------------------------// Block until an event shows up - then handle the event(s)int SNMPProcessEvents(){  int maxfds;  fd_set readfds;  fd_set writefds;  fd_set exceptfds;  int nfound = 0;  struct timeval fd_timeout;  msec now;  msec sendTime;  int status = 0;  now.refresh();  eventList.GetNextTimeout(sendTime);  now.GetDelta(sendTime, fd_timeout);  eventList.GetFdSets(maxfds, readfds, writefds, exceptfds);#ifdef _XPG4_EXTENDED  nfound = select(maxfds, &readfds, &writefds, &exceptfds, &fd_timeout);#else // _XPG4_EXTENDED  nfound = select(maxfds, (int *)&readfds, (int *)&writefds,		    (int *)&exceptfds, &fd_timeout);#endif // _XPG4_EXTENDED  status = SNMPProcessPendingEvents();  return status;}//---------[ Main Loop ]------------------------------------------// Infinite loop which blocks when there is nothing to do and handles// any events as they occur.void SNMPMainLoop(){  do {    SNMPProcessEvents();  } while (!eventList.Done());}//---------[ Exit Main Loop ]---------------------------------------// Force the SNMP Main Loop to terminate immediatelyvoid SNMPExitMainLoop(){   eventList.SetDone();}//---------[ Block For Response ]-----------------------------------// Wait for the completion of an outstanding SNMP event (msg).// Handle any other events as they occur.int SNMPBlockForResponse(const unsigned long req_id, Pdu &pdu){  CSNMPMessage *msg;  int status;  // tell the msg queue we are looking for something  snmpEventList->PushId(req_id);  do {    yield_pump();     SNMPProcessPendingEvents();  } while (!snmpEventList->Done());  // reset the msg queue  snmpEventList->PopId();  msg = snmpEventList->GetEntry(req_id);  if (msg) {    // we found our response    msg->GetPdu(status, pdu);    // Dequeue the message    snmpEventList->DeleteEntry(req_id);    return  status;  }  else {    // not in the send queue...must have timed out    return SNMP_CLASS_TIMEOUT;  }}void SNMPGetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,		   fd_set &exceptfds){  eventList.GetFdSets(maxfds, readfds, writefds, exceptfds);}Uint32 SNMPGetNextTimeout(){  int status;  msec now, sendTime;//TM: This function used to have an argument of sendTime and//    would simply call eventList.GetNextTimeout(sendTime) and//    return the status.  However, to avoid exposing the msec//    class we now convert the msec to hundreths of seconds

⌨️ 快捷键说明

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