# 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()
--- /dev/null
+#******************************************************************
+#
+# 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.
--- /dev/null
+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).
--- /dev/null
+##
+# 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')
+
--- /dev/null
+//******************************************************************
+//
+// 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_ */
--- /dev/null
+// This file will host the translate TO "zigbee" or "zwave" functions
--- /dev/null
+//******************************************************************
+//
+// 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_ */
--- /dev/null
+//******************************************************************
+//
+// 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_ */
--- /dev/null
+//******************************************************************
+//
+// 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_ */
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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"
--- /dev/null
+#******************************************************************
+#
+# 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')
+
+
--- /dev/null
+##
+# 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')
+
--- /dev/null
+//******************************************************************
+//
+// 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;
+}
--- /dev/null
+#******************************************************************
+#
+# 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')
+
--- /dev/null
+//******************************************************************
+//
+// 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
--- /dev/null
+//******************************************************************
+//
+// 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));
+}
+
+
+
--- /dev/null
+##
+# Zigbee Wrapper build script
+##
+
+Import('env')
+
+Print "Reading top Zigbee Wrapper."
+
+env.SConscript('./telegesis_wrapper/SConscript')
+
--- /dev/null
+##
+# Telegesis Wrapper build script
+##
+
+Import('env')
+
+Print "Reading top Telegesis Wrapper."
+
+env.SConscript('./src/SConscript')
+
--- /dev/null
+##
+# 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')