博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++之测试snmp的注册模块
阅读量:4025 次
发布时间:2019-05-24

本文共 9254 字,大约阅读时间需要 30 分钟。

## main.cpp

#include 
#include
#include
#include "dssx_helper.h"#include "typedef.h"#include "oidManager.h"RET_CODE GET_PARAM_STRING(UINT32 uiParamId, STRING paramVal){ cout << __FUNCTION__ << endl; OidManager * pManager = OidManager::getInstance(); pManager->getString(uiParamId,paramVal); cout << "\n" << endl; return RC_SUCCESS;}RET_CODE SET_PARAM_STRING(UINT32 uiParamId, STRING paramVal){ cout << __FUNCTION__ << endl; OidManager * pManager = OidManager::getInstance(); pManager->setString(uiParamId,paramVal); cout << "\n" << endl; return RC_SUCCESS;}RET_CODE GET_PARAM_UINT32(UINT32 uiParamId, UINT32 *uiParamVal){ cout << __FUNCTION__ << endl; OidManager * pManager = OidManager::getInstance(); pManager->getUint32(uiParamId,uiParamVal); cout << "\n" << endl; return RC_SUCCESS;}RET_CODE SET_PARAM_UINT32(UINT32 uiParamId, UINT32 uiParamVal){ cout << __FUNCTION__ << endl; OidManager * pManager = OidManager::getInstance(); pManager->setUint32(uiParamId,uiParamVal); cout << "\n" << endl; return RC_SUCCESS;}RET_CODE GET_PARAM_INT32(UINT32 uiParamId, INT32 *iParamVal){ cout << __FUNCTION__ << endl; OidManager * pManager = OidManager::getInstance(); pManager->getInt32(uiParamId,iParamVal); cout << "\n" << endl; return RC_SUCCESS;}RET_CODE SET_PARAM_INT32(UINT32 uiParamId, INT32 iParamVal){ cout << __FUNCTION__ << endl; OidManager * pManager = OidManager::getInstance(); pManager->setInt32(uiParamId,iParamVal); cout << "\n" << endl; return RC_SUCCESS;}int main(int argc,char **argv){ if (argc < 2){ cout << __FUNCTION__ << "::\t" << "Usage: ./command modulename" << endl; return 0; } string fname = string(argv[1]) + ".txt"; OidManager::getInstance()->loadOidFile(fname.c_str()); DSSX_INIT(argv[1]); DSSX_REG_PARAM_STRING_CALLBACK(GET_PARAM_STRING,SET_PARAM_STRING); DSSX_REG_PARAM_UINT32_CALLBACK(GET_PARAM_UINT32,SET_PARAM_UINT32); DSSX_REG_PARAM_INT32_CALLBACK(GET_PARAM_INT32,SET_PARAM_INT32); while(1){ sleep(1); } return 0;}

## oidManager.h

#ifndef OID_MANAGER_H#define OID_MANAGER_H#include 
#include
#include "typedef.h"using namespace std;class Node{public: Node(string _req,string _type,string _id,string _val,string _comment){ req = _req; type = _type; id = _id; val = _val; comment = _comment; } string req; string type; string id; string val; string comment;};class OidManager{public: static OidManager * getInstance(); bool loadOidFile(const string & fname); /*getString & setString*/ bool getString(UINT32 paramId ,STRING val); bool setString(UINT32 paramId ,STRING val); /*getUin32 & setUint32*/ bool getUint32(UINT32 paramId ,UINT32 *uiParamVal); bool setUint32(UINT32 paramId ,UINT32 uiParamVal); /*Int32*/ bool getInt32(UINT32 paramId ,INT32 *iParamVal); bool setInt32(UINT32 paramId ,INT32 Val);private: OidManager(){ m_isLoaded = false; m_nodeList.clear(); } ~OidManager(){ } Node parseBuffeToNode(const char * buffer);private: bool m_isLoaded; vector
m_nodeList;};#endif

## oidManager.cpp

#include "oidManager.h"#include 
#include
#include
#include
#include
#include
using namespace std;string toString(int n){ strstream m; m<
>s; return s;}int toINT(string str){ strstream m; m<
>n; return n;}static OidManager * g_instance = NULL;/******************************************************************************/OidManager * OidManager::getInstance(){ if (g_instance == NULL) g_instance = new OidManager(); return g_instance;}/******************************************************************************/bool OidManager::loadOidFile(const string & fname){ if (m_isLoaded){ cout << __FUNCTION__ << "::\t" << "oid config file is loaded." << endl; return true; } FILE * fp = fopen(fname.c_str(),"r"); if ( fp == NULL){ cout << __FUNCTION__ << "::\t" << "fopen() failed ,please make sure " << fname << "exist" << endl; return false; } char buffer[100]; while(true){ memset(buffer,'\0',sizeof(buffer)); char * ret = fgets(buffer, sizeof(buffer), fp); if (ret == NULL){ cout << __FUNCTION__ << "::\t" << "fgets() read eof." << endl; break; } Node node = parseBuffeToNode(buffer); m_nodeList.push_back(node); } fclose(fp);}Node OidManager::parseBuffeToNode(const char * buffer){ char req[10], type[10], id[10], val[20], comment[20]; memset(req, '\0',10); memset(type,'\0',10); memset(id, '\0',10); memset(val, '\0',20); memset(comment, '\0',20); cout << buffer << endl; sscanf(buffer,"%s\t%s\t%s\t%s\t%s",req,type,id,val,comment);#ifdef DDEBUG cout << __FUNCTION__ << "::\t" << "Parsed Commont <" << req << ">" << endl; cout << __FUNCTION__ << "::\t" << "Parsed Commont <" << type << ">" << endl; cout << __FUNCTION__ << "::\t" << "Parsed Commont <" << id << ">" << endl; cout << __FUNCTION__ << "::\t" << "Parsed Commont <" << val << ">" << endl; cout << __FUNCTION__ << "::\t" << "Parsed Commont <" << comment << ">" << endl;#endif return Node(string(req),string(type),string(id),string(val),string(comment));}/******************************************************************************//*getString & setString*/bool OidManager::getString(UINT32 paramId ,STRING val){ vector
::iterator pIterator = m_nodeList.begin(); for (pIterator; pIterator != m_nodeList.end(); pIterator++){ if ( pIterator->req == "get" && pIterator->type == "string"){ if ( toString(paramId) == pIterator->id){ strcpy(val, pIterator->val.c_str()); break; } } } if (pIterator == m_nodeList.end()){ cout << __FUNCTION__ << "::\t" << "Cannot Find the Record with paramId " << paramId << endl; return false; } cout << __FUNCTION__ << "::\t" << "Find the Record (" << pIterator->comment << ")" << endl; return true;}bool OidManager::setString(UINT32 paramId ,STRING val){ vector
::iterator pIterator = m_nodeList.begin(); for (pIterator; pIterator != m_nodeList.end(); pIterator++){ if ( pIterator->req == "set" && pIterator->type == "string"){ if ( toString(paramId) == pIterator->id){ break; } } } if (pIterator == m_nodeList.end()){ cout << __FUNCTION__ << "::\t" << "Cannot Find the Record with paramId " << paramId << endl; return false; } cout << __FUNCTION__ << "::\t" << "Find the Record " << pIterator->comment << ")" << endl; return true;}/******************************************************************************//*getUin32 & setUint32*/bool OidManager::getUint32(UINT32 paramId ,UINT32 *uiParamVal){ vector
::iterator pIterator = m_nodeList.begin(); for (pIterator; pIterator != m_nodeList.end(); pIterator++){ if ( pIterator->req == "get" && pIterator->type == "uint"){ if ( toString(paramId) == pIterator->id){ *uiParamVal = toINT(pIterator->val); break; } } } if (pIterator == m_nodeList.end()){ cout << __FUNCTION__ << "::\t" << "Cannot Find the Record with paramId " << paramId << endl; return false; } cout << __FUNCTION__ << "::\t" << "Find the Record " << pIterator->comment << ")" << endl; return true;}bool OidManager::setUint32(UINT32 paramId ,UINT32 uiParamVal){ vector
::iterator pIterator = m_nodeList.begin(); for (pIterator; pIterator != m_nodeList.end(); pIterator++){ if ( pIterator->req == "set" && pIterator->type == "uint"){ if ( toString(paramId) == pIterator->id){ break; } } } if (pIterator == m_nodeList.end()){ cout << __FUNCTION__ << "::\t" << "Cannot Find the Record with paramId " << paramId << endl; return false; } cout << __FUNCTION__ << "::\t" << "Find the Record " << pIterator->comment << ")" << endl; return true;}/******************************************************************************//*Int32*/bool OidManager::getInt32(UINT32 paramId ,INT32 *iParamVal){ vector
::iterator pIterator = m_nodeList.begin(); for (pIterator; pIterator != m_nodeList.end(); pIterator++){ if ( pIterator->req == "get" && pIterator->type == "int"){ if ( toString(paramId) == pIterator->id){ *iParamVal = toINT(pIterator->val); break; } } } if (pIterator == m_nodeList.end()){ cout << __FUNCTION__ << "::\t" << "Cannot Find the Record with paramId " << paramId << endl; return false; } cout << __FUNCTION__ << "::\t" << "Find the Record " << pIterator->comment << ")" << endl; return true;}bool OidManager::setInt32(UINT32 paramId ,INT32 Val){ vector
::iterator pIterator = m_nodeList.begin(); for (pIterator; pIterator != m_nodeList.end(); pIterator++){ if ( pIterator->req == "set" && pIterator->type == "int"){ if ( toString(paramId) == pIterator->id){ break; } } } if (pIterator == m_nodeList.end()){ cout << __FUNCTION__ << "::\t" << "Cannot Find the Record with paramId " << paramId << endl; return false; } cout << __FUNCTION__ << "::\t" << "Find the Record " << pIterator->comment << ")" << endl; return true;}/******************************************************************************/

## Makefile

TARGET=okINCLUDES=-I/home/zengzhe/avod/api/common -I/home/zengzhe/avod/api/emod_helperLIBS=-L/home/zengzhe/avod/lib/LOCAL -ldssx -lcommon -lpthreadSOURCES=main.cpp oidManager.cpp$(TARGET):	g++ $(SOURCES) -o $(TARGET) $(INCLUDES) $(LIBS)clean:	rm -rf $(TARGET) *.o *~

## server_suu.txt

get	string	10	getVersion	getVersionget	string	11	queryUpdate	queryUpdateget	string	12	queryUpdateStat	queryUpdateStatget	string	13	ConfirmUpdate	ConfirmUpdate

## 用法说明

./ok server_suu.txt

该模块是配合自定义snmpd一起进行使用的辅助模块,用于验证是否正确设置了snmpd的扩展oid的接口。

转载地址:http://lcvbi.baihongyu.com/

你可能感兴趣的文章
GNU hello代码分析
查看>>
Qt继电器控制板代码
查看>>
busybox passwd修改密码
查看>>
wpa_supplicant控制脚本
查看>>
rfkill: WLAN hard blocked
查看>>
gstreamer相关工具集合
查看>>
arm 自动升级脚本
查看>>
RS232 四入四出模块控制代码
查看>>
gstreamer插件之 videotestsrc
查看>>
autoupdate script
查看>>
linux 驱动开发 头文件
查看>>
/etc/resolv.conf
查看>>
container_of()传入结构体中的成员,返回该结构体的首地址
查看>>
linux sfdisk partition
查看>>
ipconfig,ifconfig,iwconfig
查看>>
opensuse12.2 PL2303 minicom
查看>>
电平触发方式和边沿触发的区别
查看>>
网络视频服务器移植
查看>>
Encoding Schemes
查看>>
移植QT
查看>>