Exemple #1
0
/*
    Start the COM server (if necessary).
*/
bool qax_startServer(QAxFactory::ServerType type)
{
    if (qAxIsServer)
        return true;
    
    const QStringList keys = qAxFactory()->featureList();
    if (!keys.count())
        return false;
    
    if (!qAxFactory()->isService())
        StartMonitor();
    
    classRegistration = new DWORD[keys.count()];
    int object = 0;
    for (QStringList::ConstIterator key = keys.begin(); key != keys.end(); ++key, ++object) {
        IUnknown* p = 0;
        CLSID clsid = qAxFactory()->classID(*key);
        
        // Create a QClassFactory (implemented in qaxserverbase.cpp)
        HRESULT hRes = GetClassObject(clsid, IID_IClassFactory, (void**)&p);
        if (SUCCEEDED(hRes))
            hRes = CoRegisterClassObject(clsid, p, CLSCTX_LOCAL_SERVER,
                type == QAxFactory::MultipleInstances ? REGCLS_MULTIPLEUSE : REGCLS_SINGLEUSE,
                classRegistration+object);
        if (p)
            p->Release();
    }

    qAxIsServer = true;
    return true;
}
bool SensorResource::status_check(sensor_data &sensor)
{
	SensorMapIter iter;
	iter = m_sensorMap.find(sensor.s_name);
	if ((sensor.s_active == false) && (sensor.s_resource != nullptr)) {
		std::cout << "Sensor: " << sensor.s_name << " is offline" <<std::endl;
		if (iter != m_sensorMap.end()) {
			m_sensorMap.erase(iter);
			sensor.s_resource = nullptr;
		}

		return true;
	}
	else if ((sensor.s_active == true) && (sensor.s_resource == nullptr)) {
		//should not have this case, maybe there is a long delay
		//of notification packet, we need to refind the resource
		std::string address;
		if (iter != m_sensorMap.end()) {
			address = std::string(iter->second);
			StartMonitor(address);
		}
		sensor.s_active = false;
	}

	return false;
}
void SensorResource::put(OCRepresentation rep)
{
	if (rep.hasAttribute("name")) {
		m_sensorName = rep.getValue<std::string>("name");
	}

	if (rep.hasAttribute("address")) {
		m_sensorAddr = rep.getValue<std::string>("address");
	}

	std::cout << "Registered sensor name : " << m_sensorName << " address : " << m_sensorAddr<< std::endl;
	if ((!m_sensorName.empty()) && (!m_sensorAddr.empty())) {
		if (m_sensorMap.find(m_sensorName) == m_sensorMap.end()) {
			m_sensorMap.insert(SensorMap::value_type(m_sensorName, m_sensorAddr));
		}
	}
	else {
		return;
	}

	if (m_sensorName == "gas") {
		m_gas.s_name = m_sensorName;
	}
	else if (m_sensorName == "fan") {
		m_fan.s_name = m_sensorName;
	}
	else if (m_sensorName == "led") {
		m_led.s_name = m_sensorName;
	}
	else if (m_sensorName == "pri") {
		m_pri.s_name = m_sensorName;
	}

	StartMonitor(m_sensorAddr);
}
Exemple #4
0
////////////////////////////////////////////////////////////////////////////////
// HLSClip Implementation
//
HLSClip::HLSClip(IOPLUGIN& IoPlugin,
                 PlayListItem* pItem,
                 const char* pUserAgent): m_IoPlugin(IoPlugin),
    m_pFileHandle(NULL),
    m_pItem(pItem),
    m_iRefCounter(1)
{
    HLSPlayList* pPlayList = (HLSPlayList*)pItem->pOwner;
    if (pItem->iTag == TAG_FILE || pItem->iTag == TAG_EXT_INF)
        m_URL = pPlayList->GetFileURL(pItem);
    else if (pItem->iTag == TAG_EXT_KEY_INF) // This is a key file
        m_URL = ((M3UExtKeyInf*)(pItem->pItemInfo))->pKeyURI;

    if (pUserAgent && !m_URL.empty())
    {
        // Add extra command to HTTP IO Plugin
        m_URL.append(" extraHeader='User-Agent: ");
        m_URL.append(pUserAgent);
        m_URL.append("'");
    }
    zDebug("HLSClip::HLSClip(): Load %s(0x%x)(%s)\n",
           (pItem->iTag == TAG_EXT_KEY_INF ? "Key" : ""), (int)this, m_URL.c_str());
    m_pFileHandle = m_IoPlugin.open(const_cast<char*>(m_URL.c_str()), 0);
    zDebug("HLSClip::HLSClip(): Load (0x%x-0x%x)(%s) Done.\n",
           (int)this, (int)m_pFileHandle, m_URL.c_str());
#ifdef DUMP_DEBUG_MESSAGE
    StartMonitor(this);
#endif
}
int main(int argc, wchar_t* argv[])
{
	wchar_t configfile[64] = L"config.ini";
	if(ReadConfig() == -1){
		return 1;
	}

	//隐藏程序窗口
	HWND   hWnd;
	hWnd=GetConsoleWindow();
	ShowWindow(hWnd,SW_HIDE);

	StartMonitor(CallbackFunc, 5, NULL);
	return 0;
}
void RequestMonitor(int nSocket)
{
    int *pFiles,nLoopCount=1,nFiles,nIndex=0,nFlag=0;
    char szFilePath[200], szFiles[2],szSendMsg[300], szFileNamePath[10][200];
    printf("\n-----Request for Monitor by Client %d------\n",nSocket);
    strcpy(szFiles,(char*)RecieveMsg(nSocket));
    nFiles = atoi(szFiles);
    printf("Server nFiles : %d\n",nFiles);
    while(nLoopCount<=nFiles) {
        bzero(szFilePath,sizeof(szFilePath));
        strcpy(szFilePath,(char*)RecieveMsg(nSocket));
        printf("Inside RequestMonitor() = %s\n",szFilePath);
        if(!FileExists(szFilePath,nLoopCount-1)) {
            if(!CheckStatus(szFilePath)) {
                sprintf(szSendMsg,"%s --- Already being monitored by someone else",szFilePath);
                SendMsg(nSocket,szSendMsg);
                SendMsg(nSocket,"1");
                TransactWithClient((void*)nSocket);
            }
            else {
                sprintf(szSendMsg,"%s --- Available for monitoring\n",szFilePath);
                SendMsg(nSocket,szSendMsg);
                strcpy(szFileNamePath[nIndex],szFilePath);
                nIndex++;
            }
        }
        else {
            sprintf(szSendMsg,"%s --- This file doesn't exist\n",szFilePath);
            SendMsg(nSocket,szSendMsg);
            SendMsg(nSocket,"2");
            TransactWithClient((void*)nSocket);
        }
        nLoopCount++;
    }
    SendMsg(nSocket,"3");
    StartMonitor(szFileNamePath,nIndex,nSocket);
}
Exemple #7
0
BOOL ThreadContrl::AddTask(Monitor *pMonitor)
{ 
//	if(m_hThread==NULL)
//		throw MSException("Error : NO ThreadContrl thread");

	CString strError="";
	if(pMonitor==NULL)
		throw MSException("Monitor is empty");

	//bool ist=false;

	//if(stricmp(pMonitor->GetMonitorClass().getText(),"telnet")==0)
	//{
	//	char buf[100]={0};
	//	sprintf(buf,"////////////////class:%s telnet monitor:%s//////////////\n",pMonitor->GetMonitorClass().getText(),
	//		pMonitor->GetMonitorID());

	//	ist=true;

	//	//putil->ErrorLog(buf);
	//}

	if(pMonitor->GetSkipCount()>=MAXSKIPCOUNT)
	{
		strError.Format("SkipCount > %d, MonitorID:%s, this monitor will be deleted. ",MAXSKIPCOUNT,pMonitor->GetMonitorID());
		m_pSchMain->DeleteMonitorV70(pMonitor->GetMonitorID());
		string strTemp = strError.getText();
		WriteLog( strTemp.c_str() );
		//putil->ErrorLog(strError);
		//throw MSException((LPCSTR)strError);
		return false;
	}

	if(pMonitor->GetRunning())
	{
		pMonitor->SetSkipCount(pMonitor->GetSkipCount()+1);
		strError.Format("Monitor skip count:%d,Monitor ID:%s",pMonitor->GetSkipCount(),pMonitor->GetMonitorID());
		string strTemp = strError.getText();
		WriteLog( strTemp.c_str() );
		//putil->ErrorLog(strError);

	}else{
		if(!CheckSubsequent(pMonitor))
		{
			//if(ist)
			//	//putil->ErrorLog("will Start Monitor");
			StartMonitor(pMonitor);
	//		StartMonitor(PopMonitorInQueue(pMonitor));
		}
		else
		{
			//if(ist)
			//	//putil->ErrorLog("Enter queue");
			AddQueue(pMonitor);
		}
	}


	return TRUE;

}