From be8c9fc21758bcbc1d9f3d565b221310344231bd Mon Sep 17 00:00:00 2001 From: "Mark Palange (Mani)" Date: Wed, 27 Oct 2010 17:07:31 -0700 Subject: CHOP-122 Initializing Facade service in the viewer. Rev. by Brad. --- indra/viewer_components/updater/CMakeLists.txt | 10 ++ .../viewer_components/updater/llupdaterservice.cpp | 107 +++++------ indra/viewer_components/updater/llupdaterservice.h | 19 +- .../updater/tests/llupdaterservice_test.cpp | 195 +++++++++++++-------- 4 files changed, 203 insertions(+), 128 deletions(-) (limited to 'indra/viewer_components/updater') diff --git a/indra/viewer_components/updater/CMakeLists.txt b/indra/viewer_components/updater/CMakeLists.txt index df9404474c..a8a1d685f7 100644 --- a/indra/viewer_components/updater/CMakeLists.txt +++ b/indra/viewer_components/updater/CMakeLists.txt @@ -55,3 +55,13 @@ if(LL_TESTS) LL_ADD_PROJECT_UNIT_TESTS(llupdaterservice "${llupdater_service_TEST_SOURCE_FILES}") endif(LL_TESTS) + +set(UPDATER_INCLUDE_DIRS + ${LIBS_OPEN_DIR}/viewer_components/updater + CACHE INTERNAL "" +) + +set(UPDATER_LIBRARIES + llupdaterservice + CACHE INTERNAL "" +) diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp index 6c7619a2b9..28c942b5f2 100644 --- a/indra/viewer_components/updater/llupdaterservice.cpp +++ b/indra/viewer_components/updater/llupdaterservice.cpp @@ -27,18 +27,19 @@ #include "llupdaterservice.h" -#include "llsingleton.h" #include "llpluginprocessparent.h" #include +#include -class LLUpdaterServiceImpl : public LLPluginProcessParentOwner, - public LLSingleton +boost::weak_ptr gUpdater; + +class LLUpdaterServiceImpl : public LLPluginProcessParentOwner { std::string mUrl; std::string mChannel; std::string mVersion; - unsigned int mUpdateCheckPeriod; + unsigned int mCheckPeriod; bool mIsChecking; boost::scoped_ptr mPlugin; @@ -52,17 +53,20 @@ public: virtual void pluginLaunchFailed(); virtual void pluginDied(); - void setURL(const std::string& url); - void setChannel(const std::string& channel); - void setVersion(const std::string& version); - void setUpdateCheckPeriod(unsigned int seconds); + void setParams(const std::string& url, + const std::string& channel, + const std::string& version); + + void setCheckPeriod(unsigned int seconds); + void startChecking(); void stopChecking(); + bool isChecking(); }; LLUpdaterServiceImpl::LLUpdaterServiceImpl() : mIsChecking(false), - mUpdateCheckPeriod(0), + mCheckPeriod(0), mPlugin(0) { // Create the plugin parent, this is the owner. @@ -87,42 +91,35 @@ void LLUpdaterServiceImpl::pluginDied() { }; -void LLUpdaterServiceImpl::setURL(const std::string& url) -{ - if(mUrl != url) - { - mUrl = url; - } -} - -void LLUpdaterServiceImpl::setChannel(const std::string& channel) +void LLUpdaterServiceImpl::setParams(const std::string& url, + const std::string& channel, + const std::string& version) { - if(mChannel != channel) - { - mChannel = channel; - } -} - -void LLUpdaterServiceImpl::setVersion(const std::string& version) -{ - if(mVersion != version) + if(mIsChecking) { - mVersion = version; + throw LLUpdaterService::UsageError("Call LLUpdaterService::stopCheck()" + " before setting params."); } + + mUrl = url; + mChannel = channel; + mVersion = version; } -void LLUpdaterServiceImpl::setUpdateCheckPeriod(unsigned int seconds) +void LLUpdaterServiceImpl::setCheckPeriod(unsigned int seconds) { - if(mUpdateCheckPeriod != seconds) - { - mUpdateCheckPeriod = seconds; - } + mCheckPeriod = seconds; } void LLUpdaterServiceImpl::startChecking() { if(!mIsChecking) { + if(mUrl.empty() || mChannel.empty() || mVersion.empty()) + { + throw LLUpdaterService::UsageError("Set params before call to " + "LLUpdaterService::startCheck()."); + } mIsChecking = true; } } @@ -135,42 +132,54 @@ void LLUpdaterServiceImpl::stopChecking() } } +bool LLUpdaterServiceImpl::isChecking() +{ + return mIsChecking; +} + //----------------------------------------------------------------------- // Facade interface LLUpdaterService::LLUpdaterService() { + if(gUpdater.expired()) + { + mImpl = + boost::shared_ptr(new LLUpdaterServiceImpl()); + gUpdater = mImpl; + } + else + { + mImpl = gUpdater.lock(); + } } LLUpdaterService::~LLUpdaterService() { } -void LLUpdaterService::setURL(const std::string& url) -{ - LLUpdaterServiceImpl::getInstance()->setURL(url); -} - -void LLUpdaterService::setChannel(const std::string& channel) +void LLUpdaterService::setParams(const std::string& url, + const std::string& chan, + const std::string& vers) { - LLUpdaterServiceImpl::getInstance()->setChannel(channel); + mImpl->setParams(url, chan, vers); } -void LLUpdaterService::setVersion(const std::string& version) -{ - LLUpdaterServiceImpl::getInstance()->setVersion(version); -} - -void LLUpdaterService::setUpdateCheckPeriod(unsigned int seconds) +void LLUpdaterService::setCheckPeriod(unsigned int seconds) { - LLUpdaterServiceImpl::getInstance()->setUpdateCheckPeriod(seconds); + mImpl->setCheckPeriod(seconds); } void LLUpdaterService::startChecking() { - LLUpdaterServiceImpl::getInstance()->startChecking(); + mImpl->startChecking(); } void LLUpdaterService::stopChecking() { - LLUpdaterServiceImpl::getInstance()->stopChecking(); + mImpl->stopChecking(); +} + +bool LLUpdaterService::isChecking() +{ + return mImpl->isChecking(); } diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h index 33d0dc0816..6459ca49f8 100644 --- a/indra/viewer_components/updater/llupdaterservice.h +++ b/indra/viewer_components/updater/llupdaterservice.h @@ -26,11 +26,16 @@ #ifndef LL_UPDATERSERVICE_H #define LL_UPDATERSERVICE_H +#include + +class LLUpdaterServiceImpl; + class LLUpdaterService { public: class UsageError: public std::runtime_error { + public: UsageError(const std::string& msg) : std::runtime_error(msg) {} }; @@ -39,14 +44,18 @@ public: // The base URL. // *NOTE:Mani The grid, if any, would be embedded in the base URL. - void setURL(const std::string& url); - void setChannel(const std::string& channel); - void setVersion(const std::string& version); - - void setUpdateCheckPeriod(unsigned int seconds); + void setParams(const std::string& url, + const std::string& channel, + const std::string& version); + + void setCheckPeriod(unsigned int seconds); void startChecking(); void stopChecking(); + bool isChecking(); + +private: + boost::shared_ptr mImpl; }; #endif LL_UPDATERSERVICE_H diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp index 9edf15ba11..73cf6ea6eb 100644 --- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp +++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp @@ -1,50 +1,50 @@ -/** - * @file llupdaterservice_test.cpp - * @brief Tests of llupdaterservice.cpp. - * - * $LicenseInfo:firstyear=2010&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -// Precompiled header -#include "linden_common.h" -// associated header -#include "../llupdaterservice.h" - -#include "../../../test/lltut.h" -//#define DEBUG_ON -#include "../../../test/debug.h" - -#include "llevents.h" -#include "llpluginprocessparent.h" - -/***************************************************************************** -* MOCK'd -*****************************************************************************/ -LLPluginProcessParentOwner::~LLPluginProcessParentOwner() {} -LLPluginProcessParent::LLPluginProcessParent(LLPluginProcessParentOwner *owner) -: mOwner(owner), - mIncomingQueueMutex(NULL) -{ -} +/** + * @file llupdaterservice_test.cpp + * @brief Tests of llupdaterservice.cpp. + * + * $LicenseInfo:firstyear=2010&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +// Precompiled header +#include "linden_common.h" +// associated header +#include "../llupdaterservice.h" + +#include "../../../test/lltut.h" +//#define DEBUG_ON +#include "../../../test/debug.h" + +#include "llevents.h" +#include "llpluginprocessparent.h" + +/***************************************************************************** +* MOCK'd +*****************************************************************************/ +LLPluginProcessParentOwner::~LLPluginProcessParentOwner() {} +LLPluginProcessParent::LLPluginProcessParent(LLPluginProcessParentOwner *owner) +: mOwner(owner), + mIncomingQueueMutex(gAPRPoolp) +{ +} LLPluginProcessParent::~LLPluginProcessParent() {} LLPluginMessagePipeOwner::LLPluginMessagePipeOwner(){} @@ -52,30 +52,77 @@ LLPluginMessagePipeOwner::~LLPluginMessagePipeOwner(){} void LLPluginProcessParent::receiveMessageRaw(const std::string &message) {} int LLPluginMessagePipeOwner::socketError(int) { return 0; } void LLPluginProcessParent::setMessagePipe(LLPluginMessagePipe *message_pipe) {} -void LLPluginMessagePipeOwner::setMessagePipe(class LLPluginMessagePipe *) {} -LLPluginMessage::~LLPluginMessage() {} - -/***************************************************************************** -* TUT -*****************************************************************************/ -namespace tut -{ - struct llupdaterservice_data - { - llupdaterservice_data() : - pumps(LLEventPumps::instance()) - {} - LLEventPumps& pumps; - }; - - typedef test_group llupdaterservice_group; - typedef llupdaterservice_group::object llupdaterservice_object; - llupdaterservice_group llupdaterservicegrp("LLUpdaterService"); - - template<> template<> - void llupdaterservice_object::test<1>() - { - DEBUG; - ensure_equals("Dummy", 0, 0); - } -} +void LLPluginMessagePipeOwner::setMessagePipe(class LLPluginMessagePipe *) {} +LLPluginMessage::~LLPluginMessage() {} + +/***************************************************************************** +* TUT +*****************************************************************************/ +namespace tut +{ + struct llupdaterservice_data + { + llupdaterservice_data() : + pumps(LLEventPumps::instance()), + test_url("dummy_url"), + test_channel("dummy_channel"), + test_version("dummy_version") + {} + LLEventPumps& pumps; + std::string test_url; + std::string test_channel; + std::string test_version; + }; + + typedef test_group llupdaterservice_group; + typedef llupdaterservice_group::object llupdaterservice_object; + llupdaterservice_group llupdaterservicegrp("LLUpdaterService"); + + template<> template<> + void llupdaterservice_object::test<1>() + { + DEBUG; + LLUpdaterService updater; + bool got_usage_error = false; + try + { + updater.startChecking(); + } + catch(LLUpdaterService::UsageError) + { + got_usage_error = true; + } + ensure("Caught start before params", got_usage_error); + } + + template<> template<> + void llupdaterservice_object::test<2>() + { + DEBUG; + LLUpdaterService updater; + bool got_usage_error = false; + try + { + updater.setParams(test_url, test_channel, test_version); + updater.startChecking(); + updater.setParams("other_url", test_channel, test_version); + } + catch(LLUpdaterService::UsageError) + { + got_usage_error = true; + } + ensure("Caught params while running", got_usage_error); + } + + template<> template<> + void llupdaterservice_object::test<3>() + { + DEBUG; + LLUpdaterService updater; + updater.setParams(test_url, test_channel, test_version); + updater.startChecking(); + ensure(updater.isChecking()); + updater.stopChecking(); + ensure(!updater.isChecking()); + } +} -- cgit v1.2.3