示例#1
0
//接受数据
void CNetLink::OnData(const CEasyBuffer& DataBuffer)
{
	FUNCTION_BEGIN;


	SMSG * pMsg=(SMSG *)DataBuffer.GetBuffer();
	UINT DataSize=pMsg->Header.Size-sizeof(SMSG_HEADER);

	switch(pMsg->Header.MsgID)
	{
	case SC_MSG_SERVER_LOG:
		{
			CSmartStruct LogInfo(pMsg->Data,DataSize,false);

			LPCTSTR szLogMsg=LogInfo.GetMember(SC_SST_SL_LOG_STR);
			if(szLogMsg&&m_pView)
			{
				m_pView->PrintLogMsg(szLogMsg);
			}

		}
		break;
	case SC_MSG_QUERY_SERVER_STATUS_RESULT:
		if(m_pView)
		{
			CSmartStruct ServerStatus(pMsg->Data,DataSize,false);
			m_pView->SetServerStatus(ServerStatus);
		}
		break;
	case SC_MSG_GET_SERVER_STATUS_FORMAT_INFO_RESULT:
		if(m_pView)
		{
			CSmartStruct ServerStatusFormats(pMsg->Data,DataSize,false);
			m_pView->SetServerStatusFormats(ServerStatusFormats);
		}
	}

	FUNCTION_END;
}
CString CImpactCtrl::ExecPrint(CString &command) 
{
    CString MethodName("AccessDish"); // We will run AccessSync method of the DataSource
    CString ServerStatus("IsServerBusy"); 
    DISPID accessID;                  // IDispatch id for the AccessSync command
    HRESULT hresult;
    CString cmd = command;

    // if there is no data source assigned to this control, we will be unable to
    // evaluate this function.
    if(m_DataSource==NULL) return m_cszError + CString(" No data source - can't evaluate a command");


    // Trying to receve method ID from it's name.
    BSTR statusBSTR=ServerStatus.AllocSysString();
    hresult = m_DataSource->GetIDsOfNames(IID_NULL,&statusBSTR, 
                                          1,LOCALE_SYSTEM_DEFAULT,&accessID);
    VARIANT busyBOOL;
    unsigned int errors_in_arg;
    DISPPARAMS Param;
    Param.cArgs     = 0;
    Param.cNamedArgs=0;
    hresult = m_DataSource->Invoke(accessID,
                                   IID_NULL,
                                   LOCALE_SYSTEM_DEFAULT,
                                   DISPATCH_METHOD,
                                   &Param,
                                   &busyBOOL,
                                   NULL,
                                   &errors_in_arg);
    if (busyBOOL.intVal!=0) return m_cszError + CString(" server is busy.");
	::SysFreeString(statusBSTR);

    // Trying to receve method ID from it's name.
    BSTR methodBSTR=MethodName.AllocSysString();
    hresult = m_DataSource->GetIDsOfNames(IID_NULL,&methodBSTR, 
                                          1,LOCALE_SYSTEM_DEFAULT,&accessID);

    // Interface doesn't support AccessSync method
    if(hresult!=S_OK) return m_cszError + CString(" data source does not support AccessSync method");
	::SysFreeString(methodBSTR);

    // Converting command into new OEM string wich will be passed into OLE automation.
    // We will free when pushing into the stack
    BSTR access_call = cmd.AllocSysString();

    // Creating parameter structure - only one parameter will be passed as argument - command string
    DISPPARAMS cmdParamStruct;
    cmdParamStruct.rgvarg              = new VARIANT[1];
    cmdParamStruct.rgvarg[0].vt        = VT_BSTR | VT_BYREF; // we will pass it as BSTR reference
    cmdParamStruct.rgvarg[0].pbstrVal  = &access_call;
    cmdParamStruct.cArgs               = 1;
    cmdParamStruct.cNamedArgs=0;

    // Results will be inserted into VARIANT union
    VARIANT resBSTR;
    // This will show the argument with an error
    unsigned int argWithError;
    // Remote command execution
    hresult = m_DataSource->Invoke(accessID,
                                   IID_NULL,
                                   LOCALE_SYSTEM_DEFAULT,
                                   DISPATCH_METHOD,
                                   &cmdParamStruct,
                                   &resBSTR,
                                   NULL,
                                   &argWithError);
    delete cmdParamStruct.rgvarg;
    ::SysFreeString(access_call);

    CString szResult;
    if(hresult!=S_OK) szResult = m_cszError + " Command '" + command + "' failed.\n";
    szResult += resBSTR.bstrVal;
	
	int nLen = szResult.GetLength()-2; // remove % sign at the end
	szResult = szResult.Left(nLen);
    return szResult;
}
示例#3
0
ServerStatus Handle::registerServerStatus(const char *service_name,
                                          const ServerStatusCallback &callback)
{
    return ServerStatus(_handle, service_name, callback);
}