MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / getOperateOpt

Method getOperateOpt

native/model/Model.cpp:82–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80
81
82 OperatePtr Model::getOperateOpt(const ElementPtr &element, const std::string &activity,
83 const std::string &deviceID) {
84 // the whole process begins.
85 double methodStartTimestamp = currentStamp(); //the time stamp of this current time
86 ActionPtr customActionPtr = nullptr;
87 if (this->_preference) //load the preferred action in preference file specified by user in sdcard
88 {
89 BLOG("try get custom action from preference");
90 customActionPtr = this->_preference->resolvePageAndGetSpecifiedAction(activity,
91 element);
92 }
93 // get activity
94 stringPtrSet activityStringPtrSet = this->_graph->getVisitedActivities();
95 stringPtr activityPtr = std::make_shared<std::string>(activity);
96 auto founded = activityStringPtrSet.find(
97 activityPtr); //Searches the container for an element equivalent to val and returns an iterator to it if found, otherwise it returns an iterator to set::end.
98 stringPtr activityStringPtr = nullptr;
99 if (founded == activityStringPtrSet.end())
100 activityStringPtr = activityPtr; //this is a new activity.
101 else
102 activityStringPtr = *founded; // use the cached activity.
103 // get agent
104 if (this->_deviceIDAgentMap.empty()) // create a default agent
105 {
106 BLOG("%s", "use reuseAgent as the default agent");
107 this->addAgent(DefaultDeviceID, AlgorithmType::Reuse);
108 }
109 auto agentIterator = this->_deviceIDAgentMap.find(deviceID);
110 AbstractAgentPtr agent = nullptr;
111 if (agentIterator == this->_deviceIDAgentMap.end())
112 agent = this->_deviceIDAgentMap[DefaultDeviceID]; // get the agent from the default device
113 else
114 agent = (*agentIterator).second; // get the found agent
115
116 // get state
117 StatePtr state = nullptr;
118 if (nullptr != element) // make sure the XML is not null
119 {
120 //according to the type of the used agent, create the state of this page
121 //include all the possible actions according to the widgets inside.
122 state = StateFactory::createState(agent->getAlgorithmType(), activityStringPtr,
123 element);
124 // add state
125 // add this state, and the agent will treat this state as the new state(_newState)
126 state = this->_graph->addState(state);
127 state->visit(this->_graph->getTimestamp());
128 }
129
130 // new state is prepared, record the current time
131 double stateGeneratedTimestamp = currentStamp();
132 ActionPtr action = customActionPtr; // load the action specified by user
133
134 BDLOGE("%s", state->toString().c_str());
135
136 double startGeneratingActionTimestamp = currentStamp();
137 double endGeneratingActionTimestamp = currentStamp();
138 bool shouldSkipActionsFromModel = this->_preference->skipAllActionsFromModel();
139 if (shouldSkipActionsFromModel) // seems that user could specify if the model should be used?

Callers

nothing calls this directly

Calls 15

addAgentMethod · 0.95
currentStampFunction · 0.85
getVisitedActivitiesMethod · 0.80
emptyMethod · 0.80
getAlgorithmTypeMethod · 0.80
addStateMethod · 0.80
visitMethod · 0.80
getTimestampMethod · 0.80

Tested by

no test coverage detected