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

📄 opagent.cpp

📁 ABis无线接口全套资料
💻 CPP
字号:
/* ======================================================================== *\
 |
 |
 |  JOYIT Communication Technology
 |  Copyright (C)  2002-2003,  All Right Reserved.
 |
 |  System: Programmable Signaling Gateway
 |  Sub-system:
 |  Filename: opagent.cpp
 |  Environment:    LINUX -- Red Hat 9.0 & GNU C/C++ Compiler 3.2.2
 |                vxWorks -- Tornado 2.0 & vxWorks 5.4
 |  Function description: Define the function of out put agent class.
 |           
 |
\* ======================================================================== */

#ifndef _OPAGENT_HPP
#include "opagent.hpp"
#endif

OutPutAgent  *opaPtr = NULL;

OutPutAgent::OutPutAgent(const char  * const logfilename) : WObject( ), outMode(OUT_STDOUT), log( )
{
	SetMask(evPrint);

	if (logfilename != NULL)
	{
		log.SetFileName(logfilename);
		outMode |= OUT_FILE;
		log.OpenFile( );
	}
	/*
	else
	{
		log.SetFileName("mtp3.log");    // Set the default file name. Set the 
										// module name as the log file name.
	}
	log.OpenFile( );
	*/
}

OutPutAgent::~OutPutAgent( )
{
	log.CloseFile( );
}

void OutPutAgent::handleEvent(WEvent& event)
{
	if (outMode == OUT_NULL)
	{
		// No out put device available here, return immediate.
		return;
	}
	
	if (event.what & GetMask( ))
	{
		struct tm * ltm;
		char buf[256];
		int len = (event.msgPtr != NULL) ? strlen(event.msgPtr) : 0;

		ltm = localtime(&event.prEvent.timeStamp);
		sprintf(buf, "<%04d-%02d-%02d %02d:%02d:%02d>   ", ltm->tm_year+1900, ltm->tm_mon+1,
						ltm->tm_mday, ltm->tm_hour, ltm->tm_min, ltm->tm_sec);
		memcpy(buf+24, event.msgPtr, len);
		buf[24+len] = '\0';

		if (outMode & OUT_STDOUT)
		{
			printf("%s\n", buf);
		}
		if (outMode & OUT_STDERR)
		{
			fprintf(stderr, "%s\n", buf);
		}
		if (outMode & OUT_PTERM)
		{
			// Send the message to PTERM process.
			// ......
		}
		if (outMode & OUT_FILE)
		{
			// Log the message into disk file.
			log.Log(buf);
		}
	}
}

void OutPutAgent::idle( )
{
	WObject::idle( );
}

void OutPutAgent::OAMagent( )
{
	return;
}

UINT8 OutPutAgent::SetOutMode(UINT8 om)
{
	UINT8 o;
	o = outMode;
	outMode = om;
	return o;
}

UINT8 OutPutAgent::GetOutMode( )
{
	return outMode;
}

void OutPutAgent::SetLogFileName(const char  * const logfilename)
{
	log.SetFileName(logfilename);
	log.OpenFile( );    // Must open file here. Because set file name, it means
						// that you want store the information into file.
}

// ------------------------------------------------------------------------
//
//  Revision list.
//  ==============
//
//  1.0,        2003-04-18,     Wu jianjin
//      Initial version.
//  1.1,        2003-05-19,     Wu jianjin
//      Ported to vxWorks.
//
// ------------------------------------------------------------------------

⌨️ 快捷键说明

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