本文整理汇总了C++中shared_from_this函数的典型用法代码示例。如果您正苦于以下问题:C++ shared_from_this函数的具体用法?C++ shared_from_this怎么用?C++ shared_from_this使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了shared_from_this函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TcpConnection
void my::GateServer::handle_accept(ConnectionPtr conn, boost::system::error_code err)
{
if (err)
{
LogE << err.message() << LogEnd;
conn->getSocket().close();
ConnectionPtr nextConn = boost::shared_ptr<TcpConnection>(new TcpConnection(core.getService(), m_GateHandler, shared_from_this()));
m_pAcceptor->async_accept(nextConn->getSocket(), boost::bind(&GateServer::handle_accept, this, nextConn, boost::asio::placeholders::error));
}
else
{
//new incomming player!!!
LogD << conn->getSocket().remote_endpoint().address() << " " << conn->getSocket().remote_endpoint().port() << LogEnd;
boost::recursive_mutex::scoped_lock lock(mtx);
conn->setNetId(m_nNetIdHolder);
ip::tcp::no_delay option(true);
conn->getSocket().set_option(option);
m_ConnMap.insert(std::make_pair<int, ConnectionPtr>(m_nNetIdHolder, conn));
conn->start();
m_nNetIdHolder = (m_nNetIdHolder + 1) % MAX_NET_ID;
m_nConnCount++;
ConnectionPtr nextConn = boost::shared_ptr<TcpConnection>(new TcpConnection(core.getService(), m_GateHandler, shared_from_this()));
m_pAcceptor->async_accept(nextConn->getSocket(), boost::bind(&GateServer::handle_accept, this, nextConn, boost::asio::placeholders::error));
}
}
示例2: FilterImpl
CrowdDetectorFilterImpl::CrowdDetectorFilterImpl (
const std::vector<std::shared_ptr<RegionOfInterest>> &rois,
std::shared_ptr< MediaObjectImpl > parent) :
FilterImpl (parent)
{
GstBus *bus;
std::shared_ptr<MediaPipelineImpl> pipe;
GstStructure *roisStructure;
pipe = std::dynamic_pointer_cast<MediaPipelineImpl> (getMediaPipeline() );
g_object_set (element, "filter-factory", "crowddetector", NULL);
bus = gst_pipeline_get_bus (GST_PIPELINE (pipe->getPipeline() ) );
g_object_get (G_OBJECT (element), "filter", &crowdDetector, NULL);
if (crowdDetector == NULL) {
g_object_unref (bus);
throw KurentoException (MEDIA_OBJECT_NOT_AVAILABLE,
"Media Object not available");
}
roisStructure = gst_structure_new_empty ("Rois");
for (auto roi : rois) {
GstStructure *roiStructureAux = get_structure_from_roi (roi);
gst_structure_set (roisStructure,
roi->getId().c_str(), GST_TYPE_STRUCTURE,
roiStructureAux,
NULL);
gst_structure_free (roiStructureAux);
}
g_object_set (G_OBJECT (crowdDetector), ROIS_PARAM, roisStructure, NULL);
gst_structure_free (roisStructure);
busMessageLambda = [&] (GstMessage * message) {
const GstStructure *st;
gchar *roiID;
const gchar *type;
std::string roiIDStr, typeStr;
if (GST_MESSAGE_SRC (message) != GST_OBJECT (crowdDetector) ||
GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT) {
return;
}
st = gst_message_get_structure (message);
type = gst_structure_get_name (st);
if (!gst_structure_get (st, "roi", G_TYPE_STRING , &roiID, NULL) ) {
GST_WARNING ("The message does not contain the roi ID");
return;
}
roiIDStr = roiID;
typeStr = type;
g_free (roiID);
if (typeStr == "fluidity-event") {
double fluidity_percentage;
int fluidity_level;
if (! (gst_structure_get (st, "fluidity_percentage", G_TYPE_DOUBLE,
&fluidity_percentage, NULL) ) ) {
GST_WARNING ("The message does not contain the fluidity percentage");
return;
}
if (! (gst_structure_get (st, "fluidity_level", G_TYPE_INT,
&fluidity_level, NULL) ) ) {
GST_WARNING ("The message does not contain the fluidity level");
return;
}
try {
CrowdDetectorFluidity event (fluidity_percentage, fluidity_level, roiIDStr,
shared_from_this(),
CrowdDetectorFluidity::getName() );
signalCrowdDetectorFluidity (event);
} catch (std::bad_weak_ptr &e) {
}
} else if (typeStr == "occupancy-event") {
double occupancy_percentage;
int occupancy_level;
if (! (gst_structure_get (st, "occupancy_percentage", G_TYPE_DOUBLE,
&occupancy_percentage, NULL) ) ) {
GST_WARNING ("The message does not contain the occupancy percentage");
return;
}
if (! (gst_structure_get (st, "occupancy_level", G_TYPE_INT,
&occupancy_level, NULL) ) ) {
//.........这里部分代码省略.........
示例3: forwardProperty
void Node::forwardProperty(int ourProperty, std::shared_ptr<Node> toNode, int toProperty) {
forwarded_properties[ourProperty] = std::make_tuple(toNode, toProperty);
toNode->addPropertyBackref(toProperty, std::static_pointer_cast<Node>(shared_from_this()), ourProperty);
simulation->invalidatePlan();
}
示例4:
std::shared_ptr<base::IBlock> BlockFS::block() const {
return std::const_pointer_cast<BlockFS>(shared_from_this());
}
示例5:
neb::fnd::app::Base * const THIS::get_fnd_app()
{
auto a = std::dynamic_pointer_cast<neb::fnd::app::Base>(shared_from_this());
return a.get();
}
示例6: plugin_tkn
//.........这里部分代码省略.........
std::vector<OSG::FieldContainerType*> core_types;
const unsigned int num_types = model_elt->getNum(core_type_tkn);
for ( unsigned int t = 0; t < num_types; ++t )
{
const std::string type_name =
model_elt->getProperty<std::string>(core_type_tkn, i);
OSG::FieldContainerType* fct =
OSG::FieldContainerFactory::the()->findType(
type_name.c_str()
);
if ( NULL != fct )
{
core_types.push_back(fct);
}
else
{
VRKIT_STATUS << "Skipping unknown type '" << type_name
<< "'" << std::endl;
}
}
DynamicSceneObjectPtr scene_obj;
if ( ! core_types.empty() )
{
util::CoreTypePredicate pred(core_types);
scene_obj = DynamicSceneObject::create()->init(model_node,
pred, true);
}
else
{
scene_obj =
DynamicSceneObjectTransform::create()->init(model_node);
}
// scene_obj's root will be added as a child of
// scene_xform_root.
child_root = scene_obj->getRoot();
scene_obj->moveTo(xform_mat_osg);
viewer->addObject(scene_obj);
}
// If this model is not supposed to be grabbable, we examine the
// core of the root node.
else
{
OSG::NodeCorePtr root_core = model_node->getCore();
OSG::TransformPtr xform_core =
#if OSG_MAJOR_VERSION < 2
OSG::TransformPtr::dcast(root_core);
#else
OSG::cast_dynamic<OSG::TransformPtr>(root_core);
#endif
// If model_node's core is of type OSG::Transform, then we set
// set the matrix on that core to be xform_mat_osg.
if ( OSG::NullFC != xform_core )
{
#if OSG_MAJOR_VERSION < 2
OSG::CPEditor xce(xform_core, OSG::Transform::MatrixFieldMask);
#endif
xform_core->setMatrix(xform_mat_osg);
// model_node will be added as a child of scene_xform_root.
child_root = model_node;
}
// If model_node's core is not of type OSG::Transform, then we
// need to make a new node with an OSG::Transform core and make
// it the parent of model_node.
else
{
OSG::TransformNodePtr xform_node(OSG::Transform::create());
#if OSG_MAJOR_VERSION < 2
OSG::CPEditor xnce(xform_node.core(),
OSG::Transform::MatrixFieldMask);
#endif
xform_node->setMatrix(xform_mat_osg);
#if OSG_MAJOR_VERSION < 2
OSG::CPEditor xne(xform_node.node(),
OSG::Node::ChildrenFieldMask);
#endif
xform_node.node()->addChild(model_node);
// xform_node will be added as a child of scene_xform_root.
child_root = xform_node.node();
}
}
vprASSERT(child_root != OSG::NullFC);
// The OSG::{begin,end}EditCP() calls for scene_xform_root wrap
// the for loop that we are in.
scene_xform_root.node()->addChild(child_root);
}
}
return shared_from_this();
}
示例7: getName
bool Subscription::negotiateConnection(const std::string& xmlrpc_uri)
{
XmlRpcValue tcpros_array, protos_array, params;
XmlRpcValue udpros_array;
ros::TransportUDPPtr udp_transport;
int protos = 0;
ros::V_string transports = transport_hints_.getTransports();
if (transports.empty())
{
transport_hints_.reliable();
transports = transport_hints_.getTransports();
}
for (ros::V_string::const_iterator it = transports.begin();
it != transports.end();
++it)
{
if (*it == "UDP")
{
int max_datagram_size = transport_hints_.getMaxDatagramSize();
udp_transport = ros::TransportUDPPtr(new ros::TransportUDP(&ros::PollManager::instance()->getPollSet()));
if (!max_datagram_size)
max_datagram_size = udp_transport->getMaxDatagramSize();
udp_transport->createIncoming(0, false);
udpros_array[0] = "UDPROS";
M_string m;
m["topic"] = getName();
m["md5sum"] = md5sum();
m["callerid"] = ros::this_node::getName();
m["type"] = datatype();
boost::shared_array<uint8_t> buffer;
uint32_t len;
ros::Header::write(m, buffer, len);
XmlRpcValue v(buffer.get(), len);
udpros_array[1] = v;
udpros_array[2] = ros::network::getHost();
udpros_array[3] = udp_transport->getServerPort();
udpros_array[4] = max_datagram_size;
protos_array[protos++] = udpros_array;
}
else if (*it == "TCP")
{
tcpros_array[0] = std::string("TCPROS");
protos_array[protos++] = tcpros_array;
}
else
{
ROS_WARN("Unsupported transport type hinted: %s, skipping", it->c_str());
}
}
params[0] = ros::this_node::getName();
params[1] = name_;
params[2] = protos_array;
std::string peer_host;
uint32_t peer_port;
if (!ros::network::splitURI(xmlrpc_uri, peer_host, peer_port))
{
ROS_ERROR("Bad xml-rpc URI: [%s]", xmlrpc_uri.c_str());
return false;
}
XmlRpcClient* c = new XmlRpcClient(peer_host.c_str(),
peer_port, "/");
// if (!c.execute("requestTopic", params, result) || !g_node->validateXmlrpcResponse("requestTopic", result, proto))
// Initiate the negotiation. We'll come back and check on it later.
if (!c->executeNonBlock("requestTopic", params))
{
ROSCPP_LOG_DEBUG("Failed to contact publisher [%s:%d] for topic [%s]",
peer_host.c_str(), peer_port, name_.c_str());
delete c;
if (udp_transport)
{
udp_transport->close();
}
return false;
}
ROSCPP_LOG_DEBUG("Began asynchronous xmlrpc connection to [%s:%d]", peer_host.c_str(), peer_port);
// The PendingConnectionPtr takes ownership of c, and will delete it on
// destruction.
PendingConnectionPtr conn(new PendingConnection(c, udp_transport, shared_from_this(), xmlrpc_uri));
//ROS_INFO("add connection to xmlrpcmanager");
XMLRPCManager::instance()->addASyncConnection(conn);
// Put this connection on the list that we'll look at later.
{
boost::mutex::scoped_lock pending_connections_lock(pending_connections_mutex_);
pending_connections_.insert(conn);
}
return true;
}
示例8: be
CameraPtr Camera::init()
{
// Create a transform to contain the location and orientation of the camera.
mTransform = OSG::Transform::create();
OSG::NodePtr beacon = OSG::Node::create();
#if OSG_MAJOR_VERSION < 2
OSG::CPEditor be(beacon, OSG::Node::CoreFieldMask);
#endif
beacon->setCore(mTransform);
mLeftTexture = tex_chunk_t::create();
#if OSG_MAJOR_VERSION < 2
OSG::CPEditor lte(mLeftTexture);
mLeftTexture->setEnvMode(GL_MODULATE);
#else
mLeftTexEnv = OSG::TextureEnvChunk::create();
mLeftTexEnv->setEnvMode(GL_MODULATE);
#endif
mRightTexture = tex_chunk_t::create();
#if OSG_MAJOR_VERSION < 2
OSG::CPEditor rte(mRightTexture);
mRightTexture->setEnvMode(GL_MODULATE);
#else
mRightTexEnv = OSG::TextureEnvChunk::create();
mRightTexEnv->setEnvMode(GL_MODULATE);
#endif
mCurrentTexture = mLeftTexture;
#if OSG_MAJOR_VERSION >= 2
mCurrentTexEnv = mLeftTexEnv;
#endif
// setup camera
mCamera = OSG::PerspectiveCamera::create();
#if OSG_MAJOR_VERSION < 2
OSG::CPEditor ce(mCamera);
#endif
mCamera->setFov(
#if OSG_MAJOR_VERSION < 2
OSG::osgdegree2rad(60.0)
#else
OSG::osgDegree2Rad(60.0)
#endif
);
mCamera->setNear(0.01);
mCamera->setFar(10000);
mCamera->setBeacon(beacon);
mLeftImage = OSG::Image::create();
mRightImage = OSG::Image::create();
OSG::ImagePtr img;
// Set up FBO textures.
img = mLeftImage;
mLeftTexture->setMinFilter(GL_LINEAR);
mLeftTexture->setMagFilter(GL_LINEAR);
mLeftTexture->setTarget(GL_TEXTURE_2D);
mLeftTexture->setInternalFormat(GL_RGBA8);
mLeftTexture->setImage(img);
img = mRightImage;
mRightTexture->setMinFilter(GL_LINEAR);
mRightTexture->setMagFilter(GL_LINEAR);
mRightTexture->setTarget(GL_TEXTURE_2D);
mRightTexture->setInternalFormat(GL_RGBA8);
mRightTexture->setImage(img);
mCurrentImage = mLeftImage;
return shared_from_this();
}
示例9: QueryProvider
void SuggestionsSidebarBlock::QueryProvider(SuggestionsBackend& backend, const CatalogItemPtr& item, uint64_t queryId)
{
m_pendingQueries++;
// we need something to talk to GUI thread through that is guaranteed
// to exist, and the app object is a good choice:
auto backendPtr = &backend;
std::weak_ptr<SuggestionsSidebarBlock> weakSelf = std::dynamic_pointer_cast<SuggestionsSidebarBlock>(shared_from_this());
m_provider->SuggestTranslation
(
backend,
m_parent->GetCurrentSourceLanguage(),
m_parent->GetCurrentLanguage(),
item->GetString().ToStdWstring(),
// when receiving data
[=](const SuggestionsList& hits){
call_on_main_thread([weakSelf,queryId,hits]{
auto self = weakSelf.lock();
// maybe this call is already out of date:
if (!self || self->m_latestQueryId != queryId)
return;
self->UpdateSuggestions(hits);
if (--self->m_pendingQueries == 0)
self->OnQueriesFinished();
});
},
// on error:
[=](std::exception_ptr e){
call_on_main_thread([weakSelf,queryId,backendPtr,e]{
auto self = weakSelf.lock();
// maybe this call is already out of date:
if (!self || self->m_latestQueryId != queryId)
return;
self->ReportError(backendPtr, e);
if (--self->m_pendingQueries == 0)
self->OnQueriesFinished();
});
}
);
}
示例10: AddPlayList
void PlayListFolder::AddPlayList(boost::shared_ptr<PlayListElement> playList) {
playList->SetParent(shared_from_this());
playlists_.push_back(playList);
}
示例11: IDatabaseSPtr
IDatabaseSPtr RedisServer::createDatabase(IDataBaseInfoSPtr info) {
return IDatabaseSPtr(new RedisDatabase(shared_from_this(), info));
}
示例12: shared_from_this
StructuredScript::Interfaces::Node::Ptr StructuredScript::Nodes::EchoNode::ptr(){
return shared_from_this();
}
示例13: serverPtr
void my::GateServer::init()
{
boost::shared_ptr<TcpServer> serverPtr(this); //make sure that shared_from_this() can run perfectly ok!
Json::Value gateConf = util::fileSystem::loadJsonFileEval(jsonconf::server_config);
if (gateConf == Json::nullValue)
{
LogW << "Error init GateServer, null gateConf" << LogEnd;
return;
}
//初始化httpSvr
{
m_HttpServerPtr = HttpServerPtr(new http::HttpServer());
m_HttpServerPtr->init(gateConf);
m_HttpServerPtr->run();
}
m_GateConf = gateConf;
int port = gateConf["gateSvrPort"].asInt();
std::string gameSvrIp = gateConf["gameSvrIp"].asString();
int gameSvrPort = gateConf["gameSvrPort"].asInt();
std::string accountSvrIp = gateConf["accountSvrIp"].asString();
int accountSvrPort = gateConf["accountSvrPort"].asInt();
m_nConnCount = 0;
m_nNetIdHolder = 0;
m_pEndpoint = EndpointPtr(new boost::asio::ip::tcp::endpoint(ip::tcp::v4(), port));
m_pAcceptor = AcceptorPtr(new boost::asio::ip::tcp::acceptor(core.getService(), *m_pEndpoint));
m_GateHandler = boost::shared_ptr<GateHandler>(new GateHandler());
ConnectionPtr nextConn = boost::shared_ptr<TcpConnection>(new TcpConnection(core.getService(), m_GateHandler, shared_from_this()));
m_pAcceptor->async_accept(nextConn->getSocket(), boost::bind(&GateServer::handle_accept, this, nextConn, boost::asio::placeholders::error));
connectToGameSvr(gameSvrIp, gameSvrPort);
connectToAccountSvr(accountSvrIp, accountSvrPort);
LogD << "Init Gate Server Ok!!!" << LogEnd;
update();
}
示例14: temp
void CShips::Retreat(const CPoint& ptRetreatSector, COMBAT_TACTIC::Typ const* NewCombatTactic)
{
NotifySector temp(shared_from_this());
CShip::Retreat(ptRetreatSector, NewCombatTactic);
}
示例15: collidedBy
void Player::collidedBy(std::shared_ptr<Actor> a) {
a->collideWith(std::static_pointer_cast<Player>(shared_from_this()));
}