aboutsummaryrefslogtreecommitdiff
path: root/cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2018-08-11 20:21:34 +0200
committerneodarz <neodarz@neodarz.net>2018-08-11 20:21:34 +0200
commit0ea5fc66924303d1bf73ba283a383e2aadee02f2 (patch)
tree2568e71a7ccc44ec23b8bb3f0ff97fb6bf2ed709 /cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service
downloadnevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.tar.xz
nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.zip
Initial commit
Diffstat (limited to 'cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service')
-rw-r--r--cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service/Attic/io_interface.cpp?rev=1.1&content-type=text/plain&hideattic=0/index.html54
-rw-r--r--cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service/Attic/py_object_trans.cpp?rev=1.1&content-type=text/plain&hideattic=0/index.html132
-rw-r--r--cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service/Attic/server.cpp?rev=1.1&content-type=text/plain&hideattic=0/index.html228
3 files changed, 414 insertions, 0 deletions
diff --git a/cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service/Attic/io_interface.cpp?rev=1.1&content-type=text/plain&hideattic=0/index.html b/cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service/Attic/io_interface.cpp?rev=1.1&content-type=text/plain&hideattic=0/index.html
new file mode 100644
index 00000000..2cfd6fb4
--- /dev/null
+++ b/cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service/Attic/io_interface.cpp?rev=1.1&content-type=text/plain&hideattic=0/index.html
@@ -0,0 +1,54 @@
+#include "nel/ai/agent/agent.h"
+#include "io_interface.h"
+#include <stdio.h>
+#include <stdarg.h>
+
+namespace SRV
+{
+ extern std::fstream logStream;
+ extern bool logFileState;
+
+ static char LaseErrorCodeOrdreInterprete[32*1024];
+ void IOTrace::Echo(char *str, ...)
+ {
+ char temp[32*1024];
+ va_list argument;
+ va_start (argument, str);
+
+ vsprintf(temp, str, argument);
+ strcpy(LaseErrorCodeOrdreInterprete,temp);
+
+#ifdef NL_DEBUG
+ printf("%s",LaseErrorCodeOrdreInterprete);
+ if(logFileState && logStream.is_open())
+ {
+ logStream << LaseErrorCodeOrdreInterprete;
+ logStream.flush();
+ }
+#else
+ printf("%s",LaseErrorCodeOrdreInterprete);
+ if(logFileState && logStream.is_open())
+ {
+ logStream << LaseErrorCodeOrdreInterprete;
+ logStream.flush();
+ }
+#endif
+
+ }
+
+ const std::string IOTrace::InPut()
+ {
+ std::string str;
+ /*char toto[4096];
+ str = gets(toto);*/
+ cin >> str;
+ return str;
+ }
+
+ const NLAIC::CIdentType &IOTrace::getType() const
+ {
+ static const NLAIC::CIdentType idIOWinInterface("IOWinInterface", NLAIC::CSelfClassFactory(*this),
+ NLAIC::CTypeOfObject(NLAIC::CTypeOfObject::tObject),NLAIC::CTypeOfOperator(0));
+ return idIOWinInterface;
+ }
+}
diff --git a/cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service/Attic/py_object_trans.cpp?rev=1.1&content-type=text/plain&hideattic=0/index.html b/cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service/Attic/py_object_trans.cpp?rev=1.1&content-type=text/plain&hideattic=0/index.html
new file mode 100644
index 00000000..92f3b304
--- /dev/null
+++ b/cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service/Attic/py_object_trans.cpp?rev=1.1&content-type=text/plain&hideattic=0/index.html
@@ -0,0 +1,132 @@
+#include "py_object_trans.h"
+//#include "ag_compile.h"
+
+
+namespace SRV
+{
+ static PyObject *commandSell(pyCPyEditWin *self, PyObject *arg)
+ {
+ char *txt;
+ PyObject *argi;
+ argi = PyTuple_GetItem (arg, 0);
+ PyArg_Parse(argi,"s",&txt);
+ txt[strlen(txt)] = 0;
+ char command[1024*16];
+#ifdef NL_DEBUG
+ memset(command,0,sizeof(command));
+#endif
+ int i = 0,j = 0;
+
+ while(txt[i] != 0)
+ {
+ if(txt[i] != '\n')
+ {
+ command[j] = txt[i];
+ j ++;
+ }
+ else
+ {
+ command[j] = 0;
+ self->Instance->commandSell(command);
+ j = 0;
+ }
+ i ++;
+ }
+ if(j)
+ {
+ command[j] = 0;
+ self->Instance->commandSell(command);
+ }
+ return Py_BuildValue("i",false);
+ }
+
+ static PyObject *coord(pyCPyEditWin *self, PyObject *arg)
+ {
+ char *txt;
+ PyObject *argi;
+ argi = PyTuple_GetItem (arg, 0);
+ PyArg_Parse(argi,"s",&txt);
+ //txt[strlen(txt)] = 0;
+ char num[1024];
+#ifdef NL_DEBUG
+ memset(num,0,sizeof(num));
+#endif
+ int i = 0,j = 0;
+ int x = -1,y = -1;
+ while(txt[i] != 0)
+ {
+ if(txt[i] == '.')
+ {
+ num[j] = 0;
+ x = atoi(num);
+ j = 0;
+ i++;
+ break;
+ }
+ else
+ {
+ num[j ++] = txt[i];
+ }
+ i ++;
+ }
+
+ while(1)
+ {
+ if(txt[i] == 0)
+ {
+ num[j] = 0;
+ y = atoi(num);
+ break;
+ }
+ else
+ {
+ num[j ++] = txt[i];
+ }
+ i ++;
+ }
+ return Py_BuildValue("ii",x,y);
+ }
+
+ static PyMethodDef V_methods[] =
+ {
+ {"commandSell", (PyCFunction) commandSell, 1, NULL},
+ {"coord", (PyCFunction) coord, 1, NULL},
+ {NULL, NULL} /* sentinel */
+ };
+
+ static PyObject *getAttribDigitalType(pyCPyEditWin *self,char *name)
+ {
+ return Py_FindMethod(V_methods, (PyObject *)self, name);
+ }
+
+ static void dealloc(pyCPyEditWin *self)
+ {
+ delete self;
+ }
+
+ staticforward PyTypeObject V_Type =
+ {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "Shell", /*tp_name*/
+ sizeof(pyCPyEditWin), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor)dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)getAttribDigitalType, /*tp_getattr*/
+ 0,
+ /* (setattrfunc)VConnection_setattr,*/ /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ };
+
+ pyCPyEditWin *allocPyEditWin(CPyEditWin *classType)
+ {
+ return NLAIC::CreatePyObjectInstance<CPyEditWin>(classType,&V_Type);
+ }
+}
diff --git a/cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service/Attic/server.cpp?rev=1.1&content-type=text/plain&hideattic=0/index.html b/cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service/Attic/server.cpp?rev=1.1&content-type=text/plain&hideattic=0/index.html
new file mode 100644
index 00000000..9c27da39
--- /dev/null
+++ b/cvs/cvsweb.cgi/~checkout~/code/nelns/agent_service/Attic/server.cpp?rev=1.1&content-type=text/plain&hideattic=0/index.html
@@ -0,0 +1,228 @@
+/** \file server.cpp
+ * <File description>
+ *
+ * $Id: server.cpp,v 1.1 2001/04/18 13:54:25 valignat Exp $
+ */
+
+/* Copyright, 2001 Nevrax Ltd.
+ *
+ * This file is part of NEVRAX NeL Network Services.
+ * NEVRAX NeL Network Services is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+
+ * NEVRAX NeL Network Services is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with NEVRAX NeL Network Services; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+#include <time.h>
+#include "nel/ai/agent/agent.h"
+#include "nel/ai/script/codage.h"
+#include "nel/ai/script/interpret_object_agent.h"
+#include "nel/ai/agent/main_agent_script.h"
+#include "nel/ai/script/libcode.h"
+#include "nel/misc/thread.h"
+
+#include "server.h"
+const char logFile[] = "compile.log";
+#include "filestream_n.h"
+#include "io_interface.h"
+#include "ag_compile.h"
+#include "init.h"
+
+namespace NLAISCRIPT
+{
+#ifdef NL_DEBUG
+ extern bool NL_AI_DEBUG_SERVER;
+#endif
+}
+
+
+namespace SRV
+{
+ std::fstream logStream;
+ bool logFileState = false;
+ SRV::IOTrace Interface;
+
+ TAgentId getId(const NLAIAGENT::CAgentNumber &num)
+ {
+ TAgentId i;
+ i.CreatorSId = num.CreatorId;
+ i.CurrentSId = num.DynamicId;
+ i.SerialNumber = num.AgentNumber;
+ return i;
+ }
+
+ NLAIAGENT::CAgentNumber getAgentId(TBasicAgentId &num)
+ {
+ NLAIAGENT::CAgentNumber i;
+ i.CreatorId = num.CreatorSId;
+ i.AgentNumber = num.SerialNumber;
+ return i;
+ }
+
+ CApplication::CApplication(const std::vector<std::string> &args):IManager(&Interface),_Active(true),_Shell(NULL),_Runnable(NULL),_ManagerRun(NULL)
+ {
+ Interface.incRef();
+ SRV::CPyEditWin::PyServer = NLAIPYSERVER::initPythonLib(&Interface,"./pyscript");
+ Interface.incRef();
+ SRV::CPyEditWin::inputOutput = &Interface;
+ Interface.incRef();
+ NLAISCRIPT::CCallPrint::inputOutput = &Interface;
+ if(logFileState) logStream.open(logFile, std::ios_base::in | std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
+ //init();
+ }
+
+ bool CApplication::isActive() const
+ {
+ return _Active;
+ }
+
+ NLAIAGENT::IRefrence *CApplication::agentIsPresent( TBasicAgentId baid ) const
+ {
+ const NLAIAGENT::CAgentNumber &id = getAgentId(baid);
+ return NLAIAGENT::CLocWordNumRef::getRef(NLAIAGENT::CNumericIndex(id));
+
+ }
+
+ void CApplication::deliverMsg( NLAIAGENT::IRefrence *ag, NLNET::CMessage& inmsg, TAgentId src_aid )
+ {
+ NLAIC::CIdentTypeAlloc msgFactory;
+ inmsg.serial( msgFactory );
+ NLAIAGENT::IObjectIA *msg = (NLAIAGENT::IObjectIA *) msgFactory.allocClass();
+ inmsg.serial( *msg );
+#ifdef NL_DEBUG
+ NLAISCRIPT::NL_AI_DEBUG_SERVER = true;
+#endif
+ ag->sendMessage(msg);
+ }
+
+ TAgentId CApplication::getAgentManagerId() const
+ {
+ const NLAIAGENT::CNumericIndex &id = ((const NLAIAGENT::IWordNumRef &)*this).getNumIdent();
+ return getId(id.getId());
+ }
+
+ void CApplication::declareNewManager( const TAgentId& agtid )
+ {
+ NLAIAGENT::CAgentNumber id;
+ id.CreatorId = agtid.CreatorSId;
+ id.DynamicId = agtid.CurrentSId;
+ id.AgentNumber = agtid.SerialNumber;
+
+ std::list<NLAIAGENT::CAgentNumber>::iterator itr = _AgentServerID.begin();
+ while(itr != _AgentServerID.end())
+ {
+ if(*(itr ++) == id) return;
+ }
+ _AgentServerID.push_back(id);
+ }
+
+ void CApplication::releaseManager( const TAgentId& agtid )
+ {
+ NLAIAGENT::CAgentNumber id;
+ id.CreatorId = agtid.CreatorSId;
+ id.DynamicId = agtid.CurrentSId;
+ id.AgentNumber = agtid.SerialNumber;
+
+ std::list<NLAIAGENT::CAgentNumber>::iterator itr = _AgentServerID.begin();
+ while(itr != _AgentServerID.end())
+ {
+ if(*(itr ++) == id)
+ {
+ _AgentServerID.erase(itr);
+ return;
+ }
+ }
+ }
+
+ void CApplication::correctAgentLocation( TAgentId new_aid )
+ {
+ }
+
+ NLAIAGENT::IObjectIA::CProcessResult CApplication::sendMessage(const NLAIAGENT::CAgentNumber &ref,NLAIAGENT::IObjectIA *m)
+ {
+ NLNET::CMessage msg("Ag");
+ msg.serial( (NLAIC::CIdentType &)m->getType() );
+ msg.serial(*m);
+ const NLAIAGENT::CNumericIndex &id = ((const NLAIAGENT::IWordNumRef &)*this).getNumIdent();
+ CAgentService::sendToAgent(getId(id.getId()),getId(ref),msg);
+ return NLAIAGENT::IObjectIA::CProcessResult();
+ }
+
+ void CApplication::init(NLMISC::CSynchronized<IManager *> &thisSync)
+ {
+ initServer();
+
+ bool i = haveActivity();
+
+ _Runnable = new SRV::CVoidRun(thisSync, _MessageList);
+ _ManagerRun = NLMISC::IThread::create(_Runnable);
+ _Runnable->setThread(_ManagerRun);
+ _Shell = new CPyEditWin(_MessageList,*_ManagerRun);
+ _ManagerRun->start();
+
+ const NLAIAGENT::CNumericIndex &id = ((const NLAIAGENT::IWordNumRef &)*this).getNumIdent();
+ char text[1024];
+ id.getDebugString(text);
+ _CodeContext->InputOutput->Echo("service %s is run\n",text);
+ }
+
+ clock_t start = clock() - 11;
+
+ NLAIAGENT::IObjectIA::CProcessResult CApplication::runActivity()
+ {
+
+ /*NLNET::CMessage msg("PING");
+ CMessageService m("PINGS",new CObjectSerial(msg));
+ CMsgTranslater::MsgTranslater->sendMessage((CMessageService *)m.clone());*/
+
+ /*double time = ((double)(clock() - start))/(double)CLOCKS_PER_SEC;
+ if(time >= 5)
+ {
+ NLAIAGENT::CGroupType g;
+ NLAIAGENT::CStringType *name = new NLAIAGENT::CStringType(NLAIAGENT::CStringVarName("Mektoube"));
+ name->incRef();
+ g.push(name);
+ CCreatureHerbivore *x = new CCreatureHerbivore(this);
+ x->incRef();
+ x->connect();
+ g.push(x);
+ addDynamicAgent(&g);
+ start = clock();
+ }*/
+
+ NLMISC::CSynchronized<CMsgTranslater *>::CAccessor a(CMsgTranslater::MsgTranslater);
+ a.value()->run();
+
+ return NLAIAGENT::IObjectIA::CProcessResult();
+ }
+
+ NLAIAGENT::IMessageBase *CApplication::runKill(const NLAIAGENT::IMessageBase &m)
+ {
+ _Active = false;
+ //_ManagerRun->terminate();
+ return (NLAIAGENT::IMessageBase *)m.clone();
+ }
+
+ void CApplication::leave()
+ {
+ _ManagerRun->terminate();
+ }
+
+ CApplication::~CApplication()
+ {
+ NLAIPYSERVER::endPythonInterface(SRV::CPyEditWin::PyServer);
+ if(logFileState) logStream.close();
+ _Shell->release();
+ delete _Runnable;
+ delete _ManagerRun;
+ }
+}