--- /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.
+ */
+
+
+var utils_ = xwalk.utils;
+var type_ = utils_.type;
+var converter_ = utils_.converter;
+var validator_ = utils_.validator;
+var types_ = validator_.Types;
+var native_ = new xwalk.utils.NativeManager(extension);
+
+function ListenerManager(native, listenerName, handle) {
+ this.listeners = {};
+ this.nextId = 1;
+ this.nativeSet = false;
+ this.native = native;
+ this.listenerName = listenerName;
+ this.handle = handle || function(msg, listener, watchId) {};
+}
+
+ListenerManager.prototype.addListener = function(callback, nativeCall, data) {
+ var id = this.nextId;
+ if (!this.nativeSet) {
+ this.native.addListener(this.listenerName, function(msg) {
+ for (var watchId in this.listeners) {
+ if (this.listeners.hasOwnProperty(watchId)) {
+ this.handle(msg, this.listeners[watchId], watchId);
+ }
+ }
+ }.bind(this));
+ var result = this.native.callSync(nativeCall, data || {});
+ if (this.native.isFailure(result)) {
+ throw this.native.getErrorObject(result);
+ }
+ this.nativeSet = true;
+ }
+
+ this.listeners[id] = callback;
+ ++this.nextId;
+
+ return id;
+};
+
+ListenerManager.prototype.removeListener = function(watchId, nativeCall) {
+ if (this.listeners.hasOwnProperty(watchId)) {
+ delete this.listeners[watchId];
+ }
+
+ if (this.nativeSet && type_.isEmptyObject(this.listeners)) {
+ this.native.callSync(nativeCall);
+ this.native.removeListener(this.listenerName);
+ this.nativeSet = false;
+ }
+};
+
+
+function SetReadOnlyProperty(obj, n, v) {
+ Object.defineProperty(obj, n, {value: v, writable: false});
+}
+
+var TeecLoginMethod = {
+ PUBLIC: 'PUBLIC',
+ USER: 'USER',
+ GROUP: 'GROUP',
+ APPLICATION: 'APPLICATION'
+};
+var TeecValueType = {
+ INPUT: 'INPUT',
+ OUTPUT: 'OUTPUT',
+ INOUT: 'INOUT'
+};
+var TeecTempMemoryType = {
+ INPUT: 'INPUT',
+ OUTPUT: 'OUTPUT',
+ INOUT: 'INOUT'
+};
+var TeecRegisteredMemoryType = {
+ WHOLE: 'WHOLE',
+ PARTIAL_INPUT: 'PARTIAL_INPUT',
+ PARTIAL_OUTPUT: 'PARTIAL_OUTPUT',
+ PARTIAL_INOUT: 'PARTIAL_INOUT'
+};
+var TeecSharedMemoryFlags = {
+ INPUT: 'INPUT',
+ OUTPUT: 'OUTPUT',
+ INOUT: 'INOUT'
+};
+
+
+function LibTeecManager() {
+ // constructor of LibTeecManager
+
+}
+
+
+LibTeecManager.prototype.getContext = function(name) {
+ var args = validator_.validateArgs(arguments, [
+ {name: 'name', type: types_.STRING, optional: true, nullable: true}
+ ]);
+
+ var data = {
+ name: args.name
+ };
+
+
+ var result = native_.callSync('LibTeecManager_getContext', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ return new TeecContext(native_.getResultObject(result));
+
+};
+
+
+
+function TeecContext() {
+ // constructor of TeecContext
+
+}
+
+
+TeecContext.prototype.openSession = function(taUUID, loginMethod, connectionData, params, successCallback, errorCallback) {
+ var args = validator_.validateArgs(arguments, [
+ {name: 'taUUID', type: types_.STRING},
+ {name: 'loginMethod', type: types_.ENUM, values: ['PUBLIC', 'USER', 'GROUP', 'APPLICATION']},
+ {name: 'connectionData', type: types_.BYTE},
+ {name: 'params', type: types_.PLATFORM_OBJECT, values: tizen.TeecParameter},
+ {name: 'successCallback', type: types_.FUNCTION},
+ {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
+ ]);
+
+ var data = {
+ taUUID: args.taUUID,
+ loginMethod: args.loginMethod,
+ connectionData: args.connectionData,
+ params: args.params
+ };
+
+
+
+
+
+
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
+ }
+ native_.callIfPossible(args.successCallback);
+ };
+
+ native_.call('TeecContext_openSession', data, callback);
+
+
+
+};
+
+TeecContext.prototype.revokeCommand = function(id) {
+ var args = validator_.validateArgs(arguments, [
+ {name: 'id', type: types_.LONG}
+ ]);
+
+ var data = {
+ id: args.id
+ };
+
+
+ var result = native_.callSync('TeecContext_revokeCommand', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+};
+
+TeecContext.prototype.allocateSharedMemory = function(size, flags) {
+ var args = validator_.validateArgs(arguments, [
+ {name: 'size', type: types_.LONG},
+ {name: 'flags', type: types_.ENUM, values: ['INPUT', 'OUTPUT', 'INOUT']}
+ ]);
+
+ var data = {
+ size: args.size,
+ flags: args.flags
+ };
+
+
+ var result = native_.callSync('TeecContext_allocateSharedMemory', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ return new TeecSharedMemory(native_.getResultObject(result));
+
+};
+
+TeecContext.prototype.registerSharedMemory = function(addr, size, flags) {
+ var args = validator_.validateArgs(arguments, [
+ {name: 'addr', type: types_.LONG_LONG},
+ {name: 'size', type: types_.LONG},
+ {name: 'flags', type: types_.ENUM, values: ['INPUT', 'OUTPUT', 'INOUT']}
+ ]);
+
+ var data = {
+ addr: args.addr,
+ size: args.size,
+ flags: args.flags
+ };
+
+
+ var result = native_.callSync('TeecContext_registerSharedMemory', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ return new TeecSharedMemory(native_.getResultObject(result));
+
+};
+
+TeecContext.prototype.releaseSharedMemory = function(shm) {
+ var args = validator_.validateArgs(arguments, [
+ {name: 'shm', type: types_.PLATFORM_OBJECT, values: tizen.TeecSharedMemory}
+ ]);
+
+ var data = {
+ shm: args.shm
+ };
+
+
+ var result = native_.callSync('TeecContext_releaseSharedMemory', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+};
+
+
+
+function TeecSharedMemory() {
+ // constructor of TeecSharedMemory
+
+ SetReadOnlyProperty(this, 'size', null); // read only property
+}
+
+
+TeecSharedMemory.prototype.setData = function(data, offset) {
+ var args = validator_.validateArgs(arguments, [
+ {name: 'data', type: types_.BYTE},
+ {name: 'offset', type: types_.LONG_LONG}
+ ]);
+
+ var data = {
+ data: args.data,
+ offset: args.offset
+ };
+
+
+ var result = native_.callSync('TeecSharedMemory_setData', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+};
+
+TeecSharedMemory.prototype.getData = function(data, offset) {
+ var args = validator_.validateArgs(arguments, [
+ {name: 'data', type: types_.BYTE},
+ {name: 'offset', type: types_.LONG_LONG}
+ ]);
+
+ var data = {
+ data: args.data,
+ offset: args.offset
+ };
+
+
+ var result = native_.callSync('TeecSharedMemory_getData', data);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+};
+
+
+
+function TeecRegisteredMemory(memory, offset, size) {
+ // constructor of TeecRegisteredMemory
+ validator_.isConstructorCall(this, TeecRegisteredMemory);
+
+ this.shm = null;
+ this.offset = offset;
+ this.size = memory.size;
+}
+
+TeecRegisteredMemory.prototype = new TeecParameter();
+TeecRegisteredMemory.prototype.constructor = TeecRegisteredMemory;
+
+
+
+function TeecTempMemory(mem) {
+ // constructor of TeecTempMemory
+ validator_.isConstructorCall(this, TeecTempMemory);
+
+ this.mem = mem;
+}
+
+TeecTempMemory.prototype = new TeecParameter();
+TeecTempMemory.prototype.constructor = TeecTempMemory;
+
+
+
+function TeecValue(a, b) {
+ // constructor of TeecValue
+ validator_.isConstructorCall(this, TeecValue);
+
+ this.a = a;
+ this.b = b;
+}
+
+TeecValue.prototype = new TeecParameter();
+TeecValue.prototype.constructor = TeecValue;
+
+
+
+exports = new LibTeecManager();
+tizen.TeecContext = TeecContext;
+tizen.TeecSharedMemory = TeecSharedMemory;
+tizen.TeecRegisteredMemory = TeecRegisteredMemory;
+tizen.TeecTempMemory = TeecTempMemory;
+tizen.TeecValue = TeecValue;
+
--- /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 "teec/libteec_extension.h"
+
+#include "teec/libteec_instance.h"
+
+// This will be generated from libteec_api.js
+extern const char kSource_libteec_api[];
+
+common::Extension* CreateExtension() {
+ return new LibteecExtension;
+}
+
+LibteecExtension::LibteecExtension() {
+ SetExtensionName("tizen.libteec");
+ SetJavaScriptAPI(kSource_libteec_api);
+
+ const char* entry_points[] = {
+ "tizen.LibTeecManager",
+ "tizen.TeecContext",
+ "tizen.TeecSharedMemory",
+ "tizen.TeecRegisteredMemory",
+ "tizen.TeecTempMemory",
+ "tizen.TeecValue",
+ NULL
+ };
+ SetExtraJSEntryPoints(entry_points);
+}
+
+LibteecExtension::~LibteecExtension() {}
+
+common::Instance* LibteecExtension::CreateInstance() {
+ return new extension::libteec::LibteecInstance;
+}
\ No newline at end of file
--- /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 LIBTEEC_LIBTEEC_EXTENSION_H_
+#define LIBTEEC_LIBTEEC_EXTENSION_H_
+
+#include "common/extension.h"
+
+class LibteecExtension : public common::Extension {
+public:
+ LibteecExtension();
+ virtual ~LibteecExtension();
+
+private:
+ virtual common::Instance* CreateInstance();
+};
+
+#endif // LIBTEEC_LIBTEEC_EXTENSION_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 "teec/libteec_instance.h"
+
+#include <functional>
+
+#include "common/picojson.h"
+#include "common/logger.h"
+#include "common/platform_exception.h"
+
+namespace extension {
+namespace libteec {
+
+namespace {
+// The privileges that required in Libteec API
+const std::string kPrivilegeLibteec = "";
+
+} // namespace
+
+using namespace common;
+using namespace extension::libteec;
+
+LibteecInstance::LibteecInstance() {
+ using namespace std::placeholders;
+ #define REGISTER_SYNC(c,x) \
+ RegisterSyncHandler(c, std::bind(&LibteecInstance::x, this, _1, _2));
+ REGISTER_SYNC("LibTeecManager_getContext", LibTeecManagerGetContext);
+ REGISTER_SYNC("TeecSharedMemory_setData", TeecSharedMemorySetData);
+ REGISTER_SYNC("TeecContext_releaseSharedMemory", TeecContextReleaseSharedMemory);
+ REGISTER_SYNC("TeecContext_openSession", TeecContextOpenSession);
+ REGISTER_SYNC("TeecContext_registerSharedMemory", TeecContextRegisterSharedMemory);
+ REGISTER_SYNC("TeecContext_allocateSharedMemory", TeecContextAllocateSharedMemory);
+ REGISTER_SYNC("TeecSharedMemory_getData", TeecSharedMemoryGetData);
+ REGISTER_SYNC("TeecContext_revokeCommand", TeecContextRevokeCommand);
+ #undef REGISTER_SYNC
+}
+
+LibteecInstance::~LibteecInstance() {
+}
+
+
+enum LibteecCallbacks {
+ LibTeecManagerGetContextCallback,
+ TeecSharedMemorySetDataCallback,
+ TeecContextReleaseSharedMemoryCallback,
+ TeecContextOpenSessionCallback,
+ TeecContextRegisterSharedMemoryCallback,
+ TeecContextAllocateSharedMemoryCallback,
+ TeecSharedMemoryGetDataCallback,
+ TeecContextRevokeCommandCallback
+};
+
+static void ReplyAsync(LibteecInstance* instance, LibteecCallbacks cbfunc,
+ int callbackId, bool isSuccess, picojson::object& param) {
+ param["callbackId"] = picojson::value(static_cast<double>(callbackId));
+ param["status"] = picojson::value(isSuccess ? "success" : "error");
+
+ // insert result for async callback to param
+ switch(cbfunc) {
+ case LibTeecManagerGetContextCallback: {
+ // do something...
+ break;
+ }
+ case TeecContextOpenSessionCallback: {
+ // do something...
+ break;
+ }
+ case TeecContextRevokeCommandCallback: {
+ // do something...
+ break;
+ }
+ case TeecContextAllocateSharedMemoryCallback: {
+ // do something...
+ break;
+ }
+ case TeecContextRegisterSharedMemoryCallback: {
+ // do something...
+ break;
+ }
+ case TeecContextReleaseSharedMemoryCallback: {
+ // do something...
+ break;
+ }
+ case TeecSharedMemorySetDataCallback: {
+ // do something...
+ break;
+ }
+ case TeecSharedMemoryGetDataCallback: {
+ // do something...
+ break;
+ }
+ default: {
+ LoggerE("Invalid Callback Type");
+ return;
+ }
+ }
+
+ picojson::value result = picojson::value(param);
+
+ instance->PostMessage(result.serialize().c_str());
+}
+
+#define CHECK_EXIST(args, name, out) \
+ if (!args.contains(name)) {\
+ ReportError(TypeMismatchException(name" is required argument"), out);\
+ return;\
+ }
+
+
+void LibteecInstance::LibTeecManagerGetContext(const picojson::value& args, picojson::object& out) {
+
+ const std::string& name = args.get("name").get<std::string>();
+
+ // implement it
+
+
+ // if success
+ // ReportSuccess(out);
+ // if error
+ // ReportError(out);
+}
+void LibteecInstance::TeecContextOpenSession(const picojson::value& args, picojson::object& out) {
+ CHECK_EXIST(args, "callbackId", out)
+ CHECK_EXIST(args, "connectionData", out)
+
+ int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+ int connectionData = args.get("connectionData").get<int>();
+
+ // implement it
+
+ // call ReplyAsync in later (Asynchronously)
+
+ // if success
+ // ReportSuccess(out);
+ // if error
+ // ReportError(out);
+}
+void LibteecInstance::TeecContextRevokeCommand(const picojson::value& args, picojson::object& out) {
+
+
+ // implement it
+
+
+ // if success
+ // ReportSuccess(out);
+ // if error
+ // ReportError(out);
+}
+void LibteecInstance::TeecContextAllocateSharedMemory(const picojson::value& args, picojson::object& out) {
+ CHECK_EXIST(args, "size", out)
+
+ double size = args.get("size").get<double>();
+
+ // implement it
+
+
+ // if success
+ // ReportSuccess(out);
+ // if error
+ // ReportError(out);
+}
+void LibteecInstance::TeecContextRegisterSharedMemory(const picojson::value& args, picojson::object& out) {
+ CHECK_EXIST(args, "addr", out)
+ CHECK_EXIST(args, "size", out)
+
+ double addr = args.get("addr").get<double>();
+ double size = args.get("size").get<double>();
+
+ // implement it
+
+
+ // if success
+ // ReportSuccess(out);
+ // if error
+ // ReportError(out);
+}
+void LibteecInstance::TeecContextReleaseSharedMemory(const picojson::value& args, picojson::object& out) {
+
+
+ // implement it
+
+
+ // if success
+ // ReportSuccess(out);
+ // if error
+ // ReportError(out);
+}
+void LibteecInstance::TeecSharedMemorySetData(const picojson::value& args, picojson::object& out) {
+ CHECK_EXIST(args, "data", out)
+ CHECK_EXIST(args, "offset", out)
+
+ int data = args.get("data").get<int>();
+ double offset = args.get("offset").get<double>();
+
+ // implement it
+
+
+ // if success
+ // ReportSuccess(out);
+ // if error
+ // ReportError(out);
+}
+void LibteecInstance::TeecSharedMemoryGetData(const picojson::value& args, picojson::object& out) {
+ CHECK_EXIST(args, "data", out)
+ CHECK_EXIST(args, "offset", out)
+
+ int data = args.get("data").get<int>();
+ double offset = args.get("offset").get<double>();
+
+ // implement it
+
+
+ // if success
+ // ReportSuccess(out);
+ // if error
+ // ReportError(out);
+}
+
+
+#undef CHECK_EXIST
+
+} // namespace libteec
+} // namespace extension
\ No newline at end of file
--- /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 LIBTEEC_LIBTEEC_INSTANCE_H_
+#define LIBTEEC_LIBTEEC_INSTANCE_H_
+
+#include "common/extension.h"
+
+namespace extension {
+namespace libteec {
+
+class LibteecInstance : public common::ParsedInstance {
+public:
+ LibteecInstance();
+ virtual ~LibteecInstance();
+
+private:
+ void LibTeecManagerGetContext(const picojson::value& args, picojson::object& out);
+ void TeecSharedMemorySetData(const picojson::value& args, picojson::object& out);
+ void TeecContextReleaseSharedMemory(const picojson::value& args, picojson::object& out);
+ void TeecContextOpenSession(const picojson::value& args, picojson::object& out);
+ void TeecContextRegisterSharedMemory(const picojson::value& args, picojson::object& out);
+ void TeecContextAllocateSharedMemory(const picojson::value& args, picojson::object& out);
+ void TeecSharedMemoryGetData(const picojson::value& args, picojson::object& out);
+ void TeecContextRevokeCommand(const picojson::value& args, picojson::object& out);
+};
+
+} // namespace libteec
+} // namespace extension
+
+#endif // LIBTEEC_LIBTEEC_INSTANCE_H_
\ No newline at end of file