void 
TransDispatcher::processCleanup()
{
	if ( m_tickCleanup.Elapsed() < 1000 ) // every second
	{
		return;
	}

	m_tickCleanup.Reset();

	ActionMap::iterator i( m_actions.begin() );

	for ( ; i != m_actions.end(); ++i )
	{
		ActionList& lst = i->second;

		ActionList::iterator ai( lst.begin() );

		for ( ; ai != lst.end();  )
		{
			ActionPtr action = *ai;

			if ( action->IsFinished() )
			{
				ai = lst.erase( ai );
			}
			else
			{
				++ai;
			}
		}

		// keep empty list. not a big deal.
	}
}
Beispiel #2
0
TEST(TaskTest, ConditionalTaskExecute)
{
	ITaskSystemPtr pTaskSystem (new TaskSystem());
	Ts::ITaskManagerPtr pTaskMgr = pTaskSystem->GetTaskManager();

	EXPECT_EQ(true, pTaskMgr != NULL);

	{
		BehaviorManager* pBehaviorManager = pTaskSystem->GetBehaviorManager();

		WString actionName = _T("demoAction");
		ActionPtr pNewAction = Action::Create(_T("EmptyAction"), pBehaviorManager);
		pNewAction->GetParameterTable().AddParameter(Parameter(OBJECT_ID, actionName.data()));

		WString conditionName (_T("TrueCondition"));
		ConditionPtr pNewCondtion = Condition::Create(_T("TrueCondition"), pBehaviorManager);
		pNewCondtion->GetParameterTable().AddParameter(Parameter(OBJECT_ID, conditionName.data()));
		
		ImmediateTask::pointer pImmeTask (ImmediateTask::Create(_T("basicTask")));
		pImmeTask->AppendAction(actionName);
		pTaskMgr->RegisterTask(pImmeTask);

		ConditionalTask::pointer pTask (ConditionalTask::Create(_T("conditionTask"), conditionName, pImmeTask->GetObjectId()));

		const bool ok = pTask->Execute(pTaskSystem.get());
		EXPECT_EQ(true, ok);
	}
}
Beispiel #3
0
ActionPlan Planner::Plan2(){
  ActionPlan result;
  auto curr = preConds;
  auto goal = postConds;

  ActionPtr nullAction = Action::ActionFactory("NULL",{},{},0,0);
  ActionCondition start = {curr, nullAction};

  PriorityQueue<ActionNodePtr> acs;
  auto curr_ac  = std::make_shared<ActionNode>();
  curr_ac->action = nullAction;
  curr_ac->conds = curr;
  curr_ac->cost_so_far = 0;
  curr_ac->parent = nullptr;
  
  acs.put(curr_ac,0);
  bool success = false;
  while(!acs.empty()){
    curr_ac  = acs.get();

    if(!satisfies(curr_ac->conds, goal)){
      for(auto& ac : findActions(actions, curr_ac->conds)){
	bool skip = false;
	auto temp_ac = curr_ac;
	while(temp_ac->action->getName() != nullAction->getName()){
	  temp_ac = temp_ac->parent;
	  if(ac.first == temp_ac->conds){
	    skip=true;
	    break;
	  }
	}
	if(skip)
	  continue;
	auto node = std::make_shared<ActionNode>();
	node->action = ac.second;
	node->conds = ac.first;
	node->cost_so_far = ac.second->getCost()+curr_ac->cost_so_far;
	node->parent = curr_ac;
	acs.put(node,node->cost_so_far);
      }
    }
    else{
      success=true;
      break;
    }
  }
  std::cout <<"PLANNED " << std::boolalpha << success << "\n";
  if(!success)
    return result;
  while(curr_ac != nullptr){
    result.push_back(curr_ac->action);
    //std::cout << curr_ac->action << " ";
    curr_ac = curr_ac->parent;
  }
     
  std::reverse(result.begin(), result.end());
  return result;
}
Beispiel #4
0
void ScriptNode::addAction( ActionPtr action )
{
	action->doAction();
	if( m_actionAccumulator && m_undoStateStack.top() == UndoContext::Enabled )
	{
		m_actionAccumulator->addAction( action );
		actionSignal()( this, action.get(), Action::Do );
	}
}
void ServerModel::QueueAction(ActionPtr spAction)
{
   // resolve argument
   ObjectRef& ref = spAction->ArgumentRef();
   if (ref.m_sp == NULL)
      ref.m_sp = m_objectMap.FindObject(ref.m_id).m_sp;

   spAction->Do(*this);
}
Beispiel #6
0
///**********************************************************************///
///                       class implement end                            ///
///**********************************************************************///
///**********************************************************************///
///                       class implement begin                          ///
///**********************************************************************///
void Robot::RunOnce()
{
	ActionQueue::iterator iter = m_actionQueue.begin();
	ActionQueue::iterator end = m_actionQueue.end();
	for (; iter != end; iter++) {
		ActionPtr act = *iter;
		act->Do();
		CommandProc();
	}
	CommandProc();
}
   /// executes action
   void Execute(ActionPtr spAction)
   {
      ObjectRef& arg = spAction->ArgumentRef();
      ATLASSERT(arg.m_sp != NULL);

      {
         // lock argument ref
         Lockable::LockType lock = arg.m_sp->Lock();
         spAction->Do(m_model);
      }
   }
Beispiel #8
0
void Action::enact( ActionPtr action )
{
	ScriptNode *s = IECore::runTimeCast<ScriptNode>( action->subject() );
	if( !s )
	{
		s = action->subject()->ancestor<ScriptNode>();
	}

	if( s )
	{
		s->addAction( action );
	}
	else
	{
		action->doAction();
	}

}
void 
TransDispatcher::Fini()
{
	ActionMap::iterator i( m_actions.begin() );

	for ( ; i != m_actions.end(); ++i )
	{
		ActionList& lst = i->second;

		ActionList::iterator ai( lst.begin() );

		for ( ; ai != lst.end(); ++ai )
		{
			ActionPtr action = *ai;

			action->Fini();
		}

		lst.clear();
	}

	m_actions.clear();
}
Beispiel #10
0
void 
TransDispatcher::Dispatch( Transaction* trans )
{
	ActionMap::iterator i( m_actions.find( trans->GetType() ) );

	if ( i != m_actions.end() )
	{
		ActionList& lst = i->second;

		ActionList::iterator ai( lst.begin() );

		for ( ; ai != lst.end(); ++ai )
		{
			ActionPtr action = *ai;

			K_ASSERT( action.Get() != 0 );

			if ( !action->IsFinished() )
			{
				action->Completed( trans );
			}
		}
	}
}
Beispiel #11
0
void 
TransDispatcher::Subscribe( ushort type, ActionPtr action )
{
	K_ASSERT( type > 0 );
	K_ASSERT( action.Get() != 0 );

	ActionMap::iterator i( m_actions.find( type ) );

	if ( i == m_actions.end() )
	{
		ActionList lst;

		lst.push_back( action );

		m_actions.insert( ActionMap::value_type( type, lst ) );
	}
	else
	{
		ActionList& lst = i->second;

		lst.push_back( action );
	}
}
Beispiel #12
0
TEST(SaveLoadTest, SaveLoadLatestVersion)
{
    // Use the temp application.
    TaskSystem *pTempApp1 = new TaskSystem();
    TaskSystem* pPreviousApp = SetWorkingBrain(pTempApp1);

    {
        Parameter para(_T("OS"), _T("Windows7"));
        para.SetComments(_T("global"));
        GetWorkingBrain()->GetVariableManager()->AddUserParameter(para);
    }

    CString conditionId = _T("DoesRegExist");
    {
        ConditionPtr pRegCondition = Condition::Create(_T("RegisterKeyExistsCondition"), GetWorkingBrain()->GetBehaviorManager());
        Parameter objectId(OBJECT_ID, conditionId);
        Parameter para1(_T("RootKey"), _T("HKEY_LOCAL_MACHINE"));
        Parameter para2(_T("SubKey"), _T("Software\\Microsoft"));

        pRegCondition->GetParameterTable().AddParameter(objectId);
        pRegCondition->GetParameterTable().AddParameter(para1);
        pRegCondition->GetParameterTable().AddParameter(para2);

        //GetWorkingBrain()->GetBehaviorManager()->RegisterCondition(pRegCondition);
    }

    CString actionId = _T("DemoToRunSysCmd");
    {
        ActionPtr pNewAction = Action::Create(_T("RunSystemCommandAction"), GetWorkingBrain()->GetBehaviorManager());
        Parameter objectId(OBJECT_ID, actionId);
        objectId.SetComments(_T("Object Id is used to reference this object everywhere."));
        Parameter objectType;
        pNewAction->GetParameterTable().GetParameter(OBJECT_TYPE, objectType);
        objectType.SetComments(_T("Object type indicates which behavior body will this action invokes."));
        Parameter cmd(APPLICATION_NAME, _T("regedit.exe"));
        cmd.SetComments(_T("Indicate which command will be run"));
        pNewAction->GetParameterTable().AddParameter(objectId);
        pNewAction->GetParameterTable().AddParameter(objectType);
        pNewAction->GetParameterTable().AddParameter(cmd);

        //GetWorkingBrain()->GetBehaviorManager()->RegisterAction(pNewAction);
        GetWorkingBrain()->GetBehaviorManager()->AddActionTask(pNewAction);
    }

    CString fileName(_T("C:\\braintest.xml"));

    // Save
    bool ret = GetWorkingBrain()->XmlOut(fileName);
    EXPECT_EQ(true, ret);

    // Load
    TaskSystem *pTempApp2 = new TaskSystem();

    SetWorkingBrain(pTempApp2);

    ret = GetWorkingBrain()->XmlIn(fileName);
    EXPECT_EQ(true, ret);

    {
        ActionPtr pAction = GetWorkingBrain()->GetBehaviorManager()->GetActionById(actionId);
        EXPECT_EQ(true, (pAction != NULL));
    }

    {
        ConditionPtr pCondition = GetWorkingBrain()->GetBehaviorManager()->GetConditionById(conditionId);
        EXPECT_EQ(true, (pCondition != NULL));
    }

    // Recover
    SetWorkingBrain(pPreviousApp);
}
Beispiel #13
0
void		Behaviour::StartAction(ActionPtr action)
{
	mActiveActions.push_back(action);
	action->OnStart(shared_from_this());
}
Beispiel #14
0
void Robot::DoAction() {
	ActionPtr act = GetCurrnetAction();
	if (act.get()) act->Do();
	Next();
	CommandProc();
}