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


C++ poco::SharedPtr类代码示例

本文整理汇总了C++中poco::SharedPtr的典型用法代码示例。如果您正苦于以下问题:C++ SharedPtr类的具体用法?C++ SharedPtr怎么用?C++ SharedPtr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: forward

void LocalPortForwarder::forward(Poco::Net::StreamSocket& socket)
{
	if (_logger.debug())
	{
		_logger.debug(Poco::format("Local connection accepted, creating forwarding connection to %s, remote port %hu", _remoteURI.toString(), _remotePort));
	}
	try
	{
		std::string path(_remoteURI.getPathEtc());
		if (path.empty()) path = "/";
		Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, path, Poco::Net::HTTPRequest::HTTP_1_1);
		request.set(SEC_WEBSOCKET_PROTOCOL, WEBTUNNEL_PROTOCOL);
		request.set(X_WEBTUNNEL_REMOTEPORT, Poco::NumberFormatter::format(_remotePort));
		Poco::Net::HTTPResponse response;
		Poco::SharedPtr<Poco::Net::WebSocket> pWebSocket = _pWebSocketFactory->createWebSocket(_remoteURI, request, response);
		if (response.get(SEC_WEBSOCKET_PROTOCOL, "") != WEBTUNNEL_PROTOCOL)
		{
			_logger.error("The remote host does not support the WebTunnel protocol.");
			pWebSocket->shutdown(Poco::Net::WebSocket::WS_PROTOCOL_ERROR);
			pWebSocket->close();
			socket.close();
			return;
		}

		_pDispatcher->addSocket(socket, new StreamSocketToWebSocketForwarder(_pDispatcher, pWebSocket), _localTimeout);
		_pDispatcher->addSocket(*pWebSocket, new WebSocketToStreamSocketForwarder(_pDispatcher, socket), _remoteTimeout);
	}
	catch (Poco::Exception& exc)
	{
		_logger.error(Poco::format("Failed to open forwarding connection: %s", exc.displayText()));
		socket.close();
	}
}
开发者ID:JoneXie,项目名称:macchina.io,代码行数:33,代码来源:LocalPortForwarder.cpp


示例2: testCursorRequest

void MongoDBTest::testCursorRequest()
{
	Poco::MongoDB::Database db("team");
	Poco::SharedPtr<Poco::MongoDB::InsertRequest> insertRequest = db.createInsertRequest("numbers");
	for(int i = 0; i < 10000; ++i)
	{
		Document::Ptr doc = new Document();
		doc->add("number", i);
		insertRequest->documents().push_back(doc);
	}
	_mongo->sendRequest(*insertRequest);

	Poco::Int64 count = db.count(*_mongo, "numbers");
	assert(count == 10000);

	Poco::MongoDB::Cursor cursor("team", "numbers");

	int n = 0;
	Poco::MongoDB::ResponseMessage& response = cursor.next(*_mongo);
	while(1)
	{
		n += response.documents().size();
		if ( response.cursorID() == 0 )
			break;
		response = cursor.next(*_mongo);
	}
	assert(n == 10000);

	Poco::MongoDB::QueryRequest drop("team.$cmd");
	drop.setNumberToReturn(1);
	drop.selector().add("drop", std::string("numbers"));

	Poco::MongoDB::ResponseMessage responseDrop;
	_mongo->sendRequest(drop, responseDrop);
}
开发者ID:Kampbell,项目名称:poco,代码行数:35,代码来源:MongoDBTest.cpp


示例3: shutdownImpl

void WebEventServiceImpl::shutdownImpl(Poco::SharedPtr<Poco::Net::WebSocket> pWS, Poco::UInt16 statusCode, const std::string& statusMessage, bool passive)
{
    //_pContext->logger().notice("Shutting down WebSocket.");
    try
    {
        pWS->shutdown(statusCode, statusMessage);
    }
    catch (Poco::Exception& exc)
    {
        _pContext->logger().notice("Error while shutting down WebSocket: " + exc.displayText());
        passive = true; // don't wait for client confirmation
    }
    if (!passive)
    {
        if (pWS->poll(Poco::Timespan(WEBEVENT_SHUTDOWN_TIMEOUT, 0), Poco::Net::Socket::SELECT_READ))
        {
            Poco::Buffer<char> buffer(4096);
            int flags;
            pWS->receiveFrame(buffer.begin(), buffer.size(), flags);
            if (flags & Poco::Net::WebSocket::FRAME_OP_CLOSE)
            {
                pWS->close();
                return;
            }
        }
        _pContext->logger().notice("Client failed to confirm shutdown.");
    }
    pWS->close();
}
开发者ID:,项目名称:,代码行数:29,代码来源:


示例4: createQueryRequest

Poco::SharedPtr<Poco::MongoDB::QueryRequest> Database::createCountRequest(const std::string& collectionName) const
{
	Poco::SharedPtr<Poco::MongoDB::QueryRequest> request = createQueryRequest("$cmd");
	request->setNumberToReturn(1);
	request->selector().add("count", collectionName);
	return request;
}
开发者ID:Chingliu,项目名称:poco,代码行数:7,代码来源:Database.cpp


示例5: sample10

// SELECT DISTINCT birthyear FROM players WHERE birthyear > 1980
void sample10(Poco::MongoDB::Connection& connection)
{
	std::cout << "*** SAMPLE 10 ***" << std::endl;

	Poco::MongoDB::Database db("sample");
	Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = db.createCommand();

	command->selector()
		.add("distinct", "players")
		.add("key", "birthyear")
		.addNewDocument("query")
		.addNewDocument("birthyear")
		.add("$gt", 1980);

	Poco::MongoDB::ResponseMessage response;
	connection.sendRequest(*command, response);
	if ( response.hasDocuments() )
	{
		Poco::MongoDB::Array::Ptr values = response.documents()[0]->get<Poco::MongoDB::Array::Ptr>("values");
		for(int i = 0; i < values->size(); ++i )
		{
			std::cout << values->get<int>(i) << std::endl;
		}
	}

}
开发者ID:12307,项目名称:poco,代码行数:27,代码来源:SQLToMongo.cpp


示例6: listener

void WebController::listener()
{
	Poco::SharedPtr<MultiView> multiView = new MultiView("base.tpl");
	multiView->add("head", new TemplateView("listener/head.tpl"));
	multiView->add("main", new TemplateView("listener/index.tpl"));
	setView(multiView);
}
开发者ID:,项目名称:,代码行数:7,代码来源:


示例7: handleRequest

	void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
	{
		Application& app = Application::instance();
		try
		{			
			std::string proto = request.get("Sec-WebSocket-Protocol", "");
			Poco::SharedPtr<Poco::Net::WebSocket> pWebSocket;
			if (proto == "com.appinf.webtunnel.server/1.0")
			{
				response.set("Sec-WebSocket-Protocol", proto);
				pWebSocket = new Poco::Net::WebSocket(request, response);
				_portReflector.addServerSocket(pWebSocket, "ac9667bb-6032-4267-af61-9a7aafd40479");
			}
			else if (proto == "com.appinf.webtunnel.client/1.0")
			{
				response.set("Sec-WebSocket-Protocol", proto);
				std::string portStr = request.get("X-WebTunnel-RemotePort", "");
				unsigned port;
				if (!portStr.empty() && Poco::NumberParser::tryParseUnsigned(portStr, port) && port > 0 && port < 65536)
				{
					pWebSocket = new Poco::Net::WebSocket(request, response);
					try
					{
						_portReflector.addClientSocket(pWebSocket, "ac9667bb-6032-4267-af61-9a7aafd40479", static_cast<Poco::UInt16>(port));
					}
					catch (Poco::NotFoundException&)
					{
						pWebSocket->shutdown(Poco::Net::WebSocket::WS_UNEXPECTED_CONDITION, "No connection to target available");
					}
				}
				else
				{
					pWebSocket = new Poco::Net::WebSocket(request, response);
					pWebSocket->shutdown(Poco::Net::WebSocket::WS_UNEXPECTED_CONDITION, "Missing or invalid X-WebTunnel-RemotePort header");
				}
			}
			else
			{
				pWebSocket = new Poco::Net::WebSocket(request, response);
				pWebSocket->shutdown(Poco::Net::WebSocket::WS_PROTOCOL_ERROR);
			}
		}
		catch (WebSocketException& exc)
		{
			app.logger().log(exc);
			switch (exc.code())
			{
			case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION:
				response.set("Sec-WebSocket-Version", WebSocket::WEBSOCKET_VERSION);
				// fallthrough
			case Poco::Net::WebSocket::WS_ERR_NO_HANDSHAKE:
			case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_NO_VERSION:
			case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_NO_KEY:
				response.setStatusAndReason(HTTPResponse::HTTP_BAD_REQUEST);
				response.setContentLength(0);
				response.send();
				break;
			}
		}
	}
开发者ID:macchina-io,项目名称:macchina.io,代码行数:60,代码来源:WebTunnelReflector.cpp


示例8: consume

void MessageConsumer::consume(MQHCONN conn, MQMD* md, MQGMO* gmo, MQBYTE* buffer, MQCBC* context)
{
	Poco::SharedPtr<Message> msg = new Message(buffer, context->DataLength);
	memcpy(msg->md(), md, sizeof(MQMD));

	MessageConsumer* consumer = reinterpret_cast<MessageConsumer*>(context->CallbackArea);
	consumer->message.notify(consumer, msg);
}
开发者ID:,项目名称:,代码行数:8,代码来源:


示例9: addSubscriberImpl

void WebEventServiceImpl::addSubscriberImpl(Poco::SharedPtr<Poco::Net::WebSocket> pWS)
{
    Subscriber::Ptr pSubscriber = new Subscriber;
    pSubscriber->pWebSocket = pWS;
    _socketMap[*pWS] = pSubscriber;
    watchSocketImpl(*pWS);
    pWS->setSendTimeout(Poco::Timespan(WEBEVENT_SEND_TIMEOUT, 0));
    pWS->setReceiveTimeout(Poco::Timespan(WEBEVENT_RECEIVE_TIMEOUT, 0));
}
开发者ID:,项目名称:,代码行数:9,代码来源:


示例10: creds

Poco::Net::WebSocket* DefaultWebSocketFactory::createWebSocket(const Poco::URI& uri, Poco::Net::HTTPRequest& request, Poco::Net::HTTPResponse& response)
{
	Poco::SharedPtr<Poco::Net::HTTPClientSession> pSession = Poco::Net::HTTPSessionFactory::defaultFactory().createClientSession(uri);
	pSession->setTimeout(_timeout);
	if (!_username.empty())
	{
		Poco::Net::HTTPBasicCredentials creds(_username, _password);
		creds.authenticate(request);
	}
	return new Poco::Net::WebSocket(*pSession, request, response);
}
开发者ID:JoneXie,项目名称:macchina.io,代码行数:11,代码来源:LocalPortForwarder.cpp


示例11: sample13

//DELETE players WHERE firstname = 'Victor'
void sample13(Poco::MongoDB::Connection& connection)
{
	std::cout << "*** SAMPLE 13 ***" << std::endl;

	Poco::MongoDB::Database db("sample");
	Poco::SharedPtr<Poco::MongoDB::DeleteRequest> request = db.createDeleteRequest("players");
	request->selector().add("firstname", "Victor");

	connection.sendRequest(*request);

	Poco::MongoDB::Document::Ptr lastError = db.getLastErrorDoc(connection);
	std::cout << "LastError: " << lastError->toString(2) << std::endl;
}
开发者ID:12307,项目名称:poco,代码行数:14,代码来源:SQLToMongo.cpp


示例12: authenticateMongoCR

bool MongoAuthentication::authenticateMongoCR(const std::string &user, const std::string &pwd)
{
	bool ret = false;
	_user = user;
	_pwd = pwd;

	try {
		std::string nonce;
		Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = _db.createCommand();
		command->selector().add<Poco::Int32>("getnonce", 1);
		command->setNumberToReturn(1);

		Poco::MongoDB::ResponseMessage response;
		_conn.sendRequest(*command, response);

		if (response.documents().size() > 0) {
			Poco::MongoDB::Document::Ptr doc = response.documents()[0];
			nonce = doc->get<std::string>("nonce", "");

			std::string password = _user + ":mongo:" + _pwd;

			Poco::MD5Engine md5;
			md5.update(password);
			std::string hashedPassword(Poco::DigestEngine::digestToHex(md5.digest()));
			std::string key = nonce + _user + hashedPassword;
			md5.reset();
			md5.update(key);
			std::string hashedKey(Poco::DigestEngine::digestToHex(md5.digest()));


			Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = _db.createCommand();
			command->selector()
				.add<Poco::Int32>("authenticate", 1)
				.add<std::string>("user", _user)
				.add<std::string>("nonce", nonce)
				.add<std::string>("key", hashedKey);      // hex_md5( n.nonce + username + hex_md5( username + ":mongo:" + password ) )

			_conn.sendRequest(*command, response);

			if (response.documents().size() > 0 && response.documents()[0]->get<double>("ok")) {
				ret = true;
			}
		}
	} catch (Poco::Exception &) {
		throw Poco::ApplicationException("auth failed.");
	}

	return ret;
}
开发者ID:TigerLau1985,项目名称:MongoAuthentication,代码行数:49,代码来源:MongoAuthentication.cpp


示例13: UpdateUISetting

void CLogAnalyzerView::UpdateUISetting()
{
    if (!m_logger->GetActiveUISetting().isNull())
    {
        tstring strSettingName = m_logger->GetActiveUISetting()->getName();
        CLogAnalyzerApp* app = (CLogAnalyzerApp*)AfxGetApp();
        if (app != NULL)
        {
            Poco::SharedPtr<CUISetting> currentSelSetting = app->GetUISetting(strSettingName);
            if (!currentSelSetting.isNull())
                m_logger->SetActiveUISetting(currentSelSetting);
        }
    }
    
}
开发者ID:yanjunnf,项目名称:LogAnalyzer,代码行数:15,代码来源:LogAnalyzerView.cpp


示例14: ShowTraces

void CLogAnalyzerView::ShowTraces(const CString& strComponent, BOOL bShowAll)
{
    tstring strItemText = strComponent;
    const std::map<tstring, Poco::SharedPtr<CComponent>>& components = m_logger->GetComponents();
    std::map<tstring, Poco::SharedPtr<CComponent>>::const_iterator ite = components.find(strItemText);
    if (ite != components.end())
    {
        const std::vector<Poco::SharedPtr<CTraceLog>>& traceLogs = ite->second->GetTraceLogs();
        if (bShowAll)
        {
            //Only show the traces you want in list control
            m_traceList.DeleteAllTraceLog();
            for (int i = 0; i < traceLogs.size(); ++i)
                m_traceList.InsertTraceLog(traceLogs.at(i));
        }
        //Show all traces and go to the first trace log that fits to you want
        else
        {
            Poco::SharedPtr<CUISetting> uiSetting = m_logger->GetActiveUISetting();
            int nColumn = 0;
            int nCurSel = m_comboColumns.GetCurSel();
            if (nCurSel == 0)
                nColumn = -1; //All
            else
            {
                CString strItem;
                m_comboColumns.GetLBText(nCurSel, strItem);
                tstring strItemValue = strItem.GetBuffer(strItem.GetLength());
                if (!uiSetting.isNull())
                {
                    for (int i = 0; i < uiSetting->GetAllColumns().size(); ++i)
                    {
                        if (strItemValue == uiSetting->GetAllColumns().at(i)->m_strRealColumnName)
                        {
                            nColumn = i;
                            break;
                        }
                    }
                }
            }

            m_traceList.SearchText(nColumn, m_strFindContent.GetBuffer(m_strFindContent.GetLength()), m_bMatchCase);
        }
        m_strCurrentPage.Format("%d", m_traceList.GetCurrentPage());
        m_strTraceCount.Format("Total : %d", m_traceList.GetCount());
        UpdateData(FALSE);
    }
}
开发者ID:yanjunnf,项目名称:LogAnalyzer,代码行数:48,代码来源:LogAnalyzerView.cpp


示例15: testCursorRequest

void MongoDBTest::testCursorRequest()
{
	if (!_connected)
	{
		std::cout << "Not connected, test skipped." << std::endl;
		return;
	}

	Poco::MongoDB::Database db("team");
	Poco::SharedPtr<Poco::MongoDB::InsertRequest> insertRequest = db.createInsertRequest("numbers");
	for(int i = 0; i < 10000; ++i)
	{
		Document::Ptr doc = new Document();
		doc->add("number", i);
		insertRequest->documents().push_back(doc);
	}
	_mongo.sendRequest(*insertRequest);

	double count = db.count(_mongo, "numbers");
	assert(count == 10000);

	Poco::MongoDB::Cursor cursor("team", "numbers");

	int n = 0;
	Poco::MongoDB::ResponseMessage& response = cursor.next(_mongo);
	while(1)
	{
		n += response.documents().size();
		if ( response.cursorID() == 0 )
			break;
		response = cursor.next(_mongo);
	}
	std::cout << "n= " << n << std::endl;
	assert(n == 10000);

	Poco::MongoDB::QueryRequest drop("team.$cmd");
	drop.setNumberToReturn(1);
	drop.selector().add("drop", std::string("numbers"));

	Poco::MongoDB::ResponseMessage responseDrop;
	_mongo.sendRequest(drop, responseDrop);

	if ( responseDrop.documents().size() > 0 )
	{
		std::cout << responseDrop.documents()[0]->toString(2) << std::endl;
	}
}
开发者ID:12307,项目名称:poco,代码行数:47,代码来源:MongoDBTest.cpp


示例16: createGNSSSensor

	void createGNSSSensor(Poco::SharedPtr<Poco::Serial::SerialPort> pSerialPort)
	{
		typedef Poco::RemotingNG::ServerHelper<IoT::Devices::GNSSSensor> ServerHelper;
		
		Poco::SharedPtr<GNSSSensorImpl> pGNSSSensor = new GNSSSensorImpl(pSerialPort);
		std::string type = pGNSSSensor->getPropertyString("type");
		Poco::RemotingNG::Identifiable::ObjectId oid = pGNSSSensor->getPropertyString("symbolicName");
		oid += "#0";
		ServerHelper::RemoteObjectPtr pGNSSSensorRemoteObject = ServerHelper::createRemoteObject(pGNSSSensor, oid);
		
		Properties props;
		props.set("io.macchina.deviceType", type);
		props.set("io.macchina.device", oid);
		props.set("io.macchina.serialport.device", pSerialPort->device());
		
		_serviceRef = _pContext->registry().registerService(oid, pGNSSSensorRemoteObject, props);
	}
开发者ID:jacklicn,项目名称:macchina.io,代码行数:17,代码来源:BundleActivator.cpp


示例17: createConnection

ConnectionBasePtr TransferNode::createConnection(const PacketBasePtr &packet_base, const EndPoint &ep) {
	PacketHeader::PACKET_ID_TYPE packet_id = packet_base->header.getPacketID();
	if (packet_id == OpenConnection_ID) {
		INFO_LOG("Server: new connection from: " << ep.toString());
		Poco::SharedPtr<OpenConnectionPacket> packet = packet_base.cast<OpenConnectionPacket>();
		assert(packet.get());
		ConnectionBasePtr pConn(new ServerConnection(packet->OpenConnection.Code, ep, this->packet_serializer, *this));
		return pConn;
	} else if (packet_id == OpenConnectionReply_ID) {
		INFO_LOG("Client: new connection to: " << ep.toString());
		Poco::SharedPtr<OpenConnectionReplyPacket> packet = packet_base.cast<OpenConnectionReplyPacket>();
		ConnectionBasePtr pConn(new ClientConnection(packet->OpenConnectionReply.Code, ep, this->packet_serializer, *this));
		return pConn;
	} else {
		throw Poco::ApplicationException("unexpected packet type: ", packet_base->header.getPacketID()); // TODO @@@ ???
	}
}
开发者ID:lulurun,项目名称:fanni,代码行数:17,代码来源:TransferNode.cpp


示例18: createSerialDevice

	void createSerialDevice(const std::string& uid, SerialDeviceImpl::SerialPortPtr pSerialPort)
	{
		typedef Poco::RemotingNG::ServerHelper<IoT::Devices::SerialDevice> ServerHelper;
		
		Poco::SharedPtr<IoT::Devices::SerialDevice> pDevice = new SerialDeviceImpl(pSerialPort);
		std::string symbolicName = pDevice->getPropertyString("symbolicName");
		Poco::RemotingNG::Identifiable::ObjectId oid = symbolicName;
		oid += '#';
		oid += uid;
		ServerHelper::RemoteObjectPtr pDeviceRemoteObject = ServerHelper::createRemoteObject(pDevice, oid);
		
		Properties props;
		props.set("io.macchina.device", oid);
		props.set("io.macchina.serialport.device", pSerialPort->device());
		
		ServiceRef::Ptr pServiceRef = _pContext->registry().registerService(oid, pDeviceRemoteObject, props);
		_serviceRefs.push_back(pServiceRef);
	}
开发者ID:JoneXie,项目名称:macchina.io,代码行数:18,代码来源:BundleActivator.cpp


示例19: getLastErrorDoc

Document::Ptr Database::getLastErrorDoc(Connection& connection) const
{
	Document::Ptr errorDoc;

	Poco::SharedPtr<Poco::MongoDB::QueryRequest> request = createQueryRequest("$cmd");
	request->setNumberToReturn(1);
	request->selector().add("getLastError", 1);

	Poco::MongoDB::ResponseMessage response;
	connection.sendRequest(*request, response);

	if ( response.documents().size() > 0 )
	{
		errorDoc = response.documents()[0];
	}

	return errorDoc;
}
开发者ID:Chingliu,项目名称:poco,代码行数:18,代码来源:Database.cpp


示例20: sample11

// SELECT COUNT(*) FROM players WHERE birthyear > 1980
void sample11(Poco::MongoDB::Connection& connection)
{
	std::cout << "*** SAMPLE 11 ***" << std::endl;

	Poco::MongoDB::Database db("sample");
	Poco::SharedPtr<Poco::MongoDB::QueryRequest> count = db.createCountRequest("players");
	count->selector().addNewDocument("query")
		.addNewDocument("birthyear")
			.add("$gt", 1980);

	Poco::MongoDB::ResponseMessage response;
	connection.sendRequest(*count, response);

	if ( response.hasDocuments() )
	{
		std::cout << "Count: " << response.documents()[0]->get<double>("n") << std::endl;
	}
}
开发者ID:12307,项目名称:poco,代码行数:19,代码来源:SQLToMongo.cpp



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