--- /dev/null
+
+# Usages tizen.echo
+
+var ret = tizen.echo.syncEcho("Hello Xwalk!");
+console.log(ret);
+
+tizen.echo.echo("Hello Xwalk! Async mode", function(msg) {
+ console.log(msg);
+});
+
--- /dev/null
+{
+ 'targets': [
+ {
+ 'target_name': 'echo',
+ 'type': 'shared_library',
+ 'sources': [
+ 'echo_api.js',
+ 'echo_extension.h',
+ 'echo_extension.cc',
+ ],
+ 'variables': {
+ 'packages': [
+ 'xwalk-extensions-common',
+ ],
+ },
+ },
+ ],
+}
--- /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 echoListener = null;
+
+extension.setMessageListener(function(msg) {
+ if (echoListener instanceof Function) {
+ echoListener(msg);
+ }
+});
+
+exports.echo = function(msg, callback) {
+ echoListener = callback;
+ extension.postMessage(msg);
+};
+
+exports.syncEcho = function(msg) {
+ return extension.internal.sendSyncMessage(msg);
+};
--- /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 "echo_extension.h"
+
+namespace sample {
+
+/**
+ * @class EchoExtension
+ */
+
+/* @method EchoExtension::CreateInstance()
+ *
+ * CreateInstance() SHOULD be implemented in inherited class
+ * to return your own ExtensionInstance class.
+ */
+xwalk::XWalkExtensionInstance* EchoExtension::CreateInstance() {
+ return new EchoInstance;
+}
+
+/**
+ * @class EchoInstance
+ */
+
+/* @method EchoInstance::HandleMessage()
+ *
+ * HandleMessage() CAN be implemented if want to handle asyncronous messages
+ * sent by 'extension.postMessage()' in echo_api.js.
+ * Asyncronous response can be sent with PostMessage() and the sent response
+ * can be handled using 'extension.setMessageListener()' in echo_api.js also.
+ */
+void EchoInstance::HandleMessage(const char* msg) {
+ PostMessage(msg);
+}
+
+/* @method EchoInstance::HandleSyncMessage()
+ *
+ * HandleSyncMessage() CAN be implemented if want to handle syncronous messages
+ * sent by 'extension.internal.sendSyncMessage()' in echo_api.js.
+ * This method should send response with SendSyncReply().
+ */
+void EchoInstance::HandleSyncMessage(const char* msg) {
+ SendSyncReply(msg);
+}
+
+} // namespace sample
+
+/* @macro EXPORT_XWALK_EXTENSION
+ *
+ * The implemented sub-class of XWalkExtension should be exported with
+ * EXPORT_XWALK_EXTENSION(name, class) macro.
+ */
+EXPORT_XWALK_EXTENSION(tizen.echo, sample::EchoExtension);
--- /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 ECHO_ECHO_EXTENSION_H_
+#define ECHO_ECHO_EXTENSION_H_
+
+#include <xwalk/xwalk_extension.h>
+
+namespace sample {
+
+class EchoExtension : public xwalk::XWalkExtension {
+ public:
+ // @override
+ xwalk::XWalkExtensionInstance* CreateInstance();
+};
+
+class EchoInstance : public xwalk::XWalkExtensionInstance {
+ public:
+ // @override
+ void HandleMessage(const char* msg);
+
+ // @override
+ void HandleSyncMessage(const char* msg);
+};
+
+} // namespace sample
+
+#endif // ECHO_ECHO_EXTENSION_H_
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+%define crosswalk_extensions tizen-extensions-crosswalk
+%define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions}
+
+Name: echo
+Summary: Echo sample for xwalk-extensions-common
+Version: 0.0.1
+Release: 1
+Group: Development/Libraries
+License: Apache-2.0 and BSD-3-Clause
+URL: https://www.tizen.org
+Source0: %{name}-%{version}.tar.gz
+Source1: %{name}.manifest
+
+BuildRequires: pkgconfig(xwalk-extensions-common)
+BuildRequires: xwalk-gyp
+
+%description
+Echo sample extension
+
+%prep
+%setup -q
+cp %{SOURCE1} .
+
+%build
+xwalk-gyp build.gyp
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+mkdir -p %{buildroot}%{crosswalk_extensions_path}
+install -p -m 644 out/Default/lib.target/*.so %{buildroot}%{crosswalk_extensions_path}
+install -p -m 644 tizen_echo.json %{buildroot}%{crosswalk_extensions_path}
+
+%clean
+rm -rf %{buildroot}
+
+%files
+%manifest %{name}.manifest
+%{crosswalk_extensions_path}/*.so
+%{crosswalk_extensions_path}/*.json
--- /dev/null
+[
+ {
+ "name":"tizen.echo",
+ "lib":"libecho.so",
+ "entry_points":[]
+ }
+]