Add README to ocicuc; add small_example near-minimal demo program;
authorJesse Williamson <jesse.f.williamson@intel.com>
Fri, 3 Oct 2014 22:15:14 +0000 (15:15 -0700)
committerJesse Williamson <jesse.f.williamson@intel.com>
Fri, 3 Oct 2014 22:16:36 +0000 (15:16 -0700)
Miscellaneous small fixes.

Change-Id: I8fc65b8eca5c05e231c2820ccdb8ca8237eb084e

examples/ocicuc/Makefile
examples/ocicuc/README [new file with mode: 0644]
examples/ocicuc/exec.hpp
examples/ocicuc/monoprocess.cpp
examples/ocicuc/small_example.cpp [new file with mode: 0644]

index 56d61ad..88bce11 100644 (file)
@@ -22,11 +22,12 @@ BUILD:=release
 PLATFORM:=linux
 
 OCLIB=../..
-OCLIB_LIB=../../$(BUILD)/obj/liboc.a 
+OCLIB_LIB=../../$(BUILD)/obj/liboc.a
 
 CXX_FLAGS.debug     := -g3 -O0
 CXX_FLAGS.release   := -O3
-CXX_FLAGS:=-Wall -std=c++0x -ggdb $(CXX_FLAGS.$(BUILD)) -pthread
+
+CXX_FLAGS:=-Werror -Wall -std=c++0x -ggdb $(CXX_FLAGS.$(BUILD)) -pthread
 
 # There's probably nicer Makefile magic for this, but hopefully it will suffice:
 CXX_INC=-I$(OCLIB)/include \
@@ -44,20 +45,18 @@ LIB_OC_LOGGER:=../../oc_logger/lib/oc_logger.a
 
 CXX_LIBS=$(OCLIB_LIB) ../../csdk/$(PLATFORM)/$(BUILD)/liboctbstack.a $(LIB_OC_LOGGER) $(BOOST_LIBS)
 
-APPS += client 
-APPS += server 
-APPS += monoprocess 
+APPS += client
+APPS += server
+APPS += monoprocess
+APPS += small_example
 
 .PHONY: client server
 
-all: oc_cpp_sdk apps
+all: apps
        @echo Remember to \"export LD_LIBRARY_PATH=$(BOOST_LIB)\:\$$LD_LIBRARY_PATH\"
 
 apps: $(APPS)
 
-oc_cpp_sdk:
-       cd ../../ && $(MAKE) cpp_sdk "BUILD=$(BUILD)"
-
 %.o: %.cpp
        $(CXX) $(CXXFLAGS) $(CXX_FLAGS) $(CXX_INC) -c -o $@ $<
 
@@ -70,10 +69,13 @@ server: server.o driver.o utility.o light_resource.o
 monoprocess: monoprocess.o driver.o utility.o light_resource.o
        $(CXX) $(CXX_FLAGS) -o $@ $^ $(CXX_LIBS)
 
+small_example: small_example.o driver.o utility.o
+       $(CXX) $(CXX_FLAGS) -o $@ $^ $(CXX_LIBS)
+
 clean:
        rm -f *.o $(APPS)
-       cd ../../ && $(MAKE) clean_cpp_sdk      
+       cd ../../ && $(MAKE) clean_cpp_sdk
 
 clean_apps:
        rm -f *.o $(APPS)
-       
+
diff --git a/examples/ocicuc/README b/examples/ocicuc/README
new file mode 100644 (file)
index 0000000..d0d99b7
--- /dev/null
@@ -0,0 +1,49 @@
+
+OCICUC is a light framework for rapidly building OIC test/demo/example applications. It provides pre-built
+entry points and handling for things like command line parameters and modularlizes resources, so that
+adding new features or building a new test application is a lightweight undertaking.
+
+.
+├── client.cpp                           - a multi-resource client, similar to simpleclient
+├── demo_client.hpp                      - client code, shared between client and multiprocess programs
+├── driver.cpp                           - ocicuc base driver program
+├── exec.hpp                             - header for binding with the driver
+├── light_resource.cpp           - example resource
+├── light_resource.hpp           - example resource
+├── monoprocess.cpp                      - client and server in a single process
+├── server.cpp                           - a multi-resource server, similar to simpleserver
+├── small_example.cpp            - a near-minimal example program
+├── utility.cpp                          - utility functions for the demo programs
+└── utility.hpp                          - utility functions
+
+You can extend the existing programs to add new resource types, etc.. Refer to the help screen for each program
+for further details. For instance, to start a server with 5 resources and then test it with a separate client,
+you could run:
+
+       ./server --nres=5
+
+...and, in another shell:
+
+       ./client --nres=5
+
+To build a new program that hooks into the ocicuc driver program, you just need to define the functions in "exec.hpp",
+for example:
+
+namespace Intel { namespace OCDemo {
+
+int exec(const boost::program_options::variables_map& vm);
+
+auto make_description()
+    -> boost::program_options::options_description;
+
+}} // namespace Intel::OCDemo
+
+You can see an example of a skeleton program in small_example.cpp.
+
+To run a program with default parameters, use "--", for example:
+
+./monoprocess --
+
+Have fun!
+
+
index 0b4f6c5..f1ff62a 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <boost/program_options.hpp>
 
+/* Interface point for the driver code. Your program needs to implement these
+functions: */
 namespace Intel { namespace OCDemo {
 
 int exec(const boost::program_options::variables_map& vm);
@@ -30,9 +32,6 @@ int exec(const boost::program_options::variables_map& vm);
 auto make_description()
     -> boost::program_options::options_description;
 
-auto parse_options(boost::program_options::options_description& desc, int argc, char *argv[]) 
-    -> boost::program_options::variables_map;
-
 }} // namespace Intel::OCDemo
 
 #endif
index c6e50a6..72d974e 100644 (file)
@@ -49,13 +49,12 @@ auto make_description()
 
  po::options_description desc("Monoprocess Client/Server options");
 
-std::cout << "JFW: TODO: separate IP/port/etc. for server and client!\n";
  desc.add_options()
-    ("nres",        po::value<unsigned long>()->default_value(1),         "number of resources to use for testing")
+    ("nres",        po::value<unsigned long>()->default_value(1),  "number of resources to use for testing")
     ("host_ip",     po::value<string>()->default_value("0.0.0.0"), "IP of host")
-    ("host_port",   po::value<uint16_t>()->default_value(0),           "port of host")
-    ("interface",   po::value<string>()->default_value("eth0"),           "network interface name")
-    ("uri",         po::value<vector<string>>(),                          "resource URI")
+    ("host_port",   po::value<uint16_t>()->default_value(0),       "port of host")
+    ("interface",   po::value<string>()->default_value("eth0"),    "network interface name")
+    ("uri",         po::value<vector<string>>(),                   "resource URI")
     ;
 
  return desc;
diff --git a/examples/ocicuc/small_example.cpp b/examples/ocicuc/small_example.cpp
new file mode 100644 (file)
index 0000000..2773283
--- /dev/null
@@ -0,0 +1,44 @@
+/* Example program for fitting in with the ocicuc driver program: */
+
+#include "exec.hpp"
+
+#include <iostream>
+
+namespace Intel { namespace OCDemo {
+
+/* exec() is essentially main(), and is where the driver will start your
+program after command-line options have been parsed: */
+int exec(const boost::program_options::variables_map& vm)
+{
+ using std::cout;
+
+ cout << "This is the start of my wonderful program!\n";
+
+ cout << "My command-line options are:\n";
+
+ for(const auto& o : vm)
+  cout << o.first << " => " << o.second.as<std::string>() << '\n';
+
+ return 0;
+}
+
+/* make_description() is your opportunity to describe your program's help screen and command
+line parameter types. Refer to the boost::program_options library for details on how to
+add different kinds of command-line options: */
+auto make_description()
+    -> boost::program_options::options_description
+{
+ namespace po = boost::program_options;     // because boost::program_options is a lot to type!
+
+ po::options_description desc("My wonderful program's options! Run with \"--\" to simply use the defaults.");
+
+ desc.add_options()
+    ("param",   po::value<std::string>()->default_value("Hello, World!"),   "description of param")
+    ;
+
+ return desc;
+}
+
+}} // namespace Intel::OCDemo
+
+