Initial commit of "Plugin Interface" & supporting directory structure. 65/2765/3
authorJoseph Morrow <joseph.l.morrow@intel.com>
Sat, 19 Sep 2015 03:24:11 +0000 (20:24 -0700)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Sat, 19 Sep 2015 16:52:02 +0000 (16:52 +0000)
This commit will allow follow-up contributions between contributors to
this new feature to IoTivity.

Change-Id: I41b812c048e44dded31a7fefa75f1e3830fc8daf
Signed-off-by: Joseph Morrow <joseph.l.morrow@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2091
Reviewed-by: Erich Keane <erich.keane@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2765
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
Tested-by: Patrick Lankswert <patrick.lankswert@intel.com>
22 files changed:
SConstruct
extlibs/zigbee/SConscript [new file with mode: 0644]
plugins/README.txt [new file with mode: 0644]
plugins/SConscript [new file with mode: 0644]
plugins/include/internal/plugininterfaceinternal.h [new file with mode: 0644]
plugins/include/internal/plugintranslator.h [new file with mode: 0644]
plugins/include/internal/plugintranslatortypes.h [new file with mode: 0644]
plugins/include/plugininterface.h [new file with mode: 0644]
plugins/include/plugintypes.h [new file with mode: 0644]
plugins/samples/linux/IotivityandZigbee.c [new file with mode: 0644]
plugins/samples/linux/IotivityandZigbee.h [new file with mode: 0644]
plugins/samples/linux/SConscript [new file with mode: 0644]
plugins/src/SConscript [new file with mode: 0644]
plugins/src/plugininterface.c [new file with mode: 0644]
plugins/unittests/SConscript [new file with mode: 0644]
plugins/unittests/gtest_helper.h [new file with mode: 0644]
plugins/unittests/plugininterfacetest.cpp [new file with mode: 0644]
plugins/zigbee_wrapper/SConscript [new file with mode: 0644]
plugins/zigbee_wrapper/telegesis_wrapper/SConscript [new file with mode: 0644]
plugins/zigbee_wrapper/telegesis_wrapper/include/telegesis_wrapper.h [new file with mode: 0644]
plugins/zigbee_wrapper/telegesis_wrapper/src/SConscript [new file with mode: 0644]
plugins/zigbee_wrapper/telegesis_wrapper/src/telegesis_wrapper.c [new file with mode: 0644]

index 8db1ee4..0ebc436 100644 (file)
@@ -62,6 +62,9 @@ if target_os not in ['arduino','darwin','ios', 'android']:
 # Build 'service' sub-project
 SConscript(build_dir + 'service/SConscript')
 
+# Build "plugin interface" sub-project
+SConscript(build_dir + 'plugins/SConscript')
+
 # Append targets information to the help information, to see help info, execute command line:
 #     $ scon [options] -h
 env.PrintTargets()
diff --git a/extlibs/zigbee/SConscript b/extlibs/zigbee/SConscript
new file mode 100644 (file)
index 0000000..d501819
--- /dev/null
@@ -0,0 +1,23 @@
+#******************************************************************
+#
+# Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+# TODO: Need to retrieve the respective Zigbee library we're using.
+
+# Note: This is only the location for the external Zigbee library to be pulled in.
diff --git a/plugins/README.txt b/plugins/README.txt
new file mode 100644 (file)
index 0000000..78ae189
--- /dev/null
@@ -0,0 +1,15 @@
+Title of Sub-Project: "Plugin Interface" or "PI" for short.
+
+Descriptions:
+
+  include: The source code include files (*.h). Please use the
+           plugininterface.h file to access the APIs for this
+           sub-project "Plugin Interface".
+
+  samples: The consumer of IoTivity & Plugin Interface APIs.
+
+  src: The source files.
+
+  zigbee_wrapper: This contains an abstraction shim layer to encapsulate our
+                  use case for the zigbee-library (ie. the one pulled in to
+                  extlibs directory above).
diff --git a/plugins/SConscript b/plugins/SConscript
new file mode 100644 (file)
index 0000000..a4311cf
--- /dev/null
@@ -0,0 +1,21 @@
+##
+# Plugin Interface build script
+##
+
+Import('env')
+
+target_os = env.get('TARGET_OS')
+transport = env.get('TARGET_TRANSPORT')
+build_sample = env.get('BUILD_SAMPLE')
+
+env.SConscript('./src/SConscript')
+
+env.SConscript('./unittests/SConscript')
+
+if build_sample == 'ON':
+       if target_os in ['linux', 'darwin']:
+               target_path = target_os
+               if target_os == 'darwin':
+                       target_path = 'linux'
+               env.SConscript('./samples/' + target_path + '/SConscript')
+
diff --git a/plugins/include/internal/plugininterfaceinternal.h b/plugins/include/internal/plugininterfaceinternal.h
new file mode 100644 (file)
index 0000000..8882281
--- /dev/null
@@ -0,0 +1,49 @@
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * @file
+ *
+ * This file contains APIs for PIPlugin module to be implemented.
+ */
+
+#ifndef PLUGININTERFACEINTERNAL_H_
+#define PLUGININTERFACEINTERNAL_H_
+
+#include "plugintypes.h"
+#include "plugintranslatortypes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+/**
+ *
+ * Called from PIProcess. Gives cycles for Zigbee Wrapper'
+ * internal operation.
+ *
+ */
+OCStackResult ProcessZigbee(PIPlugin_Zigbee * plugin);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif /* PLUGININTERFACEINTERNAL_H_ */
diff --git a/plugins/include/internal/plugintranslator.h b/plugins/include/internal/plugintranslator.h
new file mode 100644 (file)
index 0000000..f9b2701
--- /dev/null
@@ -0,0 +1 @@
+// This file will host the translate TO "zigbee" or "zwave" functions
diff --git a/plugins/include/internal/plugintranslatortypes.h b/plugins/include/internal/plugintranslatortypes.h
new file mode 100644 (file)
index 0000000..6d37325
--- /dev/null
@@ -0,0 +1,80 @@
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//******************************************************************
+
+
+/**
+ * @file
+ *
+ * This file contains the definition, types and APIs for resource(s) be
+ * implemented.
+ */
+
+#ifndef PLUGINTRANSLATORTYPES_H_
+#define PLUGINTRANSLATORTYPES_H_
+
+#include "octypes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+// This file will hold structs which will help aid in abstraction of zigbee
+// protocol to a PIPlugin.:
+
+typedef struct
+{
+    PIPluginBase * header;
+    struct PIResource_Zigbee * resource; // All resources which exist within this context.
+    //Todo: Whatever other zigbee plugin specific stuff...
+    //Todo:  zigbee_homeautomationprofile profile;
+} PIPlugin_Zigbee;
+
+/**
+ *  Header for all PIResources.
+ */
+typedef struct
+{
+    struct PIResourceBase * next; // Linked list of resources.
+    PIPluginBase * plugin; // Context this resource exists.
+    OCResourceHandle * resourceHandle; // Handle to OIC Resource.
+} PIResourceBase;
+
+typedef struct
+{
+// Todo: This needs to map nicely to a struct that's defined in Zigbee_wrapper
+    uint8_t placeholder;
+// Todo: This struct will be refactored once Zigbee_Wrapper is finished.
+} PIZigbeeProfile;
+
+/**
+ * Parameter list for a resource. Abstraction of PIResource.
+ */
+typedef struct
+{
+    PIResourceBase * header;
+    PIPlugin_Zigbee * plugin; // Context which this Zigbee device exists.
+    PIZigbeeProfile zigbeeProfile; // Representation of a Zigbee Device.
+} PIResource_Zigbee;
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif /* PLUGINTRANSLATORTYPES_H_ */
diff --git a/plugins/include/plugininterface.h b/plugins/include/plugininterface.h
new file mode 100644 (file)
index 0000000..53bddd4
--- /dev/null
@@ -0,0 +1,72 @@
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * @file
+ *
+ * This file contains APIs for PIPlugin module to be implemented.
+ */
+
+#ifndef PLUGININTERFACE_H_
+#define PLUGININTERFACE_H_
+
+#include "plugintypes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+// Todo: The following APIs can be modified as needed. This just a loose
+// declaration to illustrate how we can manage our plugins. The types are
+// defined in plugintypes.h.
+
+/**
+ *
+ * Makes any required calls to instantiate IoTivity and/or plugin's radio.
+ *
+ * @param[in] plugin The plugin to be started.
+ *   Note: Please note that the plugin will need to be managed in the
+ *         application space.
+ */
+OCStackResult PIStartPlugin(PIPluginBase * plugin);
+
+/**
+ *
+ * Makes any required calls to stop plugin's radio.
+ *
+ * @param[in] PIStopPlugin The plugin to be stopped.
+ *           Note: If NULL Makes any required calls to stop IoTivity and ALL
+ *                 plugin radios.
+ */
+OCStackResult PIStopPlugin(PIPluginBase * plugin);
+
+/**
+ *
+ * Called in main loop of application. Gives cycles for Plugin Interface'
+ * internal operation.
+ *
+ */
+OCStackResult PIProcess(PIPluginBase * plugin);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif /* PLUGININTERFACE_H_ */
diff --git a/plugins/include/plugintypes.h b/plugins/include/plugintypes.h
new file mode 100644 (file)
index 0000000..d17f3eb
--- /dev/null
@@ -0,0 +1,62 @@
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//******************************************************************
+
+
+/**
+ * @file
+ *
+ * This file contains the definition, types and APIs for resource(s) be
+ * implemented.
+ */
+
+#ifndef PLUGINTYPES_H_
+#define PLUGINTYPES_H_
+
+#include "octypes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+/**
+ * Types of plugins.
+ */
+typedef enum
+{
+    PLUGIN_UNKNOWN = 0,
+    /** Zigbee */
+    PLUGIN_ZIGBEE = 1
+
+} PIPluginType;
+
+/**
+ * Parameter list for a plugin.
+ */
+typedef struct
+{
+    PIPluginType type;
+// Todo: Any other common properties between plugins can be placed here.
+} PIPluginBase;
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif /* PLUGINTYPES_H_ */
diff --git a/plugins/samples/linux/IotivityandZigbee.c b/plugins/samples/linux/IotivityandZigbee.c
new file mode 100644 (file)
index 0000000..f21526f
--- /dev/null
@@ -0,0 +1,13 @@
+// The source file for sample application "IotivityandZigbee".
+
+// This application will utilize our interface (ie. zpluginz.h).
+// The application may still be responsible for making any IoTivity API calls,
+// except for resource-specific IoTivity APIs (ie. OCCreateResource(),
+// OCDeleteResource(), EntityHandler()..etc.)
+
+#include "IotivityandZigbee.h"
+
+int main(int argc, char* argv[])
+{
+    return 0;
+}
diff --git a/plugins/samples/linux/IotivityandZigbee.h b/plugins/samples/linux/IotivityandZigbee.h
new file mode 100644 (file)
index 0000000..53898ac
--- /dev/null
@@ -0,0 +1,8 @@
+// The source file for sample application "IotivityandZigbee".
+
+// This application will utilize our interface (ie. zpluginz.h).
+// The application may still be responsible for making any IoTivity API calls,
+// except for resource-specific IoTivity APIs (ie. OCCreateResource(),
+// OCDeleteResource(), EntityHandler()..etc.)
+
+#include "plugininterface.h"
diff --git a/plugins/samples/linux/SConscript b/plugins/samples/linux/SConscript
new file mode 100644 (file)
index 0000000..0b1f0ae
--- /dev/null
@@ -0,0 +1,74 @@
+#******************************************************************
+#
+# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+Import('env')
+import os
+import os.path
+target_os = env.get('TARGET_OS')
+samples_env = env.Clone()
+src_dir = env.get('SRC_DIR')
+pi_dir = os.path.join(src_dir, 'plugins')
+
+######################################################################
+# Build flags
+######################################################################
+samples_env.PrependUnique(CPPPATH = [
+               '../../../../logger/include',
+               '../../../../stack/include',
+               '../../../../../../extlibs/cjson',
+                os.path.join(pi_dir, 'include')
+               ])
+
+samples_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-Wextra', '-Werror'])
+samples_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
+samples_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+
+if target_os in ['darwin', 'ios']:
+       samples_env.PrependUnique(LIBS = ['m',
+                                          'octbstack',
+                                          'ocsrm',
+                                          'connectivity_abstraction',
+                                          'coap' ])
+elif target_os not in ['arduino']:
+       samples_env.PrependUnique(LIBS = ['m',
+                                          'octbstack',
+                                          'ocsrm',
+                                          'connectivity_abstraction',
+                                          'coap',
+                                          'plugin_interface'])
+       samples_env.AppendUnique(LIBS = ['rt'])
+
+if env.get('SECURED') == '1':
+    samples_env.AppendUnique(LIBS = ['tinydtls'])
+
+samples_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+iotivityandzigbee         = samples_env.Program('iotivityandzigbee', ['IotivityandZigbee.c'])
+
+list_of_samples = [iotivityandzigbee]
+
+Alias("samples", list_of_samples)
+
+env.AppendTarget('samples')
+
+
diff --git a/plugins/src/SConscript b/plugins/src/SConscript
new file mode 100644 (file)
index 0000000..06a7b55
--- /dev/null
@@ -0,0 +1,43 @@
+##
+# Plugin Interface build script
+##
+
+import os.path
+
+Import('env')
+
+target_os = env.get('TARGET_OS')
+src_dir = env.get('SRC_DIR')
+pi_path = os.path.join(src_dir, 'plugins')
+
+#####################################################################
+# Source files and Target(s)
+######################################################################
+
+print"Reading PI script"
+
+env.PrependUnique(CPPPATH = [ os.path.join(src_dir, 'resource', 'csdk', 'stack', 'include') ])
+env.AppendUnique(CPPPATH = [ os.path.join(pi_path, 'include'),
+                             os.path.join(pi_path, 'include', 'internal') ])
+
+if target_os not in ['arduino', 'windows', 'winrt']:
+       env.AppendUnique(CPPDEFINES = ['WITH_POSIX'])
+
+if target_os in ['darwin','ios']:
+       env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
+
+pi_src = [
+       'plugininterface.c',
+       ]
+
+env.AppendUnique(PI_SRC = pi_src)
+
+print "Include path is %s" % env.get('CPPPATH')
+print "Files path is %s" % env.get('PI_SRC')
+if target_os in ['android', 'tizen']:
+       calib = env.SharedLibrary('plugin_interface', env.get('PI_SRC'))
+else:
+       calib = env.StaticLibrary('plugin_interface', env.get('PI_SRC'))
+env.InstallTarget(calib, 'libplugin_interface')
+env.UserInstallTargetLib(calib, 'libplugin_interface')
+
diff --git a/plugins/src/plugininterface.c b/plugins/src/plugininterface.c
new file mode 100644 (file)
index 0000000..58292a9
--- /dev/null
@@ -0,0 +1,71 @@
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * @file
+ *
+ * This file contains APIs for Plugin Interface module to be implemented.
+ */
+
+#include "plugininterface.h"
+#include "plugininterfaceinternal.h"
+#include "plugintranslatortypes.h"
+
+// Internal Note: This API will try to start IoTivity. If it is already
+//                started, nothing will occur. The IoTivity stack will not
+//                allow another instance to occur within the same program space
+//                and will even return a soft success when we try (ie.
+//                OC_STACK_OK).
+OCStackResult PIStartPlugin(PIPluginBase * plugin)
+{
+    return OC_STACK_NOTIMPL;
+}
+
+OCStackResult PIStopPlugin(PIPluginBase * plugin)
+{
+    return OC_STACK_NOTIMPL;
+}
+
+OCStackResult PIProcess(PIPluginBase * plugin)
+{
+    OCStackResult result = OC_STACK_OK;
+    if(!plugin)
+    {
+        return OC_STACK_INVALID_PARAM;
+    }
+    if(plugin->type == PLUGIN_ZIGBEE)
+    {
+        result = ProcessZigbee((PIPlugin_Zigbee *) plugin);
+        if(result != OC_STACK_OK)
+        {
+            return result;
+        }
+    }
+    else
+    {
+        return OC_STACK_ERROR;
+    }
+    return result;
+}
+
+OCStackResult ProcessZigbee(PIPlugin_Zigbee * plugin)
+{
+    return OC_STACK_OK;
+}
diff --git a/plugins/unittests/SConscript b/plugins/unittests/SConscript
new file mode 100644 (file)
index 0000000..bd225dd
--- /dev/null
@@ -0,0 +1,70 @@
+#******************************************************************
+#
+# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+Import('env')
+import os
+import os.path
+unittests_env = env.Clone()
+
+src_dir = unittests_env.get('SRC_DIR')
+pi_dir = os.path.join(src_dir, 'plugins')
+build_dir = env.get('BUILD_DIR')
+######################################################################
+# Build flags
+######################################################################
+unittests_env.PrependUnique(CPPPATH = [
+                os.path.join(pi_dir, 'include'),
+                '#extlibs/gtest/gtest-1.7.0/include',
+               ])
+
+unittests_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+unittests_env.PrependUnique(LIBS = ['-lpthread'])
+unittests_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+unittests_env.AppendUnique(LIBPATH = [os.path.join(src_dir, 'extlibs', 'gtest', 'gtest-1.7.0', 'lib', '.libs')])
+unittests_env.PrependUnique(LIBS = [
+               'plugin_interface',
+               'oc',
+               'octbstack',
+               'oc_logger',
+               'connectivity_abstraction',
+               'coap',
+               'gtest',
+               'gtest_main'
+               ])
+
+if env.get('LOGGING'):
+       unittests_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+piunittests = unittests_env.Program('piunittests', ['plugininterfacetest.cpp'])
+
+Alias("piunittests", [piunittests])
+
+env.AppendTarget('piunittests')
+if env.get('TEST') == '1':
+       target_os = env.get('TARGET_OS')
+       if target_os == 'linux':
+                from tools.scons.RunTest import *
+                run_test(unittests_env,
+                         'plugins_unittests.memcheck',
+                         'plugins/unittests/piunittests')
+
diff --git a/plugins/unittests/gtest_helper.h b/plugins/unittests/gtest_helper.h
new file mode 100644 (file)
index 0000000..97ce5f9
--- /dev/null
@@ -0,0 +1,151 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef IOTY_GTEST_HELPER_H
+#define IOTY_GTEST_HELPER_H
+
+#include <atomic>
+#include <chrono>
+#include <condition_variable>
+#include <future>
+#include <mutex>
+#include <thread>
+
+namespace iotivity
+{
+    namespace test
+    {
+        /**
+         * Simple implementation of a deadman's timer that can be used to
+         * terminate a test that hangs.
+         *
+         * Since there is no standard way to terminate an individual thread,
+         * the entire process will be killed once time has been exceeded.
+         *
+         * @note provisions for watchdog thread cleanup are not currently added.
+         * Testing has not yet shown any need for such complexity.
+         */
+        class DeadmanTimer
+        {
+        public:
+
+            /**
+             * Creates an instance of a timer set to kill the running process
+             * after the specified timeout.
+             *
+             * If the destructor is invoked before time is up (aka this instance
+             * goes out of scope) the timeout will not cause the program to be
+             * terminated.
+             *
+             * @param time to wait before assuming the process is hung and must be
+             * killed.
+             * Examples of values that can be passed include
+             * std::chrono::milliseconds(250), std::chrono::seconds(5),
+             * std::chrono::minutes(3).
+             */
+            DeadmanTimer(std::chrono::milliseconds timeout) :
+                m_ctx(new DeadmanCtx(timeout)),
+                m_thread()
+                {
+                    m_thread = std::thread([this](){run(m_ctx);});
+                    {
+                        std::unique_lock<std::mutex> lock(m_ctx->m_mutex);
+                        while (!m_ctx->m_isArmed)
+                        {
+                            m_ctx->m_cond.wait(lock);
+                        }
+                    }
+                    // Now that the thread is live, we can stop tracking it.
+                    m_thread.detach();
+                }
+
+            /**
+             * Destructor that also will cancel the termination of the
+             * running process.
+             */
+            ~DeadmanTimer()
+            {
+                std::unique_lock<std::mutex> lock(m_ctx->m_mutex);
+                m_ctx->m_isArmed = false;
+            }
+
+        private:
+
+            /**
+             * Shared data that main and child thread might both need to
+             * access.
+             *
+             * Avoids referencing data in class instances that have been
+             * deleted.
+             */
+            class DeadmanCtx
+            {
+            public:
+
+                DeadmanCtx(std::chrono::milliseconds timeout) :
+                    m_mutex(),
+                    m_cond(),
+                    m_isArmed(false),
+                    m_timeout(timeout)
+                    {
+                    }
+
+                std::mutex m_mutex;
+                std::condition_variable m_cond;
+                bool m_isArmed;
+                std::chrono::milliseconds m_timeout;
+            };
+
+            // Explicitly block assignment and copy ctor
+            DeadmanTimer &operator=(const DeadmanTimer &rhs);
+            DeadmanTimer(const iotivity::test::DeadmanTimer &rhs);
+
+            std::shared_ptr<DeadmanCtx> m_ctx;
+            std::thread m_thread;
+
+
+            static void run(std::shared_ptr<DeadmanCtx> ctx)
+            {
+                // Let the calling thread know it can stop waiting:
+                {
+                    std::unique_lock<std::mutex> lock(ctx->m_mutex);
+                    ctx->m_isArmed = true;
+                    ctx->m_cond.notify_all();
+                }
+
+                std::this_thread::sleep_for(ctx->m_timeout);
+
+                std::unique_lock<std::mutex> lock(ctx->m_mutex);
+                if (ctx->m_isArmed)
+                {
+                    try {
+                        throw std::runtime_error("deadman timer expired");
+                    }
+                    catch (std::exception&)
+                    {
+                        std::terminate();
+                    }
+                }
+            }
+        };
+    } // namespace test
+} // namespace iotivity
+
+#endif // IOTY_GTEST_HELPER_H
diff --git a/plugins/unittests/plugininterfacetest.cpp b/plugins/unittests/plugininterfacetest.cpp
new file mode 100644 (file)
index 0000000..57925ef
--- /dev/null
@@ -0,0 +1,85 @@
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+
+#include "plugininterface.h"
+
+#include "gtest/gtest.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+//-----------------------------------------------------------------------------
+// Includes
+//-----------------------------------------------------------------------------
+#include <stdio.h>
+#include <string.h>
+
+#include <iostream>
+#include <stdint.h>
+
+#include "gtest_helper.h"
+
+namespace itst = iotivity::test;
+
+//-----------------------------------------------------------------------------
+// Private variables
+//-----------------------------------------------------------------------------
+
+std::chrono::seconds const SHORT_TEST_TIMEOUT = std::chrono::seconds(5);
+
+//-----------------------------------------------------------------------------
+//  Tests
+//-----------------------------------------------------------------------------
+
+// Plugin Interface API PIStartPlugin()
+TEST(PITests, StartPluginTest)
+{
+    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+    EXPECT_EQ(OC_STACK_NOTIMPL, PIStartPlugin(NULL));
+}
+
+// Plugin Interface API PIStopPlugin()
+TEST(PITests, StopPluginTest)
+{
+    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+    EXPECT_EQ(OC_STACK_NOTIMPL, PIStopPlugin(NULL));
+}
+
+// Plugin Interface API PIProcess()
+TEST(PITests, ProcessTest)
+{
+    PIPluginBase zigbeePlugin;
+    zigbeePlugin.type = PLUGIN_ZIGBEE;
+
+    PIPluginBase invalidPlugin;
+    invalidPlugin.type = PLUGIN_UNKNOWN;
+
+    itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, PIProcess(NULL));
+    EXPECT_EQ(OC_STACK_OK, PIProcess(&zigbeePlugin));
+    EXPECT_EQ(OC_STACK_ERROR, PIProcess(&invalidPlugin));
+}
+
+
+
diff --git a/plugins/zigbee_wrapper/SConscript b/plugins/zigbee_wrapper/SConscript
new file mode 100644 (file)
index 0000000..1376832
--- /dev/null
@@ -0,0 +1,10 @@
+##
+# Zigbee Wrapper build script
+##
+
+Import('env')
+
+Print "Reading top Zigbee Wrapper."
+
+env.SConscript('./telegesis_wrapper/SConscript')
+
diff --git a/plugins/zigbee_wrapper/telegesis_wrapper/SConscript b/plugins/zigbee_wrapper/telegesis_wrapper/SConscript
new file mode 100644 (file)
index 0000000..0c1f12b
--- /dev/null
@@ -0,0 +1,10 @@
+##
+# Telegesis Wrapper build script
+##
+
+Import('env')
+
+Print "Reading top Telegesis Wrapper."
+
+env.SConscript('./src/SConscript')
+
diff --git a/plugins/zigbee_wrapper/telegesis_wrapper/include/telegesis_wrapper.h b/plugins/zigbee_wrapper/telegesis_wrapper/include/telegesis_wrapper.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/plugins/zigbee_wrapper/telegesis_wrapper/src/SConscript b/plugins/zigbee_wrapper/telegesis_wrapper/src/SConscript
new file mode 100644 (file)
index 0000000..282d4d9
--- /dev/null
@@ -0,0 +1,40 @@
+##
+# Plugin Interface build script
+##
+
+import os.path
+
+Import('env')
+
+target_os = env.get('TARGET_OS')
+src_dir = env.get('SRC_DIR')
+tw_path = os.path.join(src_dir, 'plugins')
+
+#####################################################################
+# Source files and Target(s)
+######################################################################
+
+print"Reading Telegesis Wrapper (TW) script"
+
+env.AppendUnique(CPPPATH = [ os.path.join(tw_path, 'include'),
+                             os.path.join(tw_path, 'include', 'internal')
+                             os.path.join(tw_path, 'zigbee_wrapper', 'telegesis_wrapper', 'include' ])
+
+if target_os not in ['arduino', 'windows', 'winrt']:
+       env.AppendUnique(CPPDEFINES = ['WITH_POSIX'])
+
+if target_os in ['darwin','ios']:
+       env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
+
+tw_src = [
+       'telegesis_wrapper.c',
+       ]
+
+env.AppendUnique(TW_SRC = tw_src)
+
+if target_os in ['android', 'tizen']:
+       calib = env.SharedLibrary('telegesis_wrapper', env.get('TW_SRC'))
+else:
+       calib = env.StaticLibrary('telegesis_wrapper', env.get('TW_SRC'))
+env.InstallTarget(calib, 'libtelegesis_wrapper')
+env.UserInstallTargetLib(calib, 'libtelegesis_wrapper')
diff --git a/plugins/zigbee_wrapper/telegesis_wrapper/src/telegesis_wrapper.c b/plugins/zigbee_wrapper/telegesis_wrapper/src/telegesis_wrapper.c
new file mode 100644 (file)
index 0000000..e69de29