SingleAgentModule.cc

Go to the documentation of this file.
00001 /*
00002  * examples/modules/SingleAgentModule.cc
00003  *
00004  * Copyright (C) 2008 by Singularity Institute for Artificial Intelligence
00005  * All Rights Reserved
00006  *
00007  * Written by Gustavo Gama <gama@vettalabs.com>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU Affero General Public License v3 as
00011  * published by the Free Software Foundation and including the exceptions
00012  * at http://opencog.org/wiki/Licenses
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Affero General Public License
00020  * along with this program; if not, write to:
00021  * Free Software Foundation, Inc.,
00022  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00023  */
00024 
00025 #include "SingleAgentModule.h"
00026 
00027 #include <opencog/server/Factory.h>
00028 #include <opencog/server/CogServer.h>
00029 #include <opencog/util/Logger.h>
00030 
00031 using namespace opencog;
00032 
00033 // load/unload functions for the Module interface
00034 extern "C" const char* opencog_module_id()
00035 {
00036     return SingleAgentModule::info().id.c_str();
00037 }
00038 
00039 extern "C" Module* opencog_module_load()
00040 {
00041     CogServer& cogserver = static_cast<CogServer&>(server());
00042     cogserver.registerAgent(SingleAgentModule::info().id, &(SingleAgentModule::factory()));
00043     SingleAgentModule* agent =
00044         static_cast<SingleAgentModule*>(cogserver.createAgent(SingleAgentModule::info().id, true));
00045     agent->name = "OriginalSingleAgentModule";
00046     return agent;
00047 }
00048 
00049 extern "C" void opencog_module_unload(Module* m)
00050 {
00051     SingleAgentModule* agent = static_cast<SingleAgentModule*>(m);
00052     CogServer& cogserver = static_cast<CogServer&>(server());
00053     cogserver.stopAgent(agent);
00054     delete m;
00055 }
00056 
00057 SingleAgentModule::SingleAgentModule() : Agent(100), Module()
00058 {
00059     logger().info("[SingleAgentModule] constructor (%s)", name.c_str());
00060 }
00061 
00062 SingleAgentModule::~SingleAgentModule() {
00063     logger().info("[SingleAgentModule] destructor (%s)", name.c_str());
00064     CogServer& cogserver = static_cast<CogServer&>(server());
00065     cogserver.destroyAllAgents(SingleAgentModule::info().id);
00066 }
00067 
00068 void SingleAgentModule::run(CogServer* server)
00069 {
00070     logger().info("[SingleAgentModule] run (%s)", name.c_str());
00071 }
00072 
00073 void SingleAgentModule::init()
00074 {
00075     logger().info("[TestModule] init (%s)", name.c_str());
00076     CogServer& cogserver = static_cast<CogServer&>(server());
00077 
00078     SingleAgentModule* a =
00079         static_cast<SingleAgentModule*>(cogserver.createAgent(info().id, true));
00080     a->name = "SingleAgentModule1";
00081 
00082     a = static_cast<SingleAgentModule*>(cogserver.createAgent(info().id, true));
00083     a->name = "SingleAgentModule2";
00084 
00085     a = static_cast<SingleAgentModule*>(cogserver.createAgent(info().id, true));
00086     a->name = "SingleAgentModule3";
00087 }

Generated on Fri Dec 4 23:23:25 2009 for OpenCog Framework by  doxygen 1.5.6