Commit 7033427e authored by Joseph Morrow's avatar Joseph Morrow

Merge branch 'plugin-interface' into master

Change-Id: Idb58ff366694797d8bc433e974faf2c6124091aa
Signed-off-by: default avatarJoseph Morrow <joseph.l.morrow@intel.com>
parents fab88743 1d238e0f
......@@ -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()
......
#******************************************************************
#
# 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.
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).
#******************************************************************
#
# 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.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
##
# Plugin Interface build script
##
import os.path
Import('env')
target_os = env.get('TARGET_OS')
build_sample = env.get('BUILD_SAMPLE')
src_dir = env.get('SRC_DIR')
if target_os not in ['android', 'arduino', 'darwin', 'ios']:
SConscript(os.path.join('zigbee_wrapper', 'SConscript'))
SConscript(os.path.join('src', 'SConscript'))
SConscript(os.path.join('unittests', 'SConscript'))
if build_sample == 'ON':
if target_os in ['linux']:
target_path = target_os
SConscript(os.path.join('samples', target_path, 'SConscript'))
//******************************************************************
//
// 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.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/**
* @file
*
* This file contains the accessors and setters for the PluginList
*/
#ifndef PLUGINLIST_H_
#define PLUGINLIST_H_
#include "plugintranslatortypes.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
OCStackResult AddPlugin(PIPluginBase * plugin);
OCStackResult DeletePlugin(PIPluginBase * plugin);
OCStackResult DeletePluginList();
OCStackResult GetResourceFromHandle(PIPluginBase * plugin, PIResource ** piResource,
OCResourceHandle * resourceHandle);
OCStackResult AddResourceToPlugin(PIPluginBase * plugin, PIResourceBase * resource);
OCStackResult DeleteResource(PIPluginBase * plugin, PIResourceBase * resource);
OCStackResult DeleteResourceList(PIPluginBase * plugin);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif /* PLUGINLIST_H_ */
// This file will host the translate TO "zigbee" or "zwave" functions
//******************************************************************
//
// 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 all operations
* required to translate plugin's respective devices to an OCResource.
*/
#ifndef PLUGINTRANSLATORTYPES_H_
#define PLUGINTRANSLATORTYPES_H_
#include "plugintypes.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#define PI_ZIGBEE_PREFIX "/zb"
// Forward definitions to support inter-linking between structs in this file
// and the following callback.
// Note: If there are issues with either of the following two structs, please
// manually check these structs and their uses for valid operation.
struct PIPluginBase;
struct PIResourceBase;
/**
*
* This callback will be called when a new resource is created by radio wrapper.
*
*/
typedef void (* PINewResourceFound)(struct PIPluginBase * plugin,
struct PIResourceBase *newResource);
/**
*
* This function type is used by the radio's mapping implementation against IoTivity.
* The mapping implementation must implement this function to handle GET & PUT requests.
*
*/
typedef OCEntityHandlerResult (* PIProcessRequest) (struct PIPluginBase * plugin,
OCEntityHandlerRequest *ehRequest,
OCRepPayload **payload);
/**
* Parameter list for a plugin.
*/
typedef struct PIPluginBase
{
/** The type of plugin this represents. */
PIPluginType type;
/** The file location which represents the interface of the plugin. */
char * comPort;
/** Linked list of plugins. */
struct PIPluginBase * next;
/** Callback to be used when a new resource has been found. */
PINewResourceFound NewResourceFoundCB;
/** Function Pointer to be invoked upon an incoming IoTivity request. */
PIProcessRequest processEHRequest;
/** All resources which exist within the context of this plugin. */
struct PIResourceBase * resourceList;
// Any other common internal properties between plugins can be placed here.
} PIPluginBase;
/**
* The inherite plugin type to be associated with the ZigBee radio and its
* implementation.
*/
// Note: Although ZigBee has no new members for it's Plugin Type, other radio
// implementations should follow this paradigm where each radio type has
// inherited from the PIPluginBase type.
typedef struct
{
PIPluginBase header;
} PIPlugin_Zigbee;
/**
* Parameter list for a new OCResource. This will be handed up in the
* PINewResource callback.
*/
typedef struct
{
OCResourceHandle resourceHandle;
char *resourceTypeName;
char *resourceInterfaceName;
char *uri;
OCEntityHandler entityHandler;
void* callbackParam;
uint8_t resourceProperties;
} PIResource;
/**
* Header for all PIResources.
*/
typedef struct PIResourceBase
{
PIResource piResource;
struct PIResourceBase * next; // Linked list of resources.
PIPluginBase * plugin; // Context this resource exists.
} 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;
char * eui;
char * nodeId;
char * endpointId;
char * clusterId;
} PIResource_Zigbee;
#ifdef __cplusplus
}
#endif // __cplusplus
#endif /* PLUGINTRANSLATORTYPES_H_ */
//******************************************************************
//
// 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
/**
*
* Makes any required calls to instantiate plugin's radio.
*
* @param[in] comPort The com port which this plugin is located.
* @param[in] pluginType The type of plugin to start.
* @param[out] plugin The plugin handle that will be started.
*
*/
OCStackResult PIStartPlugin(const char * comPort, PIPluginType pluginType, PIPlugin ** plugin);
/**
*
* Makes any required calls to stop plugin.
*
* @param[in] plugin The plugin to be stopped.
*
*/
OCStackResult PIStopPlugin(PIPlugin * plugin);
/**
*
* Makes any required calls to stop all plugins.
*
*/
OCStackResult PIStopAll();
/**
*
* Called in main loop of application. Gives cycles for Plugin Interface'
* internal operation.
*
* @param[in] plugin The plugin to get cycles from this function's invocation.
*
*/
OCStackResult PIProcess(PIPlugin * plugin);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif /* PLUGININTERFACE_H_ */
//******************************************************************
//
// 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,
PLUGIN_ZIGBEE = 1
} PIPluginType;
/**
* Handle to a plugin.
*/
typedef struct PIPlugin {} PIPlugin;
#ifdef __cplusplus
}
#endif // __cplusplus
#endif /* PLUGINTYPES_H_ */
This diff is collapsed.
//******************************************************************
//
// 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.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// The source file for sample application "IotivityandZigbeeServer".
// 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.)
#ifndef OCZBCLIENT_H_
#define OCZBCLIENT_H_
#include "ocstack.h"
#include "plugininterface.h"
typedef enum
{
TEST_QUIT = 0,
TEST_GET = 1,
TEST_CUSTOM_PUT,
TEST_TURN_SWITCH_ON,
TEST_TURN_SWITCH_OFF,
TEST_SET_LIGHT_BRIGHTNESS,
MAX_TESTS
} CLIENT_TEST;
#endif
//******************************************************************
//
// 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.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "IotivityandZigbeeServer.h"
#include <signal.h>
#include <ocstack.h>
#include <logger.h>
#define TAG "IoTivityZigbeeServer"
#define defaultComPort "/dev/ttyUSB0"
int main()
{
OC_LOG(INFO, TAG, "Initializing IoTivity...");
OCStackResult result = OCInit(NULL, 0, OC_SERVER);
if (result != OC_STACK_OK)
{
OC_LOG_V(ERROR, TAG, "OCInit Failed %d", result);
return -1;
}
result = SetPlatformInfo();
if (result != OC_STACK_OK)
{
OC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed %d", result);
goto IotivityStop;
}
result = SetDeviceInfo();
if (result != OC_STACK_OK)
{
OC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed: %d", result);
goto IotivityStop;
}
result = OCStartPresence(0);
if (result != OC_STACK_OK)
{
OC_LOG_V(ERROR, TAG, "OCStartPresence Failed: %d", result);
goto IotivityStop;
}
// PIStartPlugin
PIPlugin* plugin = NULL;
OC_LOG(INFO, TAG, "IoTivity Initialized properly, Starting Zigbee Plugin...");
result = PIStartPlugin(defaultComPort, PLUGIN_ZIGBEE, &plugin);
if (result != OC_STACK_OK)
{
OC_LOG_V(ERROR, TAG, "Zigbee Plugin Start Failed: %d", result);
goto IotivityStop;
}
if (signal(SIGINT, processCancel) == SIG_ERR)
{
OC_LOG(ERROR, TAG, "Unable to catch SIGINT, terminating...");
}
else
{
OC_LOG(INFO, TAG, "Zigbee Plugin started correctly, press Ctrl-C to terminate application");
// Loop until sigint
while (!processSignal(false) && result == OC_STACK_OK)
{
result = OCProcess();
if (result != OC_STACK_OK)
{
OC_LOG_V(ERROR, TAG, "OCProcess Failed: %d", result);
break;
}
result = PIProcess(plugin);
if (result != OC_STACK_OK)
{
OC_LOG_V(ERROR, TAG, "PIProcess Failed: %d", result);
}
}
}
OC_LOG(INFO, TAG, "Stopping Zigbee Plugin...");
// PIStopPlugin
OC_LOG(INFO, TAG, "Zigbee Plugin Stopped");
result = PIStopPlugin(plugin);
if (result != OC_STACK_OK)
{
OC_LOG_V(ERROR, TAG, "Zigbee Plugin Stop Failed: %d", result);
}
// OCStop
IotivityStop:
OC_LOG(INFO, TAG, "Stopping IoTivity...");
result = OCStop();
if (result != OC_STACK_OK)
{
OC_LOG_V(ERROR, TAG, "OCStop Failed: %d", result);
return 0;
}
OC_LOG(INFO, TAG, "Application Completed Successfully");
return 0;
}
OCStackResult SetPlatformInfo()
{
static const OCPlatformInfo platformInfo =
{
.platformID = "IoTivityZigbeeID",
.manufacturerName = "IoTivity",
.manufacturerUrl = "http://iotivity.org",
.modelNumber = "T1000",
.dateOfManufacture = "January 14th, 2015",
.platformVersion = "0.9.2",
.operatingSystemVersion = "7",
.hardwareVersion = "0.5",
.firmwareVersion = "0",
.supportUrl = "http://iotivity.org",
.systemTime = ""
};
return OCSetPlatformInfo(platformInfo);
}
OCStackResult SetDeviceInfo()
{
static const OCDeviceInfo deviceInfo =
{
.deviceName = "IoTivity/Zigbee Server Sample"
};
return OCSetDeviceInfo(deviceInfo);
}
bool processSignal(bool set)
{
static sig_atomic_t signal = 0;
if (set)
{
signal = 1;