Example #1
0
void test_ProcessMonitorData()
{
	ProcessMonitorData pmdata;
	char buf[256]={0};
	pmdata.m_funname="myfunc";
	pmdata.m_dllname="C:\\siteview\\siteview ecc\\fcgi-bin\\monitor.dll";
	pmdata.m_data=buf;
	pmdata.m_datalen=256;

	unsigned int len=0;
	len=pmdata.GetRawDataSize();
	svutil::buffer dbuf(len);

	if(!pmdata.GetRawData(dbuf,len))
	{
		puts("Get raw data failed");
		return;
	}

	ProcessMonitorData clone;
//	clone.m_data=buf;
//	clone.m_datalen=256;
	if(!clone.CreateObjectByRawData(dbuf,len))
	{
		puts("Create Object failed");
		return;
	}

	printf("funname:%s,dllname:%s,datalen:%d,state:%d\n",clone.m_funname.c_str(),clone.m_dllname.c_str(),clone.m_datalen,clone.m_state);
	clone.Clear();
}
Example #2
0
void Run_ProcessMonitor(string queuename)
{
   CString strError;
#ifdef WIN32

	if(queuename.empty())
		return ;
	MQRECORD mrd=::PopMessage(queuename);
	if(mrd==INVALID_VALUE)
	{
	   throw MSException("Pop Message failed failed in Run_ProcessMonitor function");
		return ;
	}
   string label="";
   unsigned int blen=0;
   svutil::TTime rt;
   if(!GetMessageData(mrd,label,rt,NULL,blen))
   {
      ::CloseMQRecord(mrd);
	   throw MSException("Get Message failed failed in Run_ProcessMonitor function");
	   return;
   }
   svutil::buffer dbuf;
   if(!dbuf.checksize(blen))
   {
       ::CloseMQRecord(mrd);
	   return ;
   }
   if(!GetMessageData(mrd,label,rt,dbuf,blen))
   {
       ::CloseMQRecord(mrd);
	   return;
   }

   ::CloseMQRecord(mrd);


   ProcessMonitorData pdata;
   if(!pdata.CreateObjectByRawData(dbuf,blen))
   {
	   ::CloseMQRecord(mrd);
	   throw MSException("Create object failed in Run_ProcessMonitor function");
	   return;
   }

 	HMODULE hm=::LoadLibrary(pdata.m_dllname.c_str());
	if(!hm)
	{
		strError.Format("RunMonitor-Load library failed,DLL name:%s",pdata.m_dllname.c_str());
		throw MSException((LPCSTR)strError);
	}

	char retbuf[RETBUFCOUNT]={0};


	LPFUNC pfunc = (LPFUNC)GetProcAddress(hm,pdata.m_funname.c_str());
	if(!pfunc)
	{
		::FreeLibrary(hm);
		throw MSException("RunMonitor-GetProcAddress failed");

	}


	int buflen=RETBUFCOUNT;

	try{

		(*pfunc)(pdata.m_data,retbuf,buflen);

	}catch(...)
	{
		::FreeLibrary(hm);
		throw MSException("RunMonitor-Execute monitor happen exception");
	}
	::FreeLibrary(hm);

	pdata.Clear();

	int ilen=CheckReturnLen(retbuf);
	if(ilen<=0)
		throw MSException("Return result error in Run_ProcessMonitor function"); 

	if(!::PushMessage(queuename,"SiteView_Return",retbuf,ilen))
		throw MSException("Push message failed in Run_ProcessMonitor function");



#else
#endif


}
Example #3
0
bool MonitorThread::RunInProcess(int iLen,string dllname,string funname)
{
	if(m_Monitor==NULL)
		throw MSException("Monitor is empty in RunInProcess function");

#ifdef WIN32

	DWORD dw=::GetCurrentThreadId();
	char queuename[256]={0};
	sprintf(queuename,"SiteView_RunMonitor_%d",dw);
	::CreateQueue(queuename,2);
	::ClearQueueMessage(queuename);

	ProcessMonitorData pdata;
	pdata.m_data=m_InBuf.getbuffer();
	pdata.m_datalen=iLen;
	pdata.m_dllname=dllname;
	pdata.m_funname=funname;
    
	int len=pdata.GetRawDataSize();
	if(len<=RETBUFCOUNT)
	{
		if(!pdata.GetRawData(m_RetBuf,len))
			throw MSException("Get data failed in RunInProcess function");
		if(!::PushMessage(queuename,"InData",m_RetBuf,len))
			throw MSException("PushMessage failed in RunInProcess function");
	}else
	{
		svutil::buffer ibuf;
		if(!ibuf.checksize(len))
			throw MSException("Malloc memmory failed in RunInProcess function");

		if(!pdata.GetRawData(ibuf,len))
			throw MSException("Get data failed2 in RunInProcess function");
	}
	char strCommandLine[1024]={0};
	sprintf(strCommandLine,"%s\\fcgi-bin\\MonitorSchedule.exe -e %s",(char *)g_strRootPath,queuename);
//	sprintf(strCommandLine,"\"%s\\fcgi-bin\\MonitorSchedule.exe\"",(char *)g_strRootPath);
	PROCESS_INFORMATION pi;
	ZeroMemory( &pi, sizeof(PROCESS_INFORMATION) );
	STARTUPINFO si;
	ZeroMemory( &si, sizeof(STARTUPINFO) );
	si.cb=sizeof(STARTUPINFO);

	char strDir[256]={0};
	sprintf(strDir,"%s\\fcgi-bin\\",(char *)g_strRootPath);
	printf("CommandLine :%s\n",strCommandLine);
	printf("dir :%s\n",strDir);

	if(!::CreateProcess(NULL,
		strCommandLine,
		NULL,
		NULL,
		FALSE,
		/*CREATE_NO_WINDOW*/CREATE_NEW_CONSOLE,
		NULL,
		strDir,
		&si,&pi))
	{
		
		DWORD dw=GetLastError();
		printf("error:%d\n",dw);
		::DeleteQueue(queuename);

		throw MSException("Create process failed in RunInProcess function");
	}

   ::WaitForSingleObject(pi.hProcess,INFINITE);

   MQRECORD mrd=::PopMessage(queuename);
   if(mrd==INVALID_VALUE)
   {
		::DeleteQueue(queuename);
	   throw MSException("Receive messgae failed in RunInProcess function");
   }

   string label="";
   unsigned int blen=0;
   svutil::TTime rt;
   if(!GetMessageData(mrd,label,rt,NULL,blen))
   {
	   ::CloseMQRecord(mrd);
		::DeleteQueue(queuename);
	   throw MSException("GetMessageData failed in RunInProcess function");
   }

   if(label.compare("SiteView_Return")!=0)
   {
	   ::CloseMQRecord(mrd);
		::DeleteQueue(queuename);
	   throw MSException("Return data error in RunInProcess function");
   }

   if(blen>RETBUFCOUNT)
   {
	   ::CloseMQRecord(mrd);
		::DeleteQueue(queuename);
	   throw MSException("Return data too big in RunInProcess function");
   }

   if(!GetMessageData(mrd,label,rt,m_RetBuf,blen))
   {
	   ::CloseMQRecord(mrd);
		::DeleteQueue(queuename);
	   throw MSException("GetMessageData failed2 in RunInProcess function");
   }
   ::CloseMQRecord(mrd);
   ::DeleteQueue(queuename);


#endif

	return true;
}