summaryrefslogtreecommitdiff
path: root/indra/viewer_components
diff options
context:
space:
mode:
authorAndrew A. de Laix <alain@lindenlab.com>2010-12-01 15:51:10 -0800
committerAndrew A. de Laix <alain@lindenlab.com>2010-12-01 15:51:10 -0800
commit765d939956a0c1f67029d44fd29770aabc36d9b4 (patch)
treeaf350c0fe64495397363cd92ce6ef4ecb23d427c /indra/viewer_components
parent18dbbb4fa45fae8fc9d74eb040308e96abd9e749 (diff)
state change events for updater service.
Diffstat (limited to 'indra/viewer_components')
-rw-r--r--indra/viewer_components/updater/llupdaterservice.cpp62
-rw-r--r--indra/viewer_components/updater/llupdaterservice.h16
2 files changed, 75 insertions, 3 deletions
diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp
index cc60eaead2..cfda314d43 100644
--- a/indra/viewer_components/updater/llupdaterservice.cpp
+++ b/indra/viewer_components/updater/llupdaterservice.cpp
@@ -98,6 +98,8 @@ class LLUpdaterServiceImpl :
LLUpdaterService::app_exit_callback_t mAppExitCallback;
+ LLUpdaterService::eUpdaterState mState;
+
LOG_CLASS(LLUpdaterServiceImpl);
public:
@@ -115,6 +117,7 @@ public:
void startChecking(bool install_if_ready);
void stopChecking();
bool isChecking();
+ LLUpdaterService::eUpdaterState getState();
void setAppExitCallback(LLUpdaterService::app_exit_callback_t aecb) { mAppExitCallback = aecb;}
@@ -139,6 +142,7 @@ public:
private:
void restartTimer(unsigned int seconds);
+ void setState(LLUpdaterService::eUpdaterState state);
void stopTimer();
};
@@ -149,7 +153,8 @@ LLUpdaterServiceImpl::LLUpdaterServiceImpl() :
mIsDownloading(false),
mCheckPeriod(0),
mUpdateChecker(*this),
- mUpdateDownloader(*this)
+ mUpdateDownloader(*this),
+ mState(LLUpdaterService::INITIAL)
{
}
@@ -201,10 +206,16 @@ void LLUpdaterServiceImpl::startChecking(bool install_if_ready)
if(!mIsDownloading)
{
+ setState(LLUpdaterService::CHECKING_FOR_UPDATE);
+
// Checking can only occur during the mainloop.
// reset the timer to 0 so that the next mainloop event
// triggers a check;
restartTimer(0);
+ }
+ else
+ {
+ setState(LLUpdaterService::DOWNLOADING);
}
}
}
@@ -222,6 +233,8 @@ void LLUpdaterServiceImpl::stopChecking()
mUpdateDownloader.cancel();
mIsDownloading = false;
}
+
+ setState(LLUpdaterService::TERMINAL);
}
bool LLUpdaterServiceImpl::isChecking()
@@ -229,6 +242,11 @@ bool LLUpdaterServiceImpl::isChecking()
return mIsChecking;
}
+LLUpdaterService::eUpdaterState LLUpdaterServiceImpl::getState()
+{
+ return mState;
+}
+
bool LLUpdaterServiceImpl::checkForInstall(bool launchInstaller)
{
bool foundInstall = false; // return true if install is found.
@@ -266,6 +284,8 @@ bool LLUpdaterServiceImpl::checkForInstall(bool launchInstaller)
{
if(launchInstaller)
{
+ setState(LLUpdaterService::INSTALLING);
+
LLFile::remove(update_marker_path());
int result = ll_install_update(install_script_path(),
@@ -335,6 +355,8 @@ void LLUpdaterServiceImpl::optionalUpdate(std::string const & newVersion,
stopTimer();
mIsDownloading = true;
mUpdateDownloader.download(uri, hash);
+
+ setState(LLUpdaterService::DOWNLOADING);
}
void LLUpdaterServiceImpl::requiredUpdate(std::string const & newVersion,
@@ -344,6 +366,8 @@ void LLUpdaterServiceImpl::requiredUpdate(std::string const & newVersion,
stopTimer();
mIsDownloading = true;
mUpdateDownloader.download(uri, hash);
+
+ setState(LLUpdaterService::DOWNLOADING);
}
void LLUpdaterServiceImpl::upToDate(void)
@@ -352,6 +376,8 @@ void LLUpdaterServiceImpl::upToDate(void)
{
restartTimer(mCheckPeriod);
}
+
+ setState(LLUpdaterService::UP_TO_DATE);
}
void LLUpdaterServiceImpl::downloadComplete(LLSD const & data)
@@ -369,6 +395,8 @@ void LLUpdaterServiceImpl::downloadComplete(LLSD const & data)
payload["type"] = LLSD(LLUpdaterService::DOWNLOAD_COMPLETE);
event["payload"] = payload;
LLEventPumps::instance().obtain("mainlooprepeater").post(event);
+
+ setState(LLUpdaterService::TERMINAL);
}
void LLUpdaterServiceImpl::downloadError(std::string const & message)
@@ -390,6 +418,8 @@ void LLUpdaterServiceImpl::downloadError(std::string const & message)
payload["message"] = message;
event["payload"] = payload;
LLEventPumps::instance().obtain("mainlooprepeater").post(event);
+
+ setState(LLUpdaterService::ERROR);
}
void LLUpdaterServiceImpl::restartTimer(unsigned int seconds)
@@ -402,6 +432,28 @@ void LLUpdaterServiceImpl::restartTimer(unsigned int seconds)
sListenerName, boost::bind(&LLUpdaterServiceImpl::onMainLoop, this, _1));
}
+void LLUpdaterServiceImpl::setState(LLUpdaterService::eUpdaterState state)
+{
+ if(state != mState)
+ {
+ mState = state;
+
+ LLSD event;
+ event["pump"] = LLUpdaterService::pumpName();
+ LLSD payload;
+ payload["type"] = LLSD(LLUpdaterService::STATE_CHANGE);
+ payload["state"] = state;
+ event["payload"] = payload;
+ LLEventPumps::instance().obtain("mainlooprepeater").post(event);
+
+ LL_INFOS("UpdaterService") << "setting state to " << state << LL_ENDL;
+ }
+ else
+ {
+ ; // State unchanged; noop.
+ }
+}
+
void LLUpdaterServiceImpl::stopTimer()
{
mTimer.stop();
@@ -425,10 +477,13 @@ bool LLUpdaterServiceImpl::onMainLoop(LLSD const & event)
LLSD event;
event["type"] = LLSD(LLUpdaterService::INSTALL_ERROR);
LLEventPumps::instance().obtain(LLUpdaterService::pumpName()).post(event);
+
+ setState(LLUpdaterService::TERMINAL);
}
else
{
mUpdateChecker.check(mProtocolVersion, mUrl, mPath, mChannel, mVersion);
+ setState(LLUpdaterService::CHECKING_FOR_UPDATE);
}
}
else
@@ -496,6 +551,11 @@ bool LLUpdaterService::isChecking()
return mImpl->isChecking();
}
+LLUpdaterService::eUpdaterState LLUpdaterService::getState()
+{
+ return mImpl->getState();
+}
+
void LLUpdaterService::setImplAppExitCallback(LLUpdaterService::app_exit_callback_t aecb)
{
return mImpl->setAppExitCallback(aecb);
diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h
index 1266bcae08..6ee7060d28 100644
--- a/indra/viewer_components/updater/llupdaterservice.h
+++ b/indra/viewer_components/updater/llupdaterservice.h
@@ -44,12 +44,23 @@ public:
static std::string const & pumpName(void);
// Type codes for events posted by this service. Stored the event's 'type' element.
- enum eUpdateEvent {
+ enum eUpdaterEvent {
INVALID,
DOWNLOAD_COMPLETE,
DOWNLOAD_ERROR,
INSTALL_ERROR,
- PROGRESS
+ PROGRESS,
+ STATE_CHANGE
+ };
+
+ enum eUpdaterState {
+ INITIAL,
+ CHECKING_FOR_UPDATE,
+ DOWNLOADING,
+ INSTALLING,
+ UP_TO_DATE,
+ TERMINAL,
+ ERROR
};
LLUpdaterService();
@@ -66,6 +77,7 @@ public:
void startChecking(bool install_if_ready = false);
void stopChecking();
bool isChecking();
+ eUpdaterState getState();
typedef boost::function<void (void)> app_exit_callback_t;
template <typename F>