本文整理汇总了C++中Protocol类的典型用法代码示例。如果您正苦于以下问题:C++ Protocol类的具体用法?C++ Protocol怎么用?C++ Protocol使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Protocol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PluginCommand_GetMyAvatar
static int PluginCommand_GetMyAvatar(WPARAM wParam,LPARAM lParam)
{
char * ret = (char *)lParam;
char * proto = (char *)wParam;
if (ret == NULL)
return -1;
if (proto == NULL)
{
if (protocols->default_avatar_file != NULL)
lstrcpyn(ret, protocols->default_avatar_file, MS_MYDETAILS_GETMYAVATAR_BUFFER_SIZE);
else
ret[0] = '\0';
}
else
{
Protocol protocol = GetProtocolByName(proto);
if (!protocol)
return -1;
if (!protocol.CanGetAvatar())
return -2;
lstrcpyn(ret, protocol.GetAvatarFile(), MS_MYDETAILS_GETMYAVATAR_BUFFER_SIZE);
}
return 0;
}
示例2: QTimer
void StatusLabel::setPict()
{
const char *icon;
const char *text;
if (m_client->getState() == Client::Connecting){
if (m_timer == NULL){
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
m_timer->start(1000);
m_bBlink = false;
}
Protocol *protocol = m_client->protocol();
text = I18N_NOOP("Connecting");
unsigned status;
if (m_bBlink){
icon = "online";
status = m_client->getManualStatus();
}else{
icon = "offline";
status = STATUS_OFFLINE;
}
if (protocol){
for (const CommandDef *cmd = protocol->statusList(); cmd->text; cmd++){
if (cmd->id == status){
icon = cmd->icon;
break;
}
}
}
}else{
if (m_timer){
delete m_timer;
m_timer = NULL;
}
if (m_client->getState() == Client::Error){
icon = "error";
text = I18N_NOOP("Error");
}else{
Protocol *protocol = m_client->protocol();
const CommandDef *cmd = protocol->description();
icon = cmd->icon;
text = cmd->text;
for (cmd = protocol->statusList(); cmd->text; cmd++){
if (cmd->id == m_client->getStatus()){
icon = cmd->icon;
text = cmd->text;
break;
}
}
}
}
QPixmap pict = Pict(icon);
QString tip = CorePlugin::m_plugin->clientName(m_client);
tip += "\n";
tip += i18n(text);
setPixmap(pict);
QToolTip::add(this, tip);
resize(pict.width(), pict.height());
setFixedSize(pict.width(), pict.height());
};
示例3: onNodeUpdated
void ProtocolManager::onNodeUpdated(Event *e)
{
if (!e)
return;
NodeRef& node = e->getNode();
NodeRefList& nl = e->getNodeList();
if (!node)
return;
// Check if there are any protocols that are associated with the updated nodes.
for (NodeRefList::iterator it = nl.begin(); it != nl.end(); it++) {
NodeRef& old_node = *it;
old_node.lock();
for (InterfaceRefList::const_iterator it2 = old_node->getInterfaces()->begin();
it2 != old_node->getInterfaces()->end(); it2++) {
const InterfaceRef& iface = *it2;
for (protocol_registry_t::iterator it3 = protocol_registry.begin(); it3 != protocol_registry.end(); it3++) {
Protocol *p = (*it3).second;
if (p->isForInterface(iface)) {
HAGGLE_DBG("Setting peer node %s on protocol %s\n", node->getName().c_str(), p->getName());
p->setPeerNode(node);
}
}
}
old_node.unlock();
}
}
示例4: NameserTwoWayStream
bool yarp::os::impl::NameserCarrier::respondToHeader(Protocol& proto) {
// I am the receiver
NameserTwoWayStream *stream =
new NameserTwoWayStream(proto.giveStreams());
proto.takeStreams(stream);
return true;
}
示例5: getSpecifierName
bool yarp::os::impl::NameserCarrier::sendHeader(Protocol& proto) {
yarp::os::impl::String target = getSpecifierName();
yarp::os::Bytes b((char*)target.c_str(),8);
proto.os().write(b);
proto.os().flush();
return proto.os().isOk();
}
示例6: xml
/*!
Load static built-in components.
*/
void Server::loadStaticComponents ()
{
string xml ("xml");
mimeManager.setLogger (this);
mimeManager.registerHandler (xml, new XmlMimeHandler ());
XmlVhostHandler::registerBuilder (vhostManager);
XmlMimeHandler::registerBuilder (mimeManager);
validatorFactory.addValidator (xml, xmlValidator);
authMethodFactory.addAuthMethod (xml, (AuthMethod*) xmlValidator);
if (filtersFactory.insert ("gzip", Gzip::factory))
log (MYSERVER_LOG_MSG_ERROR, _("Error while loading plugins"));
HttpProtocol *http = new HttpProtocol ();
Protocol *protocolsSet[] = {http,
new HttpsProtocol (http),
new GopherProtocol (),
new FtpProtocol (),
new ControlProtocol (),
NULL};
for (int j = 0; protocolsSet[j]; j++)
{
Protocol *protocol = protocolsSet[j];
protocol->loadProtocol ();
const char *protocolName = protocol->getName ();
getProtocolsManager ()->addProtocol (protocolName, protocol);
}
Md5::initialize (&cryptAlgoManager);
Sha1::initialize (&cryptAlgoManager);
}
示例7: HAGGLE_DBG
void ProtocolManager::onWatchableEvent(const Watchable& wbl)
{
protocol_registry_t::iterator it = protocol_registry.begin();
HAGGLE_DBG("Receive on %s\n", wbl.getStr());
// Go through each protocol in turn:
for (; it != protocol_registry.end(); it++) {
Protocol *p = (*it).second;
// Did the Watchable belong to this protocol
if (p->hasWatchable(wbl)) {
// Let the protocol handle whatever happened.
p->handleWatchableEvent(wbl);
return;
}
}
HAGGLE_DBG("Was asked to handle a socket no protocol knows about!\n");
// Should not happen, but needs to be dealt with because if it isn't,
// the kernel will call us again in an endless loop!
kernel->unregisterWatchable(wbl);
CLOSE_SOCKET(wbl.getSocket());
}
示例8: checkTitle
void FileDescription::checkTitle()
{
Protocol *gadu = AccountManager::instance()->defaultAccount()->protocol();
if (QFile::exists(config_file.readEntry("FileDesc", "file")))
{
QFile file(config_file.readEntry("FileDesc", "file"));
if (!gadu->currentStatus().isOffline())
{
if (file.open(IO_ReadOnly))
{
QString desc = "";
QTextStream stream(&file);
if (!stream.atEnd())
desc = stream.readLine();
if ((desc != currDesc || gadu->currentStatus().description() != desc && !config_file.readBoolEntry("FileDesc", "allowOther")
|| !gadu->currentStatus().hasDescription() && config_file.readBoolEntry("FileDesc", "forceDescr")) && !gadu->currentStatus().isOffline())
{
currDesc = desc;
fileDescStatusChanger->setTitle(desc);
}
file.close();
}
}
}
}
示例9: hawk_EchoClientRoutine
PVoid hawk_EchoClientRoutine(void* pArg)
{
HawkSession session;
if (session.Init(g_IpAddr))
{
while (g_Running)
{
//更新
if (!session.Tick(PROTO_TIME))
break;
//发送协议
Int32 iType = HawkRand::RandInt(PROTO_A, PROTO_C);
if (iType == PROTO_A)
{
ProtoA sCmd;
session.SendProtocol(&sCmd);
}
else if (iType == PROTO_B)
{
ProtoB sCmd;
session.SendProtocol(&sCmd);
}
else if (iType == PROTO_C)
{
ProtoC sCmd;
session.SendProtocol(&sCmd);
}
//接收协议
Protocol* pProto = 0;
while (session.DecodeProtocol(pProto) && pProto)
{
#if (PRINT_PROTO == 1)
ProtoType iType = pProto->GetType();
if (iType == PROTO_A)
{
ProtoA* pA = (ProtoA*)pProto;
HawkFmtPrint("Msg: %s",pA->m_sMsg.c_str());
}
else if (iType == PROTO_B)
{
ProtoB* pB = (ProtoB*)pProto;
HawkFmtPrint("Size: %d, Time: %d",pB->m_iSize, pB->m_iTime);
}
else if (iType == PROTO_C)
{
ProtoC* pC = (ProtoC*)pProto;
HawkFmtPrint("X: %f, Y: %f, Z: %f",pC->m_fX, pC->m_fY, pC->m_fZ);
}
#endif
P_ProtocolManager->ReleaseProto(pProto);
}
HawkSleep(PROTO_TIME);
}
}
return 0;
}
示例10: while
void Session::Run()
{
Command cmd;
while (true)
{
mQueue.WaitAndPop(cmd);
if (cmd == START)
{
cmd = NO_CMD;
if (mTcpClient.Connect(mHostName, mTcpPort) == true)
{
Protocol proto;
while (mInitialized)
{
if (mTcpClient.DataWaiting(200U))
{
std::string payload;
if (mTcpClient.Recv(payload))
{
proto.Add(payload);
std::string data;
while (proto.Parse(data))
{
// TLogNetwork("Found one packet with data: " + data);
std::vector<Reply> out;
std::uint32_t client_uuid = proto.GetDestUuid();
bool ret = mListener.Deliver(proto.GetSourceUuid(), client_uuid, data, out);
// Send synchronous data to the server
if (ret)
{
Send(out);
}
}
}
}
else
{
//std::cout << "client wait timeout or failure" << std::endl;
mInitialized = IsConnected(); // determine origine of failure
}
}
mListener.Signal(net::IEvent::ErrDisconnectedFromServer);
TLogNetwork("Client connection closed.");
}
else
{
TLogError("Client cannot connect to server.");
mListener.Signal(net::IEvent::ErrCannotConnectToServer);
}
}
else if (cmd == EXIT)
{
std::cout << "Exit client thread" << std::endl;
return;
}
}
}
示例11: executeCommands
void Manager::executeCommands()
{
m_currentCommand = MaxCommand;
if(m_commands.isEmpty()) {
return;
}
m_currentCommand = m_commands.takeFirst();
Protocol protocol;
protocol.setStateOn(m_state.on);
protocol.setColor(m_state.color);
protocol.setRate(m_state.rate);
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
QString request = protocol.request2Str(m_currentCommand);
out << request;
Q_EMIT message(tr("Attempt sending request: ") + request);
m_tcpSocket->write(block);
if(m_tcpSocket->waitForBytesWritten()) {
Q_EMIT message(tr("Send successeful."));
} else {
Q_EMIT message(tr("Send failed."));
}
}
示例12: memcpy
Protocol* Protocol::decode(const char *bytes, int32_t len, bool decrypt)
{
int type;
memcpy(&type, bytes, sizeof(type));
bytes += sizeof(type);
len -= 4;
char *temp = new char[len];
if (decrypt)
{
rc4_state state;
rc4_init(&state, (const u_char *)INKEY.c_str(), INKEY.size());
rc4_crypt(&state, (const u_char *)bytes, (u_char *)temp, len);
}
else
{
memcpy(temp, bytes, len);
}
std::string plain(temp, len);
delete[] temp;
CCLOG("==== Client received:%s ====", plain.c_str());
Json::Reader reader;
Json::Value root;
if (!reader.parse(plain, root))
return NULL;
//int type = root["type"].asInt();
Protocol *p = Protocol::create(type);
if (p != NULL)
{
JsonStream stream(root);
p->decode(stream);
}
return p;
}
示例13: getMethods
int Device::getMethods() const {
Protocol *p = this->retrieveProtocol();
if (p) {
return p->methods();
}
return 0;
}
示例14: PluginCommand_GetMyNickname
static int PluginCommand_GetMyNickname(WPARAM wParam,LPARAM lParam)
{
char * ret = (char *)lParam;
char * proto = (char *)wParam;
if (ret == NULL)
return -1;
if (proto == NULL)
{
if (protocols->default_nick != NULL)
lstrcpyn(ret, protocols->default_nick, MS_MYDETAILS_GETMYNICKNAME_BUFFER_SIZE);
else
ret[0] = '\0';
}
else
{
Protocol protocol = GetProtocolByName(proto);
if (!protocol)
return -1;
lstrcpyn(ret, protocol.GetNick(), MS_MYDETAILS_GETMYNICKNAME_BUFFER_SIZE);
}
return 0;
}
示例15: connect_pair
inline boost::system::error_code connect_pair(
basic_socket<Protocol, SocketService1>& socket1,
basic_socket<Protocol, SocketService2>& socket2,
boost::system::error_code& ec)
{
// Check that this function is only being used with a UNIX domain socket.
boost::asio::local::basic_endpoint<Protocol>* tmp
= static_cast<typename Protocol::endpoint*>(0);
(void)tmp;
Protocol protocol;
boost::asio::detail::socket_type sv[2];
if (boost::asio::detail::socket_ops::socketpair(protocol.family(),
protocol.type(), protocol.protocol(), sv, ec)
== boost::asio::detail::socket_error_retval)
return ec;
if (socket1.assign(protocol, sv[0], ec))
{
boost::system::error_code temp_ec;
boost::asio::detail::socket_ops::close(sv[0], temp_ec);
boost::asio::detail::socket_ops::close(sv[1], temp_ec);
return ec;
}
if (socket2.assign(protocol, sv[1], ec))
{
boost::system::error_code temp_ec;
socket1.close(temp_ec);
boost::asio::detail::socket_ops::close(sv[1], temp_ec);
return ec;
}
return ec;
}