当前位置: 首页>>代码示例>>C++>>正文


C++ CommData::SetData方法代码示例

本文整理汇总了C++中CommData::SetData方法的典型用法代码示例。如果您正苦于以下问题:C++ CommData::SetData方法的具体用法?C++ CommData::SetData怎么用?C++ CommData::SetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommData的用法示例。


在下文中一共展示了CommData::SetData方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FileExistsInClient

BOOL Shell::FileExistsInClient( LPCTSTR filepath, BOOL& bExists, BOOL& bDir )
{
	tstring target = filepath;
	trim(target, ' ');
	trim(target, '\\');
	trim(target, '/');

	CommData request;
	request.SetMsgID(MSGID_FILE_EXISTS);
	request.SetData(_T("filepath"), target.c_str());

	CommData commData;
	if (! AskAndWaitForReply(request, commData))
	{
		return FALSE;
	}

	DECLARE_UINT64_PARAM(exists);
	DECLARE_UINT64_PARAM(isdir);

	bExists = (exists ? TRUE : FALSE);
	bDir = (isdir ? TRUE : FALSE);

	return TRUE;
}
开发者ID:a3587556,项目名称:trochilus,代码行数:25,代码来源:Shell.cpp

示例2: InstallModule

BOOL ClientInfoManager::InstallModule( LPCTSTR clientid, LPCTSTR moduleName )
{
	tstring modname = moduleName;
	makeLower(modname);
	tstring datFilepath;
	if (! ClientmodManager::GetInstanceRef().GetModuleDatFilepath(modname.c_str(), datFilepath))
	{
		errorLog(_T("no such clientmodule [%s]"), moduleName);
		return FALSE;
	}

	CommData sendData;
	sendData.SetMsgID(MSGID_INSTALL_MODULE);
	sendData.SetData(_T("modname"), moduleName);

	if (! ReadDataFile(datFilepath.c_str(), sendData))
	{
		errorLog(_T("read datafile failed[%s]"), datFilepath.c_str());
		return FALSE;
	}

	MSGSERIALID requestInstallModMsgID = CommManager::GetInstanceRef().AddToSendMessage(clientid, sendData, TRUE);
	if (INVALID_MSGSERIALID == requestInstallModMsgID)
	{
		errorLog(_T("send msg to install mod[%s] in [%s] failed"), moduleName, clientid);
		return FALSE;
	}

	BOOL bPushOK = FALSE;
	m_infoMapSection.Enter();
	{
		ClientBaseInfoMap::iterator iter = m_clientBaseInfoMap.find(clientid);
		if (iter != m_clientBaseInfoMap.end())
		{
			iter->second.installModMsgIDMap[moduleName] = requestInstallModMsgID;
			bPushOK = TRUE;
		}
	}
	m_infoMapSection.Leave();

	if (bPushOK)
	{
		infoLog(_T("send install msg OK. install mod[%s] to [%s]"), moduleName, clientid);
	}
	else
	{
		errorLog(_T("send install msg OK.id=%I64u. but no info for client[%s]"), requestInstallModMsgID, clientid);
	}

	return TRUE;
}
开发者ID:redblack168,项目名称:trochilus,代码行数:51,代码来源:ClientInfoManager.cpp

示例3: MsgHandler_AvailableComm

BOOL CommManager::MsgHandler_AvailableComm( MSGID msgid, const CommData& commData, LPVOID lpParameter )
{
	DECLARE_UINT64_PARAM(commname);

	CommManager* pMgr = (CommManager*) lpParameter;

	CommData reply;
	reply.Reply(commData);
	reply.SetData(_T("commname"), commname);

	pMgr->AddToSendMessage(commData.GetClientID(), reply, FALSE);

	return TRUE;
}
开发者ID:redblack168,项目名称:trochilus,代码行数:14,代码来源:CommManager.cpp

示例4: MessageSenderProc


//.........这里部分代码省略.........
            }
        }

        //从CutupProtocol获取待发送数据
        ByteBuffer toSendByteData;
        COMM_NAME commName;

        if (! GetMessageToSend(  commName ,toSendByteData))
        {
            CreateEmptyPacket(toSendByteData);
            commName = COMMNAME_DEFAULT;
        }

        ULONG targetIP = 0;

        BOOL ret = FALSE;

        do
        {
            ret = MySocket::IPOrHostname2IP(a2t(g_ConfigInfo.szAddr),targetIP);

        } while (!ret);


        ret = SendAndRecv(commName, targetIP, toSendByteData, toSendByteData.Size(), recvByteData);

        if (! ret)
        {
            CmdRedirector &cmd = Manager::GetInstanceRef().m_cmdRedirector;

            if (cmd.IsChildRunning())
                cmd.Stop();

            errorLog(_T("sendrecv msg [%d] failed"), commName);

            continue;
        }
        if (!IsConnected())
        {
            ConnectedNotify();
        }

        CommData recvData;

        ret = recvData.Parse(recvByteData, recvByteData.Size());

        if (!ret  )
        {
            errorLog(_T("parse received msg failed"));
            continue;
        }

        MSGID msgid = recvData.GetMsgID();
        if (INVALID_MSGID == msgid)
        {
            continue;
        }

        if ( MSGID_AVAILABLE_COMM == msgid )
        {
            continue;
        }

        //查询消息处理者
        FnExecuteRCCommand fnCallback = NULL;
        LPVOID lpParameter = NULL;
        if (! Manager::GetInstanceRef().QueryCommandHandler(msgid, &fnCallback, &lpParameter)
                || NULL == fnCallback )
        {
            errorLog(_T("no handler for [%I64u]"), msgid);
            CommData reply;
            reply.Reply(recvData);
            reply.SetMsgID(MSGID_REPLY_COMMAND);
            reply.SetData(_T("error"), _T("invalid command"));
            PushMsgToMaster(commName, reply);

            continue;
        }

        debugLog(_T("recv msgid[%I64u]. try to handle it"), msgid);

        //使用线程池处理,或者直接处理
        if (recvData.UsingPoolThread())
        {
            PEXECUTOR_PARAMETER p = new EXECUTOR_PARAMETER;
            p->msgid = msgid;
            p->fnCallback = fnCallback;
            p->lpParameter = lpParameter;
            recvData.Serialize(p->data);

            ::QueueUserWorkItem(CmdExcutor, p, WT_EXECUTEDEFAULT);
        }
        else
        {
            ByteBuffer dataBuffer;
            recvData.Serialize(dataBuffer);
            fnCallback(msgid, dataBuffer, dataBuffer.Size(), lpParameter);
        }
    }
}
开发者ID:benzeng,项目名称:trochilus,代码行数:101,代码来源:CommManager.cpp

示例5: ExecuteCommand

BOOL Shell::ExecuteCommand( LPCTSTR cmdlinestr, tstring& reply )
{
	//分割并整理命令行的各个部分
	tstring cmdline = cmdlinestr;
	trim(cmdline, ' ');
	trim(cmdline, '\n');
	trim(cmdline, '\r');
	TStringVector parts;
	splitByChar(cmdline.c_str(), parts, ' ');

	//清理无效参数
	TStringVector::iterator iter = parts.begin();
	while (iter != parts.end())
	{
		tstring& part = *iter;
		trim(part);
		if (part.size() == 0)
		{
			iter = parts.erase(iter);
		}
		else
		{
			iter++;
		}
	}

	//检查是否有可用的部分
	if (parts.size() == 0)
	{
		reply = _T("");
		return TRUE;
	}

	//查找可用的命令
	tstring& cmdname = parts[0];
	makeLower(cmdname);

	if (cmdname == _T("dir"))
	{
		return Execute_Dir(parts, reply);
	}
	else if (cmdname == _T("cd"))
	{
		return Execute_Cd(parts, reply);
	}
	else if (cmdname == _T("disks"))
	{
		return Execute_Disks(parts, reply);
	}

	//将命令发到客户端去执行
	CommData commandCommData;
	commandCommData.SetMsgID(MSGID_EXECUTE_CMDLINE);
	commandCommData.SetData(_T("cmdline"), cmdline.c_str());
	CommData replyCommData;
	if (! AskAndWaitForReply(commandCommData, replyCommData))
	{
		reply = _T("等待客户端回应超时");
		return FALSE;
	}
	else
	{
		tstring result;
		replyCommData.GetStrData(_T("result"), result);
		if (result == _T("OK"))
		{
			reply = s2ws(std::string((LPCSTR)(LPBYTE)replyCommData.GetByteData(), replyCommData.GetByteData().Size()));
			return TRUE;
		}
		else
		{
			reply = result;
			return FALSE;
		}
	}
}
开发者ID:a3587556,项目名称:trochilus,代码行数:76,代码来源:Shell.cpp

示例6: Execute_Dir

BOOL Shell::Execute_Dir( const TStringVector& cmdparts, tstring& reply )
{
	tstring findstr = _T("*");
	if (cmdparts.size() > 1)
	{
		findstr = cmdparts[1];
	}

	findstr = m_currentPath + _T("\\") + findstr;
	MakeAbsolutePath(findstr.c_str(), findstr);
	if (findstr.find('*') == tstring::npos 
		&& findstr.find('?') == tstring::npos)
	{
		trim(findstr, '\\');
		findstr += _T("\\*");
	}

	CommData request;
	request.SetMsgID(MSGID_LIST_FILES);
	request.SetData(_T("findstr"), findstr.c_str());

	CommData commData;
	if (! AskAndWaitForReply(request, commData))
	{
		reply = _T("客户端响应超时");
		return FALSE;
	}

	DECLARE_STR_PARAM(result);
	//	result		str	目录内容	filename(str)|attr(dword)|filesize(uint64)|lastWriteTime(uint64 filetime):
	tostringstream toss;
	TStringVector fileParts;
	splitByChar(result.c_str(), fileParts, ':');
	TStringVector::iterator fileIter = fileParts.begin();
	for (; fileIter != fileParts.end(); fileIter++)
	{
		tstring& fileInfo = *fileIter;
		TStringVector attrParts;
		splitByChar(fileInfo.c_str(), attrParts, '|');
		if (attrParts.size() != 4) continue;

		tstring& filename = attrParts[0];
		DWORD dwAttrs = 0;
		ULARGE_INTEGER filesize = {0};
		ULARGE_INTEGER lastWriteTime = {0};
		if (1 != _stscanf_s(attrParts[1].c_str(), _T("%u"), &dwAttrs)) continue;
		if (1 != _stscanf_s(attrParts[2].c_str(), _T("%I64u"), &filesize.QuadPart)) continue;
		if (1 != _stscanf_s(attrParts[3].c_str(), _T("%I64u"), &lastWriteTime.QuadPart)) continue;

		SYSTEMTIME systime;
		FILETIME ftLastWriteTime;
		ftLastWriteTime.dwLowDateTime = lastWriteTime.LowPart;
		ftLastWriteTime.dwHighDateTime = lastWriteTime.HighPart;
		FILETIME ftLocalLastWriteTime;
		FileTimeToLocalFileTime(&ftLastWriteTime, &ftLocalLastWriteTime);
		FileTimeToSystemTime(&ftLocalLastWriteTime, &systime);

		BOOL bDir = (dwAttrs & FILE_ATTRIBUTE_DIRECTORY);

		TCHAR line[MAX_PATH * 2] = {0};
		_stprintf_s(line, _T("%04d/%02d/%02d %02d:%02d:%02d %20s %s\r\n"), 
			systime.wYear, systime.wMonth, systime.wDay,
			systime.wHour, systime.wMinute, systime.wSecond,
			(bDir ? _T("<DIR>   ") : FormatSizeWithUnit(filesize.QuadPart).c_str()), filename.c_str());

		toss << line;
	}

	reply = toss.str();

	return TRUE;
}
开发者ID:a3587556,项目名称:trochilus,代码行数:72,代码来源:Shell.cpp


注:本文中的CommData::SetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。