nrtb-core team mailing list archive
-
nrtb-core team
-
Mailing list archive
-
Message #00533
[Merge] lp:~fpstovall/nrtb/fps-sprint-003 into lp:nrtb
Rick Stovall has proposed merging lp:~fpstovall/nrtb/fps-sprint-003 into lp:nrtb.
Requested reviews:
NRTB Core (nrtb-core): code
Related bugs:
Bug #1217384 in New Real Time Battle: "tcp_server_socket_factory uses shared_ptr"
https://bugs.launchpad.net/nrtb/+bug/1217384
Bug #1217388 in New Real Time Battle: "abs_queue does not properly use move semantics"
https://bugs.launchpad.net/nrtb/+bug/1217388
For more details, see:
https://code.launchpad.net/~fpstovall/nrtb/fps-sprint-003/+merge/195485
Requesting merge of sprint 3, which includes a couple of bug fixes and the core of the internal messaging service. Unit tests are included and have been passed.
Also includes minor fixes to clean up the build process and simplify the addition of new modules.
--
https://code.launchpad.net/~fpstovall/nrtb/fps-sprint-003/+merge/195485
Your team NRTB Core is requested to review the proposed merge of lp:~fpstovall/nrtb/fps-sprint-003 into lp:nrtb.
=== modified file 'Makefile'
--- Makefile 2011-11-28 13:14:41 +0000
+++ Makefile 2013-11-16 20:43:39 +0000
@@ -33,6 +33,5 @@
@echo "========== all targets cleanup complete ==========="
doit:
- cd common; make ${action}
- cd sim_engine; make ${action}
+ cd cpp; make ${action}
=== added file 'cpp/Makefile'
--- cpp/Makefile 1970-01-01 00:00:00 +0000
+++ cpp/Makefile 2013-11-16 20:43:39 +0000
@@ -0,0 +1,31 @@
+#***********************************************
+#This file is part of the NRTB project (https://launchpad.net/nrtb).
+#
+# NRTB 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 3 of the License, or
+# (at your option) any later version.
+#
+# NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+#
+#***********************************************
+
+lib:
+ @echo "============= building C++ code ==============="
+ @make action=lib doit
+ @echo "============= C++ build complete ==============="
+
+clean:
+ @echo "============= cleaning common libs ==============="
+ @make action=clean doit
+ @echo "========== common lib cleanup complete ==========="
+
+doit:
+ @cd common; make ${action}
+ @cd sim_engine; make ${action}
=== modified file 'cpp/common/Makefile'
--- cpp/common/Makefile 2013-08-09 16:30:23 +0000
+++ cpp/common/Makefile 2013-11-16 20:43:39 +0000
@@ -47,6 +47,7 @@
@cd singleton; make ${action}
@cd logger; make ${action}
@cd confreader; make ${action}
+ @cd ipc_channel; make ${action}
# --- the following are obsolete and may be removed later.
# @cd threads; make ${action}
=== modified file 'cpp/common/abs_queue/abs_queue.h'
--- cpp/common/abs_queue/abs_queue.h 2013-06-30 18:37:44 +0000
+++ cpp/common/abs_queue/abs_queue.h 2013-11-16 20:43:39 +0000
@@ -117,7 +117,7 @@
in_count++;
{
std::unique_lock<std::mutex> lock(mylock);
- buffer.push(item);
+ buffer.push(std::move(item));
}
signal.notify_one();
}
@@ -136,10 +136,10 @@
signal.wait(lock);
if (ready)
{
- T returnme = buffer.front();
+ T returnme = std::move(buffer.front());
buffer.pop();
out_count++;
- return returnme;
+ return std::move(returnme);
}
else
{
=== modified file 'cpp/common/circular_queue/circular_queue.h'
--- cpp/common/circular_queue/circular_queue.h 2013-06-30 19:22:02 +0000
+++ cpp/common/circular_queue/circular_queue.h 2013-11-16 20:43:39 +0000
@@ -35,7 +35,7 @@
class base_cq : public boost::circular_buffer<T>
{
public:
- void push(T elem) { this->push_back(elem); };
+ void push(T elem) { this->push_back(std::move(elem)); };
void pop() { this->pop_front(); };
};
=== added directory 'cpp/common/ipc_channel'
=== added file 'cpp/common/ipc_channel/Makefile'
--- cpp/common/ipc_channel/Makefile 1970-01-01 00:00:00 +0000
+++ cpp/common/ipc_channel/Makefile 2013-11-16 20:43:39 +0000
@@ -0,0 +1,47 @@
+#***********************************************
+# This file is part of the NRTB project (https://launchpad.net/nrtb).
+#
+# NRTB 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 3 of the License, or
+# (at your option) any later version.
+#
+# NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+#
+#***********************************************
+
+target=ipc_channel
+
+lib: ${target}_test
+ @./${target}_test
+ @cp -v ${target}.h ../include/
+ @cp -v ${target}.o ../obj/
+ @echo build complete
+
+${target}_test: ${target}.o ${target}_test.cpp
+ @rm -f ${target}_test
+ g++ -c -O3 ${target}_test.cpp -I ../include ${bargs}
+ g++ -o ${target}_test ${target}_test.o ${target}.o ${largs}
+
+
+${target}.o: ${target}.cpp ${target}.h Makefile
+ @rm -f ${target}.o
+ g++ -c -O3 ${target}.cpp -I ../include ${bargs}
+
+clean:
+ @rm -vf *.o ../include/${target}.h ../obj/${target}.o ${target}_test
+ @echo all objects and executables have been erased.
+
+switches=-std=gnu++11 -D _GLIBCXX_USE_SCHED_YIELD -D _GLIBCXX_USE_NANOSLEEP
+libs=../obj/common.o ../obj/logger.o ../obj/serializer.o -lpthread
+include=-I../include
+bargs=${switches} ${include}
+largs=${switches} ${libs}
+
+
=== added file 'cpp/common/ipc_channel/ipc_channel.cpp'
--- cpp/common/ipc_channel/ipc_channel.cpp 1970-01-01 00:00:00 +0000
+++ cpp/common/ipc_channel/ipc_channel.cpp 2013-11-16 20:43:39 +0000
@@ -0,0 +1,44 @@
+/***********************************************
+ This file is part of the NRTB project (https://*launchpad.net/nrtb).
+
+ NRTB 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 3 of the License, or
+ (at your option) any later version.
+
+ NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+
+ **********************************************/
+
+// see base_socket.h for documentation
+
+#include "ipc_channel.h"
+
+namespace nrtb
+{
+abs_ipc_record::abs_ipc_record(ipc_queue& q):
+ return_to(q) {};
+
+ipc_queue& ipc_channel_manager::get(std::string name)
+{
+ return channels[name];
+};
+
+ipc_channel_manager::iterator ipc_channel_manager::begin()
+{
+ return channels.begin();
+};
+
+ipc_channel_manager::iterator ipc_channel_manager::end()
+{
+ return channels.end();
+}
+
+} // namespace nrtb
+
=== added file 'cpp/common/ipc_channel/ipc_channel.h'
--- cpp/common/ipc_channel/ipc_channel.h 1970-01-01 00:00:00 +0000
+++ cpp/common/ipc_channel/ipc_channel.h 2013-11-16 20:43:39 +0000
@@ -0,0 +1,75 @@
+/***********************************************
+ This file is part of the NRTB project (https://*launchpad.net/nrtb).
+
+ NRTB 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 3 of the License, or
+ (at your option) any later version.
+
+ NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+
+ **********************************************/
+
+#ifndef ipc_channel_header
+#define ipc_channel_header
+
+#include <common.h>
+#include <linear_queue.h>
+#include <memory>
+#include <singleton.h>
+
+
+namespace nrtb
+{
+
+class abs_ipc_record;
+
+typedef std::unique_ptr<abs_ipc_record> ipc_record_p;
+
+typedef linear_queue<ipc_record_p> ipc_queue;
+
+/** abs_ipc_record is the base for all ipc messages.
+ * This abstract includes a return_address (the
+ * ipc_queue the a return should be put to). but
+ * no other payload. It'll need to be overriden to
+ * provide whatever payload a given channel may
+ * need.
+ */
+class abs_ipc_record
+{
+public:
+ ipc_queue & return_to;
+ abs_ipc_record(ipc_queue & q);
+};
+
+/** ipc_channel_manager provides a place to stash ipc_queues
+ * so that their scope is not tied to the lifetime of any
+ * particular thread. Ideally, this should be used as s
+ * singleton class.
+ */
+class ipc_channel_manager
+{
+public:
+ typedef std::map<std::string,ipc_queue> channel_List;
+ typedef channel_List::iterator iterator;
+
+ ipc_queue & get(std::string name);
+ iterator begin();
+ iterator end();
+
+private:
+ channel_List channels;
+};
+
+/// And here is the singleton class to make ipc channels safe.
+typedef singleton<ipc_channel_manager> global_ipc_channel_manager;
+
+} // namepace nrtb
+
+#endif // ipc_channel_header
=== added file 'cpp/common/ipc_channel/ipc_channel_test.cpp'
--- cpp/common/ipc_channel/ipc_channel_test.cpp 1970-01-01 00:00:00 +0000
+++ cpp/common/ipc_channel/ipc_channel_test.cpp 2013-11-16 20:43:39 +0000
@@ -0,0 +1,133 @@
+/***********************************************
+ This file is part of the NRTB project (https://*launchpad.net/nrtb).
+
+ NRTB 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 3 of the License, or
+ (at your option) any later version.
+
+ NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+
+ **********************************************/
+
+#include "ipc_channel.h"
+#include <iostream>
+#include <future>
+
+using namespace nrtb;
+using namespace std;
+
+class main_msg: public abs_ipc_record
+{
+public:
+ using abs_ipc_record::abs_ipc_record;
+ int msg_num;
+};
+
+typedef main_msg * main_msg_p;
+
+class worker_msg: public abs_ipc_record
+{
+public:
+ using abs_ipc_record::abs_ipc_record;
+ int ret_num;
+};
+
+typedef worker_msg * worker_msg_p;
+
+int worker(int limit)
+{
+ cout << "worker started" << endl;
+ global_ipc_channel_manager & ipc
+ = global_ipc_channel_manager::get_reference();
+ ipc_queue & in = ipc.get("worker");
+ ipc_queue & out = ipc.get("main");
+ int total(0);
+ while (total < limit)
+ {
+ ipc_record_p raw_msg = in.pop();
+ main_msg_p msg = static_cast<main_msg_p>(raw_msg.get());
+ worker_msg_p outmsg(new worker_msg(in));
+ outmsg->ret_num = msg->msg_num;
+ msg->return_to.push(ipc_record_p(outmsg));
+ total++;
+ };
+ cout << "worker ended" << endl;
+ return total;
+};
+
+int main()
+{
+ cout << "=========== IPC Channel test ============="
+ << endl;
+
+ global_ipc_channel_manager & ipc
+ = global_ipc_channel_manager::get_reference();
+ ipc_queue & in = ipc.get("main");
+ ipc_queue & out = ipc.get("worker");
+ int limit = 100;
+ // start the worker here.
+ auto worktask = async(launch::async,worker,limit);
+
+ for (int i(0); i<limit; i++)
+ {
+ main_msg_p msg(new main_msg(in));
+ msg->msg_num = i;
+ out.push(ipc_record_p(msg));
+ };
+
+ cout << "processed " << worktask.get() << endl;
+
+ while (in.size())
+ {
+ ipc_record_p raw = in.pop();
+ worker_msg_p reply = static_cast<worker_msg_p>(raw.get());
+ };
+
+ auto b = ipc.begin();
+ auto e = ipc.end();
+ for (auto i = b; i != e; i++)
+ {
+ cout << i->first << ": "
+ << i->second.in_count << " | "
+ << i->second.out_count << endl;
+ }
+
+ cout << "=========== IPC Channel test complete ============="
+ << endl;
+
+ return !(out.in_count == in.out_count);
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
=== modified file 'cpp/common/sockets/base_socket.cpp'
--- cpp/common/sockets/base_socket.cpp 2013-07-14 18:47:08 +0000
+++ cpp/common/sockets/base_socket.cpp 2013-11-16 20:43:39 +0000
@@ -541,16 +541,13 @@
return sockaddr_to_str(myaddr);
};
-
tcp_server_socket_factory::tcp_server_socket_factory(
const string & address,
- const unsigned short int backlog,
- const int queue_size)
+ const unsigned short int backlog)
{
// does not attempt to set up the connection initially.
_address = address;
_backlog = backlog;
- pending.resize(queue_size);
};
tcp_server_socket_factory::~tcp_server_socket_factory()
@@ -561,6 +558,13 @@
try { stop_listen(); } catch (...) {};
};
+tcp_socket_p tcp_server_socket_factory::get_sock()
+{
+ tcp_socket_p returnme = std::move(pending.pop());
+ return std::move(returnme);
+};
+
+
void tcp_server_socket_factory::start_listen()
{
// take no action if the listen thread is already running.
@@ -725,7 +729,7 @@
if (good_connect)
{
tcp_socket_p storeme(new tcp_socket(new_conn));
- server->pending.push(storeme);
+ server->pending.push(std::move(storeme));
};
}; // while go;
}
=== modified file 'cpp/common/sockets/base_socket.h'
--- cpp/common/sockets/base_socket.h 2013-07-14 18:47:08 +0000
+++ cpp/common/sockets/base_socket.h 2013-11-16 20:43:39 +0000
@@ -23,7 +23,7 @@
#include <atomic>
#include <thread>
#include <common.h>
-#include <circular_queue.h>
+#include <linear_queue.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -376,7 +376,7 @@
};
/// smart pointer for use with tcp_sockets
-typedef std::shared_ptr<nrtb::tcp_socket> tcp_socket_p;
+typedef std::unique_ptr<nrtb::tcp_socket> tcp_socket_p;
/** "listener" TCP/IP socket socket factory for servers.
**
@@ -400,7 +400,7 @@
/// Thrown by by the listen thread in case of unexpected error.
class listen_terminated_exception: public general_exception {};
/// handlers should catch this and shutdown gracefully.
- typedef circular_queue<tcp_socket_p>::queue_not_ready queue_not_ready;
+ typedef linear_queue<tcp_socket_p>::queue_not_ready queue_not_ready;
/** Construct a tcp_server_socket_factory and puts it online.
**
@@ -419,8 +419,7 @@
** exceeded, oldest connections will be discarded.
**/
tcp_server_socket_factory(const std::string & address,
- const unsigned short int backlog = 5,
- const int queue_size=10);
+ const unsigned short int backlog = 5);
/** Destructs a server_sock.
**
@@ -433,7 +432,7 @@
virtual ~tcp_server_socket_factory();
/// Consumers call this to get a connected socket.
- tcp_socket_p get_sock() { return pending.pop(); };
+ tcp_socket_p get_sock();
/// returns the number of connections received.
int accepted() { return pending.in_count; };
@@ -512,7 +511,7 @@
std::atomic< int > _last_thread_fault {0};
std::atomic< bool > in_run_method {false};
// The accepted inbound connection queue
- nrtb::circular_queue<tcp_socket_p> pending;
+ nrtb::linear_queue<tcp_socket_p> pending;
// Provides the listener thread.
static void run(tcp_server_socket_factory * server);
=== modified file 'cpp/sim_engine/Makefile'
--- cpp/sim_engine/Makefile 2011-11-28 12:32:56 +0000
+++ cpp/sim_engine/Makefile 2013-11-16 20:43:39 +0000
@@ -21,9 +21,6 @@
./bin/nrtb_simulation: ../common/nrtb_common.a
@echo "============= building simulation engine ==============="
@make action=lib doit
- #temp target
- touch ./bin/nrtb_simulation
- @echo temp target created.
@echo "============= simulation engine complete ==============="
modules:
@@ -38,7 +35,9 @@
@echo "========== simulation engine cleanup complete ==========="
doit:
- cd comm_manager; make ${action}
+ cd messages; make ${action}
+ cd main; make ${action}
+# cd comm_manager; make ${action}
../common/nrtb_common.a:
@cd ../common; make
=== added directory 'cpp/sim_engine/control_interface'
=== added file 'cpp/sim_engine/control_interface/Makefile'
--- cpp/sim_engine/control_interface/Makefile 1970-01-01 00:00:00 +0000
+++ cpp/sim_engine/control_interface/Makefile 2013-11-16 20:43:39 +0000
@@ -0,0 +1,47 @@
+#***********************************************
+# This file is part of the NRTB project (https://launchpad.net/nrtb).
+#
+# NRTB 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 3 of the License, or
+# (at your option) any later version.
+#
+# NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+#
+#***********************************************
+
+target=control_interface
+
+lib: ${target}_test
+ @./${target}_test
+ @cp -v ${target}.h ../include/
+ @cp -v ${target}.o ../obj/
+ @echo build complete
+
+${target}_test: ${target}.o ${target}_test.cpp
+ @rm -f ${target}_test
+ g++ -c -O3 ${target}_test.cpp -I ../include ${bargs}
+ g++ -o ${target}_test ${target}_test.o ${target}.o ${largs}
+
+
+${target}.o: ${target}.cpp ${target}.h Makefile
+ @rm -f ${target}.o
+ g++ -c -O3 ${target}.cpp -I ../include ${bargs}
+
+clean:
+ @rm -vf *.o ../include/${target}.h ../obj/${target}.o ${target}_test
+ @echo all objects and executables have been erased.
+
+switches=-std=gnu++11 -D _GLIBCXX_USE_SCHED_YIELD -D _GLIBCXX_USE_NANOSLEEP
+libs=../../common/lib/nrtb_common.a -lpthread
+include=-I../../common/include -I../include
+bargs=${switches} ${include}
+largs=${switches} ${libs}
+
+
=== added file 'cpp/sim_engine/control_interface/control_interface.cpp'
--- cpp/sim_engine/control_interface/control_interface.cpp 1970-01-01 00:00:00 +0000
+++ cpp/sim_engine/control_interface/control_interface.cpp 2013-11-16 20:43:39 +0000
@@ -0,0 +1,27 @@
+/***********************************************
+ This file is part of the NRTB project (https://*launchpad.net/nrtb).
+
+ NRTB 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 3 of the License, or
+ (at your option) any later version.
+
+ NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+
+ **********************************************/
+
+// see base_socket.h for documentation
+
+#include "control_interface.h"
+
+namespace nrtb
+{
+
+} // namespace nrtb
+
=== added file 'cpp/sim_engine/control_interface/control_interface.h'
--- cpp/sim_engine/control_interface/control_interface.h 1970-01-01 00:00:00 +0000
+++ cpp/sim_engine/control_interface/control_interface.h 2013-11-16 20:43:39 +0000
@@ -0,0 +1,50 @@
+/***********************************************
+ This file is part of the NRTB project (https://*launchpad.net/nrtb).
+
+ NRTB 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 3 of the License, or
+ (at your option) any later version.
+
+ NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+
+ **********************************************/
+
+#ifndef control_interface_header
+#define control_interface_header
+
+#include <ipc_channel.h>
+#include <base_socket.h>
+
+namespace nrtb
+{
+
+enum class
+
+class ci_main_msg: public abs_ipc_record
+{
+public:
+ enum {start,stop,status,load,shutdown};
+ int msg;
+ std::string arg;
+};
+
+typedef ci_main_msg * ci_main_msg_p;
+
+class main_ci_msg: public abs_ipc_record
+{
+public:
+ enum {start,stop,status,load,shutdown};
+
+ strlist lines;
+};
+
+} // namepace nrtb
+
+#endif // control_interface_header
=== added file 'cpp/sim_engine/control_interface/control_interface_test.cpp'
--- cpp/sim_engine/control_interface/control_interface_test.cpp 1970-01-01 00:00:00 +0000
+++ cpp/sim_engine/control_interface/control_interface_test.cpp 2013-11-16 20:43:39 +0000
@@ -0,0 +1,60 @@
+/***********************************************
+ This file is part of the NRTB project (https://*launchpad.net/nrtb).
+
+ NRTB 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 3 of the License, or
+ (at your option) any later version.
+
+ NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+
+ **********************************************/
+
+#include "control_interface.h"
+
+using namespace nrtb;
+using namespace std;
+
+
+int main()
+{
+ cout << "=========== tcp_socket and server test ============="
+ << endl;
+
+ cout << "=========== tcp_socket and server test complete ============="
+ << endl;
+
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
=== added directory 'cpp/sim_engine/main'
=== added file 'cpp/sim_engine/main/Makefile'
--- cpp/sim_engine/main/Makefile 1970-01-01 00:00:00 +0000
+++ cpp/sim_engine/main/Makefile 2013-11-16 20:43:39 +0000
@@ -0,0 +1,40 @@
+#***********************************************
+# This file is part of the NRTB project (https://launchpad.net/nrtb).
+#
+# NRTB 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 3 of the License, or
+# (at your option) any later version.
+#
+# NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+#
+#***********************************************
+
+target=../bin/simengine
+
+${target}: simengine.o
+ @rm -f ${target}
+ g++ -o ${target} simengine.o ${largs}
+
+
+simengine.o: simengine.cpp Makefile
+ @rm -f simengine.o
+ g++ -c -O3 simengine.cpp ${bargs}
+
+clean:
+ @rm -vf *.o ${target}
+ @echo all objects and executables have been erased.
+
+lib: ${target}
+
+switches=-std=gnu++11 -D _GLIBCXX_USE_SCHED_YIELD -D _GLIBCXX_USE_NANOSLEEP
+libs=../../common/lib/nrtb_common.a -lpthread
+include=-I../../common/include -I../include
+bargs=${switches} ${include}
+largs=${switches} ${libs}
=== added file 'cpp/sim_engine/main/simengine.cpp'
--- cpp/sim_engine/main/simengine.cpp 1970-01-01 00:00:00 +0000
+++ cpp/sim_engine/main/simengine.cpp 2013-11-16 20:43:39 +0000
@@ -0,0 +1,81 @@
+/***********************************************
+ This file is part of the NRTB project (https://*launchpad.net/nrtb).
+
+ NRTB 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 3 of the License, or
+ (at your option) any later version.
+
+ NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+
+ **********************************************/
+
+#include <common.h>
+#include <logger.h>
+#include <confreader.h>
+
+using namespace nrtb;
+using namespace std;
+
+int main(int argc, char * argv[])
+{
+ // load the global configuration
+ conf_reader config;
+ config.read(argc, argv, "simengine.conf");
+
+ // start the system logger
+ log_queue g_log_queue;
+ log_file_writer g_log_writer(g_log_queue,
+ config.get<string>("global_log_file","simengine.log"));
+ // create our recorder
+ log_recorder g_log("main",g_log_queue);
+
+ // Report our startup and configuration.
+ g_log.info("Start up");
+ g_log.info("Configuration Follows");
+ for (auto i : config)
+ {
+ g_log.info(i.first+" = "+i.second);
+ };
+ g_log.info("Configuration list complete");
+
+ // Any modules called from here should be passed the
+ // g_log_queue and config by reference.
+
+
+ // say goodbye
+ g_log.info("Shut down");
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
=== added directory 'cpp/sim_engine/messages'
=== added file 'cpp/sim_engine/messages/Makefile'
--- cpp/sim_engine/messages/Makefile 1970-01-01 00:00:00 +0000
+++ cpp/sim_engine/messages/Makefile 2013-11-16 20:43:39 +0000
@@ -0,0 +1,47 @@
+#***********************************************
+# This file is part of the NRTB project (https://launchpad.net/nrtb).
+#
+# NRTB 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 3 of the License, or
+# (at your option) any later version.
+#
+# NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+#
+#***********************************************
+
+target=messages
+
+lib: ${target}_test
+ @./${target}_test
+ @cp -v ${target}.h ../include/
+ @cp -v ${target}.o ../obj/
+ @echo build complete
+
+${target}_test: ${target}.o ${target}_test.cpp
+ @rm -f ${target}_test
+ g++ -c -O3 ${target}_test.cpp -I ../include ${bargs}
+ g++ -o ${target}_test ${target}_test.o ${target}.o ${largs}
+
+
+${target}.o: ${target}.cpp ${target}.h Makefile
+ @rm -f ${target}.o
+ g++ -c -O3 ${target}.cpp -I ../include ${bargs}
+
+clean:
+ @rm -vf *.o ../include/${target}.h ../obj/${target}.o ${target}_test
+ @echo all objects and executables have been erased.
+
+switches=-std=gnu++11 -D _GLIBCXX_USE_SCHED_YIELD -D _GLIBCXX_USE_NANOSLEEP
+libs=../../common/lib/nrtb_common.a -lpthread
+include=-I../../common/include -I../include
+bargs=${switches} ${include}
+largs=${switches} ${libs}
+
+
=== added file 'cpp/sim_engine/messages/messages.cpp'
--- cpp/sim_engine/messages/messages.cpp 1970-01-01 00:00:00 +0000
+++ cpp/sim_engine/messages/messages.cpp 2013-11-16 20:43:39 +0000
@@ -0,0 +1,62 @@
+/***********************************************
+ This file is part of the NRTB project (https://*launchpad.net/nrtb).
+
+ NRTB 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 3 of the License, or
+ (at your option) any later version.
+
+ NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+
+ **********************************************/
+
+// see base_socket.h for documentation
+
+#include "messages.h"
+#include <sstream>
+
+using namespace nrtb;
+
+gp_sim_message::gp_sim_message(ipc_queue& q, int t, int n, int v)
+ : abs_ipc_record(q), _noun (n), _verb (v), _type (t)
+{
+ _data.reset();
+};
+
+gp_sim_message::gp_sim_message(ipc_queue & q, int t,
+ int n, int v, void_p d)
+: abs_ipc_record(q), _noun (n), _verb (v), _type (t), _data (d)
+{
+ // no actions to take.
+};
+
+int gp_sim_message::msg_type()
+{
+ return _type;
+};
+
+std::string gp_sim_message::as_str()
+{
+ std::stringstream t;
+ t << _type << ":"
+ << _noun << ":"
+ << _verb << ":"
+ << _data.get();
+ return t.str();
+};
+
+int gp_sim_message::noun()
+{
+ return _noun;
+};
+
+int gp_sim_message::verb()
+{
+ return _verb;
+};
=== added file 'cpp/sim_engine/messages/messages.h'
--- cpp/sim_engine/messages/messages.h 1970-01-01 00:00:00 +0000
+++ cpp/sim_engine/messages/messages.h 2013-11-16 20:43:39 +0000
@@ -0,0 +1,61 @@
+/***********************************************
+ This file is part of the NRTB project (https://*launchpad.net/nrtb).
+
+ NRTB 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 3 of the License, or
+ (at your option) any later version.
+
+ NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+
+ **********************************************/
+
+#ifndef sim_messages_header
+#define sim_messages_header
+
+#include <ipc_channel.h>
+#include <memory>
+
+
+namespace nrtb
+{
+
+typedef std::shared_ptr<void> void_p;
+
+class gp_sim_message : public abs_ipc_record
+{
+public:
+ gp_sim_message(ipc_queue & q, int t, int n, int v);
+ gp_sim_message(ipc_queue & q, int t, int n, int v, void_p d);
+ int msg_type();
+ std::string as_str();
+ int noun();
+ int verb();
+ template <class T>
+ T & data();
+private:
+ int _noun;
+ int _verb;
+ int _type;
+ void_p _data;
+};
+
+typedef gp_sim_message * gp_sim_message_p;
+
+
+template <class T>
+ T & gp_sim_message::data()
+{
+ return *(static_cast<T*>(_data.get()));
+};
+
+
+} // namepace nrtb
+
+#endif // sim_messages_header
=== added file 'cpp/sim_engine/messages/messages_test.cpp'
--- cpp/sim_engine/messages/messages_test.cpp 1970-01-01 00:00:00 +0000
+++ cpp/sim_engine/messages/messages_test.cpp 2013-11-16 20:43:39 +0000
@@ -0,0 +1,85 @@
+/***********************************************
+ This file is part of the NRTB project (https://*launchpad.net/nrtb).
+
+ NRTB 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 3 of the License, or
+ (at your option) any later version.
+
+ NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
+
+ **********************************************/
+
+#include "messages.h"
+#include <iostream>
+#include <string>
+
+using namespace nrtb;
+using namespace std;
+
+typedef shared_ptr<string> string_p;
+
+int main()
+{
+ cout << "=========== sim messages test ============="
+ << endl;
+
+ ipc_queue queue;
+
+ void_p s(new string("this is a test"));
+
+ queue.push(ipc_record_p(new gp_sim_message(queue, 1, 1, 0)));
+ queue.push(ipc_record_p(new gp_sim_message(queue, 2, 1, 1, s)));
+
+ ipc_record_p raw(queue.pop());
+ gp_sim_message_p msg = static_cast<gp_sim_message_p>(raw.get());
+ cout << msg->as_str() << endl;
+ bool failed = (msg->as_str() != "1:1:0:0");
+
+ raw = queue.pop();
+ msg = static_cast<gp_sim_message_p>(raw.get());
+ cout << msg->as_str() << endl;
+ failed = failed
+ or (msg->msg_type() != 2)
+ or (msg->noun() != 1)
+ or (msg->verb() != 1)
+ or (msg->data<string>() != "this is a test");
+
+ cout << "=========== sim_messages test complete ============="
+ << endl;
+
+ return failed;
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
=== removed directory 'cpp/sim_engine/physics'
=== removed file 'cpp/sim_engine/physics/Makefile'
--- cpp/sim_engine/physics/Makefile 2011-09-19 02:03:55 +0000
+++ cpp/sim_engine/physics/Makefile 1970-01-01 00:00:00 +0000
@@ -1,45 +0,0 @@
-#***********************************************
-#This file is part of the NRTB project (https://launchpad.net/nrtb).
-#
-# NRTB 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 3 of the License, or
-# (at your option) any later version.
-#
-# NRTB 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 NRTB. If not, see <http://www.gnu.org/licenses/>.
-#
-#***********************************************
-
-lib: ../lib/nrtb_physics.a
-
-../lib/nrtb_physics.a: ../../commmon/lib.nrtb_common.a
- @echo "============= building physics ==============="
- @make action=lib doit
- @ar -r ../lib/nrtb_physics.a ./obj/*.o
- @cp -v ./include/* ../include
- @echo "============= physics complete ==============="
-
-../../commmon/lib.nrtb_common.a:
- @cd ../../common; make
-
-modules:
- @echo "============= building physics modules ==============="
- @make doit
- @echo "============= completed physics modules =============="
-
-clean:
- @echo "============= cleaning physics ==============="
- @cd include; for file in *; do rm -fv ../include/$$file; done
- @make action=clean doit
- @rm -fv ./obj/* ./lib/* ./include/*
- @echo "========== physics cleanup complete ==========="
-
-doit:
-# @cd abstract_effector; make ${action}
-# @cd point_mass; make ${action}
=== removed directory 'cpp/sim_engine/physics/abstract_effector'
=== removed directory 'cpp/sim_engine/physics/include'
=== removed directory 'cpp/sim_engine/physics/obj'
=== removed directory 'cpp/sim_engine/physics/rigid_body'
Follow ups