+++ /dev/null
-CC=gcc
-CFLAGS=-fPIC -I../../src
-LDFLAGS=--shared
-
-TARGET=libecho.so
-SRCS=echo_extension.c
-
-$(TARGET): $(SRCS)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
-
-clean:
- rm -f $(TARGET)
\ No newline at end of file
+++ /dev/null
-#!/usr/bin/env node
-
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-var xwalk = require('node-xwalk');
-var echo = xwalk.require('echo');
-
-echo.echo("Hello Async!!", function(msg) {
- console.log("Async callback: " + msg);
-});
-
-var ret = echo.syncEcho("Hello Sync!!");
-console.log("Sync return: " + ret);
-
+++ /dev/null
-// Copyright (c) 2013 Intel Corporation. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#if defined(__cplusplus)
-#error "This file is written in C to make sure the C API works as intended."
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "xwalk/extensions/public/XW_Extension.h"
-#include "xwalk/extensions/public/XW_Extension_SyncMessage.h"
-
-XW_Extension g_extension = 0;
-const XW_CoreInterface* g_core = NULL;
-const XW_MessagingInterface* g_messaging = NULL;
-const XW_Internal_SyncMessagingInterface* g_sync_messaging = NULL;
-
-void instance_created(XW_Instance instance) {
- printf("Instance %d created!\n", instance);
-}
-
-void instance_destroyed(XW_Instance instance) {
- printf("Instance %d destroyed!\n", instance);
-}
-
-void handle_message(XW_Instance instance, const char* message) {
- g_messaging->PostMessage(instance, message);
-}
-
-void handle_sync_message(XW_Instance instance, const char* message) {
- g_sync_messaging->SetSyncReply(instance, message);
-}
-
-void shutdown(XW_Extension extension) {
- printf("Shutdown\n");
-}
-
-int32_t XW_Initialize(XW_Extension extension, XW_GetInterface get_interface) {
- static const char* kAPI =
- "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);"
- "};";
-
- g_extension = extension;
- g_core = get_interface(XW_CORE_INTERFACE);
- g_core->SetExtensionName(extension, "echo");
- g_core->SetJavaScriptAPI(extension, kAPI);
- g_core->RegisterInstanceCallbacks(
- extension, instance_created, instance_destroyed);
- g_core->RegisterShutdownCallback(extension, shutdown);
-
- g_messaging = get_interface(XW_MESSAGING_INTERFACE);
- g_messaging->Register(extension, handle_message);
-
- g_sync_messaging = get_interface(XW_INTERNAL_SYNC_MESSAGING_INTERFACE);
- g_sync_messaging->Register(extension, handle_sync_message);
-
- return XW_OK;
-}
+++ /dev/null
-CC=gcc
-CFLAGS=-fPIC -I../../src
-LDFLAGS=--shared
-
-TARGET=libecho2.so
-SRCS=echo_extension_messaging_2.c
-
-$(TARGET): $(SRCS)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
-
-clean:
- rm -f $(TARGET)
\ No newline at end of file
+++ /dev/null
-#!/usr/bin/env node
-
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-var xwalk = require('node-xwalk');
-var echo2 = xwalk.require('echo2');
-
-// Test async messaging
-echo2.echo("Hello Async!!", function(msg) {
- console.log(msg);
- // Test async messaging with ArrayBuffer
- var dataLength = 32;
- var buffer = new ArrayBuffer(dataLength + 4);
- var uint32View = new Uint32Array(buffer, 0, 1);
- uint32View[0] = dataLength;
- var uint8View = new Uint8Array(buffer, 4, dataLength);
- for (var i=0; i < dataLength; i++) {
- uint8View[i] = i;
- }
- echo2.echoBinary(buffer, function(msg) {
- if (!(msg instanceof ArrayBuffer))
- throw "message is not binary.";
- var retUint32View = new Uint32Array(msg, 0, 1);
- var retLength = retUint32View[0];
- if (retLength != dataLength)
- throw "message length doesn't match.";
- var retUint8View = new Uint8Array(msg, 4, retLength);
- console.log(retUint8View);
- });
-});
-
+++ /dev/null
-// Copyright (c) 2015 Intel Corporation. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#if defined(__cplusplus)
-#error "This file is written in C to make sure the C API works as intended."
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "xwalk/extensions/public/XW_Extension.h"
-#include "xwalk/extensions/public/XW_Extension_Message_2.h"
-
-XW_Extension g_extension = 0;
-const XW_CoreInterface* g_core = NULL;
-const XW_MessagingInterface2* g_messaging_2 = NULL;
-
-void instance_created(XW_Instance instance) {
- printf("Instance %d created!\n", instance);
-}
-
-void instance_destroyed(XW_Instance instance) {
- printf("Instance %d destroyed!\n", instance);
-}
-
-void handle_message(XW_Instance instance, const char* message) {
- g_messaging_2->PostMessage(instance, message);
-}
-
-void handle_binary_message(
- XW_Instance instance, const char* message, const size_t size) {
- g_messaging_2->PostBinaryMessage(instance, message, size);
-}
-
-void shutdown(XW_Extension extension) {
- printf("Shutdown\n");
-}
-
-int32_t XW_Initialize(XW_Extension extension, XW_GetInterface get_interface) {
- static const char* kAPI =
- "var echoListener = null;"
- "var echoBinaryListener = null;"
- "extension.setMessageListener(function(msg) {"
- " if (echoListener instanceof Function) {"
- " if (msg instanceof ArrayBuffer) {"
- " echoBinaryListener(msg);"
- " } else {"
- " echoListener(msg);"
- " }"
- " }"
- "});"
- "exports.echo = function(msg, callback) {"
- " echoListener = callback;"
- " extension.postMessage(msg);"
- "};"
- "exports.echoBinary = function(msg, callback) {"
- " echoBinaryListener = callback;"
- " extension.postMessage(msg);"
- "};";
-
- g_extension = extension;
- g_core = get_interface(XW_CORE_INTERFACE);
- if (g_core == NULL)
- return XW_ERROR;
- g_core->SetExtensionName(extension, "echo2");
- g_core->SetJavaScriptAPI(extension, kAPI);
- g_core->RegisterInstanceCallbacks(
- extension, instance_created, instance_destroyed);
- g_core->RegisterShutdownCallback(extension, shutdown);
-
- g_messaging_2 = get_interface(XW_MESSAGING_INTERFACE_2);
- if (g_messaging_2 == NULL)
- return XW_ERROR;
- g_messaging_2->Register(extension, handle_message);
- g_messaging_2->RegisterBinaryMesssageCallback(
- extension, handle_binary_message);
-
- return XW_OK;
-}