------------------------------------------------------------
revno: 30
committer: Rick Stovall <fpstovall>
branch nick: ricks-sprint-003
timestamp: Fri 2013-11-15 11:54:12 -0500
message:
  Completed the sim-engine's general purpuse message. Unit tested and ready to 
go.
added:
  cpp/sim_engine/messages/
  cpp/sim_engine/messages/Makefile
  cpp/sim_engine/messages/messages.cpp
  cpp/sim_engine/messages/messages.h
  cpp/sim_engine/messages/messages_test.cpp


--
lp:~fpstovall/nrtb/fps-sprint-003
https://code.launchpad.net/~fpstovall/nrtb/fps-sprint-003

Your team NRTB Core is subscribed to branch lp:~fpstovall/nrtb/fps-sprint-003.
To unsubscribe from this branch go to 
https://code.launchpad.net/~fpstovall/nrtb/fps-sprint-003/+edit-subscription
=== 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-15 16:54:12 +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-15 16:54:12 +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-15 16:54:12 +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-15 16:54:12 +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;
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

_______________________________________________
Mailing list: https://launchpad.net/~nrtb-core
Post to     : nrtb-core@lists.launchpad.net
Unsubscribe : https://launchpad.net/~nrtb-core
More help   : https://help.launchpad.net/ListHelp

Reply via email to