Rewrite of AIStateMachine, version 2.

This commit is contained in:
Aleric Inglewood
2013-03-01 00:59:06 +01:00
parent 4851cc174e
commit c4dceaf3e9
22 changed files with 1375 additions and 974 deletions

View File

@@ -76,7 +76,6 @@ typedef AIAccess<AIRegisteredStateMachines> registered_statemachines_wat;
// static
void AIEvent::Register(AIEvents event, AIStateMachine* statemachine, bool one_shot)
{
statemachine->idle();
registered_statemachines_wat registered_statemachines_w(registered_statemachines_list[event]);
registered_statemachines_w->Register(statemachine, one_shot);
}

View File

@@ -49,19 +49,20 @@ class AIInventoryFetchDescendentsObserver : public LLInventoryFetchDescendentsOb
protected:
/*virtual*/ void done()
{
mStateMachine->set_state(AIFetchInventoryFolder_folderCompleted);
mStateMachine->advance_state(AIFetchInventoryFolder_folderCompleted);
delete this;
}
private:
AIStateMachine* mStateMachine;
LLPointer<AIStateMachine> mStateMachine;
};
AIInventoryFetchDescendentsObserver::AIInventoryFetchDescendentsObserver(AIStateMachine* statemachine, LLUUID const& folder) :
mStateMachine(statemachine),
LLInventoryFetchDescendentsObserver(folder)
{
mStateMachine->idle();
// Call idle() on the parent state machine before passing it.
llassert(mStateMachine->waiting());
startFetch();
if(isFinished())
{
@@ -97,14 +98,15 @@ void AIFetchInventoryFolder::initialize_impl(void)
set_state(AIFetchInventoryFolder_checkFolderExists);
if (!gInventory.isInventoryUsable())
{
// This immediately calls this->idle(), and then when the event occurs cont().
idle();
// This calls this->cont() when the event occurs.
AIEvent::Register(AIEvent::LLInventoryModel_mIsAgentInvUsable_true, this);
}
}
void AIFetchInventoryFolder::multiplex_impl(void)
void AIFetchInventoryFolder::multiplex_impl(state_type run_state)
{
switch (mRunState)
switch (run_state)
{
case AIFetchInventoryFolder_checkFolderExists:
{
@@ -172,6 +174,7 @@ void AIFetchInventoryFolder::multiplex_impl(void)
}
case AIFetchInventoryFolder_fetchDescendents:
{
idle(); // Wait till the state is set to AIFetchInventoryFolder_folderCompleted.
// This sets the state to AIFetchInventoryFolder_folderCompleted once the folder is complete.
new AIInventoryFetchDescendentsObserver(this, mFolderUUID);
break;
@@ -193,10 +196,6 @@ void AIFetchInventoryFolder::multiplex_impl(void)
}
}
void AIFetchInventoryFolder::abort_impl(void)
{
}
void AIFetchInventoryFolder::finish_impl(void)
{
if (mNeedNotifyObservers)

View File

@@ -138,10 +138,7 @@ class AIFetchInventoryFolder : public AIStateMachine {
/*virtual*/ void initialize_impl(void);
// Handle mRunState.
/*virtual*/ void multiplex_impl(void);
// Handle aborting from current bs_run state.
/*virtual*/ void abort_impl(void);
/*virtual*/ void multiplex_impl(state_type run_state);
// Handle cleaning up from initialization (or post abort) state.
/*virtual*/ void finish_impl(void);

View File

@@ -66,7 +66,7 @@ char const* AIFilePicker::state_str_impl(state_type run_state) const
return "UNKNOWN STATE";
}
AIFilePicker::AIFilePicker(void) : mPluginManager(NULL), mAutoKill(false), mCanceled(false)
AIFilePicker::AIFilePicker(void) : mPluginManager(NULL), mCanceled(false)
{
}
@@ -345,7 +345,7 @@ void AIFilePicker::initialize_impl(void)
set_state(AIFilePicker_initialize_plugin);
}
void AIFilePicker::multiplex_impl(void)
void AIFilePicker::multiplex_impl(state_type run_state)
{
mPluginManager->update(); // Give the plugin some CPU for it's messages.
LLPluginClassBasic* plugin = mPluginManager->getPlugin();
@@ -355,7 +355,7 @@ void AIFilePicker::multiplex_impl(void)
abort();
return;
}
switch (mRunState)
switch (run_state)
{
case AIFilePicker_initialize_plugin:
{
@@ -430,10 +430,6 @@ void AIFilePicker::multiplex_impl(void)
}
}
void AIFilePicker::abort_impl(void)
{
}
void AIFilePicker::finish_impl(void)
{
if (mPluginManager)
@@ -442,12 +438,6 @@ void AIFilePicker::finish_impl(void)
mPluginManager = NULL;
}
mFilter.clear(); // Check that open is called before calling run (again).
if (mAutoKill)
{
// The default behavior is to delete the plugin. This can be overridden in
// the callback by calling run() again.
kill();
}
}
// This function is called when a new message is received from the plugin.
@@ -467,7 +457,7 @@ void AIFilePicker::receivePluginMessage(const LLPluginMessage &message)
if (message_name == "canceled")
{
LL_DEBUGS("Plugin") << "received message \"canceled\"" << LL_ENDL;
set_state(AIFilePicker_canceled);
advance_state(AIFilePicker_canceled);
}
else if (message_name == "done")
{
@@ -478,7 +468,7 @@ void AIFilePicker::receivePluginMessage(const LLPluginMessage &message)
{
mFilenames.push_back(*filename);
}
set_state(AIFilePicker_done);
advance_state(AIFilePicker_done);
}
else
{

View File

@@ -136,8 +136,8 @@ new AIFilePicker
which sets the state to AIFilePicker_canceled or AIFilePicker_done
respectively, causing a call to AIStateMachine::finish(), which calls
AIFilePicker::finish_impl which destroys the plugin (mPluginBase),
the plugin manager (mPluginManager) and calls AIStateMachine::kill()
causing the AIFilePicker to be deleted.
the plugin manager (mPluginManager) after which the state machine
calls unref() causing the AIFilePicker to be deleted.
*/
@@ -155,7 +155,7 @@ public:
AIFilePicker(void);
// Create a dynamically created AIFilePicker object.
static AIFilePicker* create(bool auto_kill = true) { AIFilePicker* filepicker = new AIFilePicker; filepicker->mAutoKill = auto_kill; return filepicker; }
static AIFilePicker* create(void) { AIFilePicker* filepicker = new AIFilePicker; return filepicker; }
// The starting directory that the user will be in when the file picker opens
// will be the same as the directory used the last time the file picker was
@@ -191,7 +191,6 @@ private:
typedef std::map<std::string, std::string> context_map_type; //!< Type of mContextMap.
static AIThreadSafeSimpleDC<context_map_type> sContextMap; //!< Map context (ie, "snapshot" or "image") to last used folder.
std::string mContext; //!< Some key to indicate the context (remembers the folder per key).
bool mAutoKill; //!< True if the default behavior is to delete itself after being finished.
// Input variables (cache variable between call to open and run).
open_type mOpenType; //!< Set to whether opening a filepicker to select for saving one file, for loading one file, or loading multiple files.
@@ -215,10 +214,7 @@ protected:
/*virtual*/ void initialize_impl(void);
// Handle mRunState.
/*virtual*/ void multiplex_impl(void);
// Handle aborting from current bs_run state.
/*virtual*/ void abort_impl(void);
/*virtual*/ void multiplex_impl(state_type run_state);
// Handle cleaning up from initialization (or post abort) state.
/*virtual*/ void finish_impl(void);