'iotcon_extension.cc',
'iotcon_extension.h',
'iotcon_instance.cc',
- 'iotcon_instance.h'
+ 'iotcon_instance.h',
+ 'iotcon_server_manager.cc',
+ 'iotcon_server_manager.h',
+ 'iotcon_utils.cc',
+ 'iotcon_utils.h',
],
'includes': [
'../common/pkg-config.gypi',
#include "iotcon/iotcon_instance.h"
-#include <iotcon.h>
-
#include "common/logger.h"
+#include "common/task-queue.h"
+#include "common/tools.h"
+
+#include "iotcon/iotcon_utils.h"
+
+using common::PlatformResult;
+using common::ErrorCode;
+using common::TypeMismatchException;
+using common::tools::ReportError;
+using common::tools::ReportSuccess;
+using common::Instance;
+using common::TaskQueue;
namespace extension {
namespace iotcon {
-IotconInstance::IotconInstance() {
+namespace {
+const std::string kCallbackId = "callbackId";
+const std::string kIsDiscoverable = "isDiscoverable";
+const std::string kIsObservable = "isObservable";
+const std::string kResourceTypes = "resourceTypes";
+const std::string kUriPath = "uriPath";
+
+#define CHECK_EXIST(args, name, out) \
+ if (!args.contains(name)) {\
+ std::string message = std::string(name) + " is required argument";\
+ common::tools::ReportError(\
+ common::PlatformResult(common::ErrorCode::TYPE_MISMATCH_ERR, message), &out);\
+ return;\
+ }
+}
+
+IotconInstance::IotconInstance() : manager_(this) {
LoggerD("Enter");
using std::placeholders::_1;
using std::placeholders::_2;
LoggerE("Could not connnect to iotcon service: %s", get_error_message(ret));
} else {
ret = iotcon_add_connection_changed_cb(ConnectionChangedCallback, nullptr);
- LoggerE("Could not add connection changed callback for iotcon service: %s",
- get_error_message(ret));
+ if (IOTCON_ERROR_NONE != ret) {
+ LoggerE("Could not add connection changed callback for iotcon service: %s",
+ get_error_message(ret));
+ }
}
}
void IotconInstance::IotconServerCreateResource(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
+ LoggerD("args: %s", args.serialize().c_str());
+ //args: {"callbackId":2,"isDiscoverable":true,
+ //"isObservable":true,"resourceTypes":["t1","t2"],"uriPath":"uriPath"}
+
+ CHECK_EXIST(args, kCallbackId, out)
+ CHECK_EXIST(args, kIsDiscoverable, out)
+ CHECK_EXIST(args, kIsObservable, out)
+ CHECK_EXIST(args, kResourceTypes, out)
+ CHECK_EXIST(args, kUriPath, out)
+
+ const double callback_id = args.get(kCallbackId).get<double>();
+ const bool is_discoverable = args.get(kIsDiscoverable).get<bool>();
+ const bool is_observable = args.get(kIsObservable).get<bool>();
+ const auto& resource_type = args.get(kResourceTypes).get<picojson::array>();
+ const std::string& uri_path = args.get(kUriPath).get<std::string>();
+
+ auto create = [this, callback_id, is_discoverable, is_observable, resource_type, uri_path]
+ (const std::shared_ptr<picojson::value>& response) -> void {
+ LoggerD("Create resource");
+ picojson::value result = picojson::value(picojson::object());
+ // TODO implement CreateResource
+ PlatformResult ret = manager_.CreateResource();
+ if (ret.IsError()) {
+ LogAndReportError(ret,&(response->get<picojson::object>()));
+ return;
+ }
+ ReportSuccess(result, response->get<picojson::object>());
+ };
+
+ auto create_response = [this, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
+ LoggerD("Response");
+ picojson::object& obj = response->get<picojson::object>();
+ obj.insert(std::make_pair("callbackId", picojson::value{static_cast<double>(callback_id)}));
+ LoggerD("message: %s", response->serialize().c_str());
+ Instance::PostMessage(this, response->serialize().c_str());
+ };
+
+ auto data = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
+ TaskQueue::GetInstance().Queue<picojson::value>(create, create_response, data);
}
void IotconInstance::IotconServerRemoveResource(const picojson::value& args,
#include "common/picojson.h"
#include "common/extension.h"
+#include "iotcon/iotcon_server_manager.h"
namespace extension {
namespace iotcon {
picojson::object& out);
void IotconSetTimeout(const picojson::value& args,
picojson::object& out);
+
+ IotconServerManager manager_;
};
} // namespace iotcon
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 "iotcon/iotcon_server_manager.h"
+
+#include "common/logger.h"
+
+#include "iotcon/iotcon_instance.h"
+
+namespace extension {
+namespace iotcon {
+
+using common::PlatformResult;
+using common::ErrorCode;
+
+IotconServerManager::IotconServerManager(IotconInstance* instance)
+ : instance_(instance) {
+ LoggerD("Entered");
+}
+
+IotconServerManager::~IotconServerManager() {
+ LoggerD("Enter");
+}
+
+PlatformResult IotconServerManager::RestoreHandles() {
+ LoggerD("Entered");
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult IotconServerManager::CreateResource() {
+ LoggerD("Entered");
+ // TODO implement
+ return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Not implemented yet");
+}
+
+} // namespace iotcon
+} // namespace extension
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 WEBAPI_PLUGINS_IOTCON_SERVER_MANAGER_H__
+#define WEBAPI_PLUGINS_IOTCON_SERVER_MANAGER_H__
+
+#include <memory>
+#include <map>
+#include <string>
+#include <iotcon.h>
+
+#include "common/picojson.h"
+#include "common/platform_result.h"
+
+namespace extension {
+namespace iotcon {
+
+struct ResourceInfo {
+ const char *uri_path;
+ iotcon_resource_types_h res_types;
+ int ifaces;
+ int properties;
+ iotcon_resource_h handle;
+ ResourceInfo() :
+ uri_path(nullptr), res_types(nullptr), ifaces(0),
+ properties(0), handle(nullptr) {}
+ ~ResourceInfo() {
+ delete uri_path;
+ iotcon_resource_types_destroy(res_types);
+ iotcon_resource_destroy (handle);
+ }
+};
+
+typedef std::shared_ptr<ResourceInfo> ResourceInfoPtr;
+typedef std::map<long long, ResourceInfoPtr> ResourceInfoMap;
+
+class IotconInstance;
+
+class IotconServerManager {
+ public:
+ IotconServerManager(IotconInstance* instance);
+ ~IotconServerManager();
+
+ common::PlatformResult RestoreHandles();
+
+ common::PlatformResult CreateResource(/*std::string uri_path, bool is_discoverable,
+ bool is_observable, picojson::array array,
+ iotcon_resource_h* res_handle*/);
+
+ private:
+ IotconInstance* instance_;
+ ResourceInfoMap resource_map_;
+};
+} // namespace iotcon
+} // namespace extension
+
+#endif // WEBAPI_PLUGINS_IOTCON_SERVER_MANAGER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 "iotcon_utils.h"
+
+#include <memory>
+
+#include "common/logger.h"
+#include "common/platform_exception.h"
+#include "common/scope_exit.h"
+
+namespace extension {
+namespace iotcon {
+
+using common::PlatformResult;
+using common::ErrorCode;
+
+PlatformResult IotconUtils::ResourceToJson(iotcon_resource_h handle, picojson::value* res) {
+ LoggerD("Entered");
+
+ // TODO implement conversion
+ return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "Not implemented yet");
+}
+
+} // namespace iotcon
+} // namespace extension
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 WEBAPI_PLUGINS_IOTCON_IOTCON_UTILS_H__
+#define WEBAPI_PLUGINS_IOTCON_IOTCON_UTILS_H__
+
+#include <string>
+
+#include <iotcon.h>
+
+#include "common/picojson.h"
+#include "common/platform_result.h"
+
+namespace extension {
+namespace iotcon {
+
+class IotconUtils {
+ public:
+ static common::PlatformResult ResourceToJson(iotcon_resource_h handle, picojson::value* res);
+};
+
+} // namespace iotcon
+} // namespace extension
+
+#endif // WEBAPI_PLUGINS_IOTCON_IOTCON_UTILS_H__