PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llmainlooprepeater.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 88 lines | 45 code | 16 blank | 27 comment | 4 complexity | 864075d634d0c75a59bda98f6522cc6f MD5 | raw file
 1/** 
 2 * @file llmachineid.cpp
 3 * @brief retrieves unique machine ids
 4 *
 5 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27#include "llviewerprecompiledheaders.h"
28#include "llapr.h"
29#include "llevents.h"
30#include "llmainlooprepeater.h"
31
32
33
34// LLMainLoopRepeater
35//-----------------------------------------------------------------------------
36
37
38LLMainLoopRepeater::LLMainLoopRepeater(void):
39	mQueue(0)
40{
41	; // No op.
42}
43
44
45void LLMainLoopRepeater::start(void)
46{
47	if(mQueue != 0) return;
48
49	mQueue = new LLThreadSafeQueue<LLSD>(gAPRPoolp, 1024);
50	mMainLoopConnection = LLEventPumps::instance().
51		obtain("mainloop").listen(LLEventPump::inventName(), boost::bind(&LLMainLoopRepeater::onMainLoop, this, _1));
52	mRepeaterConnection = LLEventPumps::instance().
53		obtain("mainlooprepeater").listen(LLEventPump::inventName(), boost::bind(&LLMainLoopRepeater::onMessage, this, _1));
54}
55
56
57void LLMainLoopRepeater::stop(void)
58{
59	mMainLoopConnection.release();
60	mRepeaterConnection.release();
61
62	delete mQueue;
63	mQueue = 0;
64}
65
66
67bool LLMainLoopRepeater::onMainLoop(LLSD const &)
68{
69	LLSD message;
70	while(mQueue->tryPopBack(message)) {
71		std::string pump = message["pump"].asString();
72		if(pump.length() == 0 ) continue; // No pump.
73		LLEventPumps::instance().obtain(pump).post(message["payload"]);
74	}
75	return false;
76}
77
78
79bool LLMainLoopRepeater::onMessage(LLSD const & event)
80{
81	try {
82		mQueue->pushFront(event);
83	} catch(LLThreadSafeQueueError & e) {
84		llwarns << "could not repeat message (" << e.what() << ")" << 
85			event.asString() << LL_ENDL;
86	}
87	return false;
88}