示例#1
0
void dump_wptr(void){
	std::cout<<"sptr1 "<<sptr1.get()<<" use_count() "<<sptr1.use_count()<<" unique() "<<sptr1.unique()<<std::endl;
	std::cout<<"sptr2 "<<sptr2.get()<<" use_count() "<<sptr2.use_count()<<" unique() "<<sptr2.unique()<<std::endl;
	std::cout<<"weak ptr1 "<<wptr1.lock().get()<<std::endl;
	std::cout<<"weak ptr2 "<<wptr2.lock().get()<<std::endl;
	std::cout<<"weak ptr3 "<<wptr3.lock().get()<<std::endl;
}
void weak_shared(
    boost::weak_ptr<FIRST>& first, 
    boost::shared_ptr<SECOND>& second
){
    const char * testfile = boost::archive::tmpnam(NULL);
    BOOST_REQUIRE(NULL != testfile);
    int firstm = first.lock()->m_x;
    int secondm = second->m_x;
    save2(testfile, first, second);

    // Clear the pointers, thereby destroying the objects they contain
    first.reset();
    second.reset();

    load2(testfile, first, second);

    // Check data member
    BOOST_CHECK(firstm == first.lock()->m_x);
    BOOST_CHECK(secondm == second->m_x);
    // Check pointer to vtable
    BOOST_CHECK(boost::dynamic_pointer_cast<Sub>(first.lock()));
    BOOST_CHECK(boost::dynamic_pointer_cast<Sub>(second));

    std::remove(testfile);
}
示例#3
0
bool substreamTruncate(boost::weak_ptr<stream::sub> w_sub,
	boost::weak_ptr<stream::seg> w_parent, int len)
{
	stream::sub_sptr sub = w_sub.lock();
	if (!sub) return false;
	stream::seg_sptr parent = w_parent.lock();
	if (!parent) return false;

	stream::pos off = sub->get_offset();
	stream::pos oldLen = sub->size();
	// Enlarge the end of the substream (in the parent)
	stream::delta delta = len - oldLen;
	stream::pos orig = parent->tellp();
	try {
		if (delta < 0) {
			// TODO: untested
			parent->seekp(off + oldLen + delta, stream::start);
			parent->remove(-delta);
		} else {
			parent->seekp(off + oldLen, stream::start);
			parent->insert(delta);
		}
		// Update the substream with its new size
		sub->resize(len);
	} catch (stream::error& e) {
		std::cerr << "Error resizing substream: " << e.what() << std::endl;
		return false;
	}
	parent->seekp(orig, stream::start);
	return true;
}
示例#4
0
/// Convenient access to the variable manager
PhysModel& physical_model()
{
  static boost::weak_ptr<PhysModel> model;
  if(!model.lock())
    model = Core::instance().root().create_component_ptr<DynamicModel>("PhysicalModel");

  return *model.lock();
}
示例#5
0
Level::Level(boost::weak_ptr<Engine> engine) : 
_tileSheetManager(engine.lock()->GetTileSheetManager()),
	_gameObjectManager(engine.lock()->GetGameObjectManager()),
	_physicsManager(engine.lock()->GetPhysicsManager()),
	_InputManager(engine.lock()->GetInputManager()),
	_engine(engine)
{

}
示例#6
0
ProcessResult GetDisco::blockArrived(JabberDataBlockRef block, const ResourceContextRef rc){
    ServiceDiscovery::ref sd=vf.lock();
    if (!sd) return CANCEL;

    if (block->getAttribute("id")==idinfo) {
        if (block->getAttribute("type")=="result") {
            sd->infoReply=block->findChildNamespace("query", "http://jabber.org/protocol/disco#info");
        } else {
            if (block->getAttribute("type")=="error") {
                sd->infoReply=block->getChildByName("error");
            }
        }
        SendMessage(sd->getHWnd(), WM_NOTIFY_BLOCKARRIVED, 0,0);
        return BLOCK_PROCESSED;
    }
    if (block->getAttribute("id")==iditems) {
        if (block->getAttribute("type")=="result") {
            sd->itemReply=block->findChildNamespace("query", "http://jabber.org/protocol/disco#items");
        } else {
            if (block->getAttribute("type")=="error") {
                sd->itemReply=block->getChildByName("error");
            }
        }
        SendMessage(sd->getHWnd(), WM_NOTIFY_BLOCKARRIVED, 0,0);
        return LAST_BLOCK_PROCESSED;
    }

    return BLOCK_REJECTED;
}
示例#7
0
void DiscoListView::eventOk() {
    ServiceDiscovery::ref sd=serviceDiscovery.lock();
    if (!sd) return;
    
    DiscoItem::ref c=boost::dynamic_pointer_cast<DiscoItem> (cursorPos);
    if (c) {
        sd->discoverJid(c->jid, c->node);
        sd->go();
        return;
    }

    DiscoCommand::ref dc=boost::dynamic_pointer_cast<DiscoCommand> (cursorPos);
    if (dc) {
        switch (dc->cmdId) {
        case DiscoCommand::BACK: 
            sd->back();
            return;
        case DiscoCommand::VCARD:
            sd->vcard();
            return;
        case DiscoCommand::JOINGC:
            sd->joingc();
            return;
        case DiscoCommand::EXECUTE:
            sd->execute();
            return;
        case DiscoCommand::REGISTER:
            sd->registerForm();
        }
    }
    VirtualListView::eventOk();
}
示例#8
0
文件: Loader.cpp 项目: jcayzac/Mini3D
boost::shared_ptr<Loader> Loader::instance() {
	static boost::weak_ptr<Loader> _instance;
	if(boost::shared_ptr<Loader> r = _instance.lock()) return r;
	boost::shared_ptr<Loader> x(new (nothrow) Loader);
	_instance = x;
	return x;
}
示例#9
0
	void runInThread()
	{
		pid_t tid =	gettid();

		boost::shared_ptr<pid_t> ptid = wkTid_.lock();
		if (ptid)
		{
			*ptid = tid;
			ptid.reset();
		}

		Rabbit::CurrentThread::t_threadName = name_.empty() ? "RabbitThread" : name_.c_str();
		try
		{
			func_();
			Rabbit::CurrentThread::t_threadName = "finished";
		}
		catch (...)
		{
			Rabbit::CurrentThread::t_threadName = "crashed";
			fprintf(stderr, "some exception caught in Thread %s\n", name_.c_str());
			perror("");
			abort();
		}
	}
示例#10
0
文件: Thread.cpp 项目: tonyw/Core
    void runInThread()
    {
        pid_t tid = pai::concurrency::CurrentThread::tid();

        boost::shared_ptr<pid_t> ptid = wkTid_.lock();
        if (ptid)
        {
            *ptid = tid;
            ptid.reset();
        }

        pai::concurrency::CurrentThread::t_threadName = name_.empty() ? "paiThread" : name_.c_str();
        ::prctl(PR_SET_NAME, pai::concurrency::CurrentThread::t_threadName);
        try
        {
            func_();
            pai::concurrency::CurrentThread::t_threadName = "finished";
        } catch (const std::exception& ex)
        {
            pai::concurrency::CurrentThread::t_threadName = "crashed";
            fprintf(stderr, "exception caught in Thread %s\n", name_.c_str());
            fprintf(stderr, "reason: %s\n", ex.what());
            abort();
        } catch (...)
        {
            pai::concurrency::CurrentThread::t_threadName = "crashed";
            fprintf(stderr, "unknown exception caught in Thread %s\n", name_.c_str());
            throw; // rethrow
        }
    }
示例#11
0
			void runInThread()
			{
				DWORD tid = GetCurrentThreadId();
				boost::shared_ptr<DWORD> ptid = wkTid_.lock();
				if (ptid)
				{
					//set thread Id
					*ptid = tid;
					ptid.reset();
				}
				if (name_.empty())
					name_ = "zyThread";
				try
				{
					func_();
					name_ += "finished";
				}
				catch (const std::exception & ex)
				{

					fprintf(stderr, "exception caught in Thread %s\n", name_.c_str());
					fprintf(stderr, "reason: %s\n", ex.what());
					name_ += "crashed";
					abort();
				}
				catch (...)
				{
					fprintf(stderr, "unknown exception caught in Thread %s \n", name_.c_str());
					name_ += "crashed";
					throw;
				}
			}
示例#12
0
		bool operator()(boost::weak_ptr<T> arg) const {
			boost::shared_ptr<T> sp=arg.lock();
			if (!sp) {
				return false;
			}
			return func_(*sp,t_);
		}
示例#13
0
	http_seed_connection::http_seed_connection(
		session_impl& ses
		, boost::weak_ptr<torrent> t
		, boost::shared_ptr<socket_type> s
		, tcp::endpoint const& remote
		, std::string const& url
		, policy::peer* peerinfo
		, std::string const& auth
		, web_seed_entry::headers_t const& extra_headers)
		: web_connection_base(ses, t, s, remote, url, peerinfo, auth, extra_headers)
		, m_url(url)
		, m_response_left(0)
		, m_chunk_pos(0)
		, m_partial_chunk_header(0)
	{
		INVARIANT_CHECK;

		if (!ses.settings().report_web_seed_downloads)
			ignore_stats(true);

		shared_ptr<torrent> tor = t.lock();
		TORRENT_ASSERT(tor);
		int blocks_per_piece = tor->torrent_file().piece_length() / tor->block_size();

		// multiply with the blocks per piece since that many requests are
		// merged into one http request
		m_max_out_request_queue = ses.settings().urlseed_pipeline_size
			* blocks_per_piece;

		prefer_whole_pieces(1);

#ifdef TORRENT_VERBOSE_LOGGING
		peer_log("*** http_seed_connection");
#endif
	}
示例#14
0
void PeerSet::TimerEntry (boost::weak_ptr<PeerSet> wptr, const boost::system::error_code& result)
{
    if (result == boost::asio::error::operation_aborted)
        return;

    boost::shared_ptr<PeerSet> ptr = wptr.lock ();

    if (ptr)
    {
        if (ptr->mTxnData)
        {
            getApp().getJobQueue ().addJob (jtTXN_DATA, "timerEntryTxn",
                BIND_TYPE (&PeerSet::TimerJobEntry, P_1, ptr));
        }
        else
        {
            int jc = getApp().getJobQueue ().getJobCountTotal (jtLEDGER_DATA);

            if (jc > 4)
            {
                WriteLog (lsDEBUG, InboundLedger) << "Deferring PeerSet timer due to load";
                ptr->setTimer ();
            }
            else
                getApp().getJobQueue ().addJob (jtLEDGER_DATA, "timerEntryLgr",
                    BIND_TYPE (&PeerSet::TimerJobEntry, P_1, ptr));
	}
    }
}
示例#15
0
 inline void onServiceInfoResultIfExists(Session_Service* s, qi::Future<qi::ServiceInfo> f,
   long requestId, std::string protocol, boost::weak_ptr<Session_Service> self)
 {
   boost::shared_ptr<Session_Service> sself = self.lock();
   if (sself)
     sself->onServiceInfoResult(f, requestId, protocol);
 }
示例#16
0
void http_connection::on_timeout(boost::weak_ptr<http_connection> p
	, error_code const& e)
{
	boost::shared_ptr<http_connection> c = p.lock();
	if (!c) return;

	if (e == asio::error::operation_aborted) return;

	if (c->m_last_receive + c->m_timeout < time_now())
	{
		if (c->m_connection_ticket > -1 && !c->m_endpoints.empty())
		{
			c->m_sock.close();
			error_code ec;
			c->m_timer.expires_at(c->m_last_receive + c->m_timeout, ec);
			c->m_timer.async_wait(bind(&http_connection::on_timeout, p, _1));
		}
		else
		{
			c->callback(asio::error::timed_out);
			c->close();
		}
		return;
	}

	if (!c->m_sock.is_open()) return;
	error_code ec;
	c->m_timer.expires_at(c->m_last_receive + c->m_timeout, ec);
	c->m_timer.async_wait(bind(&http_connection::on_timeout, p, _1));
}
示例#17
0
void Settings::RegisterVariable( std::string name, boost::weak_ptr<BaseDator> dator )
{
    boost::shared_ptr<BaseDator> real_dator = dator.lock();

    StringMap::iterator it = unparsed_settings_map.find( name );
    if( it != unparsed_settings_map.end() && real_dator )
    {
        std::string ret = real_dator->Set( it->second );
        UpdateListeners( name, it->second, ret );
        unparsed_settings_map.erase( it );
    }
    else {
        DatorMap::iterator it = dator_map.find( name );
        if( it != dator_map.end() && real_dator )
        {
            boost::shared_ptr<BaseDator> other_dator = it->second.lock();
            if( other_dator ) {
                std::string ret = real_dator->Set( other_dator->Get() );
                UpdateListeners( name, real_dator->Get(), ret );
            }
            else {
                dator_map.erase( it );
            }
        }
    }

    if( !dator.expired() ) {
        dator_map.insert( std::make_pair( name, dator ) );
    }
}
示例#18
0
	void add(boost::weak_ptr<SpotLightCalculator> light)
	{
		for(unsigned int i = 0; i < spots.size(); ++i)
			assert(spots[i].lock() != light.lock());

		spots.push_back(light);
	}
示例#19
0
void ServicePort::services(boost::weak_ptr<ServicePort> weakService, IPAddressList ips, uint16_t port)
{
	if(weakService.expired())
		return;

	if(ServicePort_ptr service = weakService.lock())
		service->open(ips, port);
}
示例#20
0
void ServicePort::openAcceptor(boost::weak_ptr<ServicePort> weak_service, uint16_t port)
{
	if(weak_service.expired())
		return;

	if(ServicePort_ptr service = weak_service.lock())
		service->open(port);
}
示例#21
0
inline void save(
    Archive & ar,
    const boost::weak_ptr< T > &t,
    const unsigned int /* file_version */
){
    const boost::shared_ptr< T > sp = t.lock();
    ar << boost::serialization::make_nvp("weak_ptr", sp);
}
示例#22
0
文件: main.cpp 项目: CCJY/coliru
int weak_call(int (X::*ptmf)() const, boost::weak_ptr<X> const& wp) 
{
    auto locked = wp.lock();
    if (!locked)
        throw boost::bad_weak_ptr();

    return ((*locked).*ptmf)();
}
示例#23
0
ProcessResult GetVcard::blockArrived(JabberDataBlockRef block, const ResourceContextRef rc){
    VcardForm::ref vfRef=vf.lock();
    if (!vfRef) return CANCEL;

    vfRef->vcardArrivedNotify(block);

    return LAST_BLOCK_PROCESSED;
}
	void tracker_manager::queue_request(
		io_service& ios
		, connection_queue& cc
		, tracker_request req
		, std::string const& auth
		, boost::weak_ptr<request_callback> c)
	{
		mutex_t::scoped_lock l(m_mutex);
		TORRENT_ASSERT(req.num_want >= 0);
		TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped);
		if (m_abort && req.event != tracker_request::stopped) return;
		if (req.event == tracker_request::stopped)
			req.num_want = 0;

		TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped);
		if (m_abort && req.event != tracker_request::stopped)
			return;

		std::string protocol = req.url.substr(0, req.url.find(':'));

		boost::intrusive_ptr<tracker_connection> con;

#ifdef TORRENT_USE_OPENSSL
		if (protocol == "http" || protocol == "https")
#else
		if (protocol == "http")
#endif
		{
			con = new http_tracker_connection(
				ios, cc, *this, req, c
				, m_ses, m_proxy, auth
#if TORRENT_USE_I2P
				, &m_ses.m_i2p_conn
#endif
				);
		}
		else if (protocol == "udp")
		{
			con = new udp_tracker_connection(
				ios, cc, *this, req , c, m_ses
				, m_proxy);
		}
		else
		{
			// we need to post the error to avoid deadlock
			if (boost::shared_ptr<request_callback> r = c.lock())
				ios.post(boost::bind(&request_callback::tracker_request_error, r, req
					, -1, error_code(errors::unsupported_url_protocol)
					, "", 0));
			return;
		}

		m_connections.push_back(con);

		boost::shared_ptr<request_callback> cb = con->requester();
		if (cb) cb->m_manager = this;
		con->start();
	}
示例#25
0
文件: Factory.cpp 项目: szqh97/test
 static void weakDeleteCallback(const boost::weak_ptr<StockFactory>& wkFactory, Stock* stock)
 {
     shared_ptr<StockFactory> factory(wkFactory.lock());
     if (factory)
     {
         factory->removeStock(stock);
     }
     delete stock;
 }
示例#26
0
ProcessResult GetMucConfig::blockArrived(JabberDataBlockRef block, const ResourceContextRef rc){
    MucConfigForm::ref ahfRef=ahf.lock();
    if (!ahfRef) return CANCEL;

    //StringRef s=block->toXML();
    ahfRef->MucConfigResultNotify(block);

    return LAST_BLOCK_PROCESSED;
}
示例#27
0
void TimerMaster::Register(boost::weak_ptr<Timer> weak_timer) {
  boost::mutex::scoped_lock locker(mutex_);
  boost::shared_ptr<Timer> timer = weak_timer.lock();
  if (weak_timer.expired()) {
    return;
  }
  TimerSlot *slot = new TimerSlot;
  InternalAddTimer(slot, weak_timer, timer->timeout() + timer_jiffies_);
}
void ribi::trim::Face::AddBelongsTo(boost::weak_ptr<const Cell> cell)
{
  assert(cell.lock());
  m_belongs_to.push_back(cell);
  assert(m_belongs_to.size() <= 2);
  assert(
       (m_belongs_to.size() == 1)
    || (m_belongs_to.size() == 2 && m_belongs_to[0].lock() != m_belongs_to[1].lock())
  );
}
示例#29
0
bool CompositePeaksPresenter::hasPeakAddModeFor(boost::weak_ptr<const Mantid::API::IPeaksWorkspace> target){
    bool hasMode  = false;
    if(auto temp = target.lock()) {
        auto it = this->getPresenterIteratorFromWorkspace(temp);
        if(it != m_subjects.end()) {
            hasMode = (*it)->hasPeakAddMode();
        }
    }
    return hasMode;
}
示例#30
0
文件: timer.cpp 项目: fathomdb/mordor
static void
stubOnTimer(
    boost::weak_ptr<void> weakCond, boost::function<void ()> dg)
{
    boost::shared_ptr<void> temp = weakCond.lock();
    if (temp) {
        dg();
    } else {
        MORDOR_LOG_DEBUG(g_log) << " Conditionally skip in stubOnTimer!";
    }
}