Skip to content

Commit

Permalink
Convert more examples to new API.
Browse files Browse the repository at this point in the history
  • Loading branch information
linas committed Oct 4, 2013
1 parent 6c0bba4 commit 848c72a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
22 changes: 11 additions & 11 deletions examples/modules/SingleAgentModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@ extern "C" const char* opencog_module_id()
extern "C" Module* opencog_module_load(CogServer& cogserver)
{
cogserver.registerAgent(SingleAgentModule::info().id, &(SingleAgentModule::factory()));
SingleAgentModule* agent =
static_cast<SingleAgentModule*>(cogserver.createAgent(SingleAgentModule::info().id, true));
SingleAgentModulePtr agent = cogserver.createAgent<SingleAgentModule>(true);
agent->name = "OriginalSingleAgentModule";
return agent;
return agent.get();
}

extern "C" void opencog_module_unload(Module* m)
{
SingleAgentModule* agent = static_cast<SingleAgentModule*>(m);
agent->stopAgent();
delete m;
}

SingleAgentModule::SingleAgentModule(CogServer& cs) : Agent(cs, 100), Module(cs)
Expand All @@ -65,7 +63,8 @@ SingleAgentModule::~SingleAgentModule()

void SingleAgentModule::stopAgent()
{
Module::_cogserver.stopAgent(this);
AgentPtr age = std::dynamic_pointer_cast<Agent>(shared_from_this());
Module::_cogserver.stopAgent(age);
}

void SingleAgentModule::run()
Expand All @@ -77,13 +76,14 @@ void SingleAgentModule::init()
{
logger().info("[TestModule] init (%s)", name.c_str());

SingleAgentModule* a =
static_cast<SingleAgentModule*>(Module::_cogserver.createAgent(info().id, true));
// Use static global vars -- the egent is destroyed when these go
// out of scope (during the C++ finalizer).
static SingleAgentModulePtr a = Module::_cogserver.createAgent<SingleAgentModule>(true);
a->name = "SingleAgentModule1";

a = static_cast<SingleAgentModule*>(Module::_cogserver.createAgent(info().id, true));
a->name = "SingleAgentModule2";
static SingleAgentModulePtr b = Module::_cogserver.createAgent<SingleAgentModule>(true);
b->name = "SingleAgentModule2";

a = static_cast<SingleAgentModule*>(Module::_cogserver.createAgent(info().id, true));
a->name = "SingleAgentModule3";
static SingleAgentModulePtr c = Module::_cogserver.createAgent<SingleAgentModule>(true);
c->name = "SingleAgentModule3";
}
2 changes: 2 additions & 0 deletions examples/modules/SingleAgentModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class SingleAgentModule : public Agent, public Module

}; // class

typedef std::shared_ptr<SingleAgentModule> SingleAgentModulePtr;

} // namespace opencog

#endif // _OPENCOG_SINGLE_AGENT_MODULE_H
1 change: 0 additions & 1 deletion opencog/server/CogServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ void CogServer::destroyAgent(AgentPtr agent)
{
stopAgent(agent);
logger().debug("[CogServer] deleting agent \"%s\"", agent->to_string().c_str());
// delete agent;
}

void CogServer::destroyAllAgents(const std::string& id)
Expand Down

0 comments on commit 848c72a

Please sign in to comment.