1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "pluginlist.h"
26 #include "zigbee_wrapper.h"
28 #include "oic_malloc.h"
30 static PIPluginBase * pluginList = NULL;
32 OCStackResult AddPlugin (PIPluginBase * plugin)
36 return OC_STACK_INVALID_PARAM;
39 LL_APPEND(pluginList, plugin);
43 OCStackResult DeletePlugin(PIPluginBase * plugin)
45 OCStackResult result = OC_STACK_ERROR;
48 return OC_STACK_INVALID_PARAM;
50 DeleteResourceList(plugin);
51 LL_DELETE(pluginList, plugin);
52 if (plugin->type == PLUGIN_ZIGBEE)
54 result = ZigbeeStop((PIPlugin_Zigbee *) plugin);
60 OCStackResult DeletePluginList()
62 OCStackResult result = OC_STACK_OK;
63 PIPluginBase * out = NULL;
64 PIPluginBase * tmp = NULL;
65 LL_FOREACH_SAFE(pluginList, out, tmp)
67 result = DeletePlugin(out);
68 if (result != OC_STACK_OK)
73 if (result == OC_STACK_OK)
80 OCStackResult GetResourceFromHandle(PIPluginBase * plugin, PIResource ** piResource,
81 OCResourceHandle * resourceHandle)
83 if (!plugin || !resourceHandle || !piResource)
85 return OC_STACK_INVALID_PARAM;
87 PIResourceBase * out = NULL;
88 PIResourceBase * tmp = NULL;
89 LL_FOREACH_SAFE(plugin->resourceList, out, tmp)
91 if (out->piResource.resourceHandle == resourceHandle)
93 *piResource = (PIResource *) out;
97 return OC_STACK_NO_RESOURCE;
100 OCStackResult AddResourceToPlugin (PIPluginBase * plugin, PIResourceBase * resource)
102 if (!plugin || !resource)
104 return OC_STACK_INVALID_PARAM;
107 LL_APPEND(plugin->resourceList, resource);
109 return OC_STACK_NO_MEMORY;
112 OCStackResult DeleteResource(PIPluginBase * plugin, PIResourceBase * resource)
114 if (!plugin || !resource)
116 return OC_STACK_INVALID_PARAM;
119 //Todo: Free all of resource allocations.
120 PIResourceBase * resourceList = ((PIResourceBase *) plugin->resourceList);
122 LL_DELETE(resourceList, resource);
124 OICFree (resource->piResource.uri);
125 if (plugin->type == PLUGIN_ZIGBEE)
127 OICFree (((PIResource_Zigbee *)resource)->eui);
128 OICFree (((PIResource_Zigbee *)resource)->nodeId);
129 OICFree (((PIResource_Zigbee *)resource)->endpointId);
130 OICFree (((PIResource_Zigbee *)resource)->clusterId);
136 OCStackResult DeleteResourceList(PIPluginBase * plugin)
140 return OC_STACK_INVALID_PARAM;
143 OCStackResult result = OC_STACK_OK;
144 PIResourceBase * out = NULL;
145 PIResourceBase * tmp = NULL;
147 LL_FOREACH_SAFE(plugin->resourceList, out, tmp)
149 result = DeleteResource(plugin, out);
150 if (result != OC_STACK_OK)
155 if (result == OC_STACK_OK)
157 plugin->resourceList = NULL;