From d58d2599925dc4062ceaa970f190aced401ec4b0 Mon Sep 17 00:00:00 2001 From: Andrzej Popowski Date: Thu, 28 Jan 2016 11:17:15 +0100 Subject: [PATCH] [MessagePort] - improving examples Change-Id: I03aec60bd313d97914caa3ca91967337b9ccefd4 Signed-off-by: Andrzej Popowski --- .../html/device_api/mobile/tizen/messageport.html | 178 ++++++++++++++++----- 1 file changed, 142 insertions(+), 36 deletions(-) diff --git a/org.tizen.web.apireference/html/device_api/mobile/tizen/messageport.html b/org.tizen.web.apireference/html/device_api/mobile/tizen/messageport.html index 575f294..36b6aa1 100644 --- a/org.tizen.web.apireference/html/device_api/mobile/tizen/messageport.html +++ b/org.tizen.web.apireference/html/device_api/mobile/tizen/messageport.html @@ -23,22 +23,35 @@ For more information on the MessagePort features, see -
  • 1. Interfaces
    @@ -71,7 +84,11 @@ For more information on the MessagePort features, see sendMessage (MessagePortDataItem[] data, optional LocalMessagePort? localMessagePort) -MessagePortDataItem +MessagePortStringDataItem + + + +MessagePortByteStreamDataItem @@ -80,10 +97,57 @@ For more information on the MessagePort features, see +

    1. Type Definitions

    +
    +

    1.1. ByteStream

    +
    + The byte stream. +
    +
      typedef octet[] ByteStream;
    +

    + Since: + 3.0 +

    +
    +
    +

    1.2. StringDataItemValue

    +
    + The string data item value, which can either be a DOMString or a DOMString array. +
    +
      typedef (DOMString or DOMString[]) StringDataItemValue;
    +

    + Since: + 3.0 +

    +
    +
    +

    1.3. ByteStreamDataItemValue

    +
    + The byte stream data item value, which can either be a ByteStream or a ByteStream array. +
    +
      typedef (ByteStream or ByteStream[]) ByteStreamDataItemValue;
    +

    + Since: + 3.0 +

    +
    +
    +

    1.4. MessagePortDataItem

    +
    + The data item value identifier, which can either be a MessagePortStringDataItem or a MessagePortByteStreamDataItem. +
    +
      typedef (MessagePortStringDataItem or MessagePortByteStreamDataItem) MessagePortDataItem;
    +

    + Since: + 3.0 +

    +
    +
    -

    1. Interfaces

    +

    2. Interfaces

    -

    1.1. MessagePortManagerObject

    +

    2.1. MessagePortManagerObject

    The MessagePortManagerObject interface defines what is instantiated by the Tizen object from the Tizen Platform.
    @@ -102,7 +166,7 @@ The tizen.messageport object allows access to the functionality of the
    -

    1.2. MessagePortManager

    +

    2.2. MessagePortManager

    The MessagePortManager interface provides methods to request message port to communicate.
    @@ -336,7 +400,7 @@ Trusted remote message port can communicate with applications that are signed wi
    -

    1.3. LocalMessagePort

    +

    2.3. LocalMessagePort

    The LocalMessagePort interface provides methods to receive data.
    @@ -485,7 +549,7 @@ Trusted remote message port can communicate with applications that are signed wi
    -

    1.4. RemoteMessagePort

    +

    2.4. RemoteMessagePort

    The RemoteMessagePort interface provides methods to send messages.
    @@ -568,11 +632,9 @@ The sent messages will be ignored without any notice, unless the target applicat
  • localMessagePort [optional] [nullable]: - LocalMessagePort object that gives local message port of the current application -It can be used to receive reply messages from the other end of the message port. -The order of items in this array is not guaranteed to be preserved during data transfer, and values of key within this + LocalMessagePort object that gives local message port of the current application
    It can be used to receive reply messages from the other end of the message port.
    The order of items in this array is not guaranteed to be preserved during data transfer, and values of key within this array must not be duplicated or empty. -
  • +
    @@ -594,9 +656,8 @@ array must not be duplicated or empty.
    -

    Code example:

     // Sends message
    +

    Code example:

     // Sends string message
      var localMsgPort = tizen.messageport.requestLocalMessagePort('MessagePortA');
    - // Let's assume that the aplication with id '6xaeuflskd.App1' is installed
      var remoteMsgPort = tizen.messageport.requestRemoteMessagePort('6xaeuflskd.App1', 'MessagePortB');
      localMsgPort.addMessagePortListener(function(items, remoteport) {
        // ...
    @@ -604,34 +665,56 @@ array must not be duplicated or empty.
          remoteport.sendMessage([{key:'RESULT', value:'OK'}]);
        }
      });
    - remoteMsgPort.sendMessage(
    -   [
    -     { key:'CMD', value:'openWindow' },
    -     { key:'OPTION', value:'bx' }
    -   ]
    -   , localMsgPort);
    + // stream - FileStream object
    + var bytePockets = [], byteCount = 0, i = 0;
    + while(byteCount  stream.bytesAvailable - 256) {
    +   bytePockets[i] = stream.readBytes(256);
    +   byteCount+=256;
    +   i++;
    + }
    + bytePockets[i] = stream.readBytes(stream.bytesAvailable - byteCount);
    +
    + var messagePortPockets = [{key: "key1", value: "val1"},
    +                        {key: "key2", value: ["val2", "val3", "val4"]},
    +                        {key: "key3", value: bytePockets[0]},
    +                        {key: "key4", value: bytePockets}];
    + remoteMsgPort.sendMessage(messagePortPockets, localMsgPort);
      
    -
    -

    1.5. MessagePortDataItem

    +
    +

    2.5. MessagePortStringDataItem

    - The dictionary that specifies the data item that is transferred. + The dictionary that specifies the string data item that is transferred.
    -
      dictionary MessagePortDataItem {
    +
      dictionary MessagePortStringDataItem {
         DOMString key;
    -    DOMString value;
    +    StringDataItemValue value;
       };

    Since: - 2.1 + 3.0 +

    +
    +
    +

    2.6. MessagePortByteStreamDataItem

    +
    + The dictionary that specifies the byte stream data item that is transferred. +
    +
      dictionary MessagePortByteStreamDataItem {
    +    DOMString key;
    +    ByteStreamDataItemValue value;
    +  };
    +

    + Since: + 3.0

    -

    1.6. MessagePortCallback

    +

    2.7. MessagePortCallback

    The MessagePortCallback interface defines notification callbacks for receiving data from other applications.
    @@ -671,14 +754,32 @@ array must not be duplicated or empty.
    +
    +

    Code example:

     // MessagePortCallback instance
    + function onreceived(data, remoteMsgPort) {
    +   console.log('Received data to \'' + remoteMsgPort.messagePortName + '\'');
    + }
    +
    + var localMsgPort = tizen.messageport.requestLocalMessagePort('MessagePortA');
    + var watchId = localMsgPort.addMessagePortListener(onreceived);
    + 
    +
    -

    2. Full WebIDL

    +

    3. Full WebIDL

    module MessagePort {
     
    +  typedef octet[] ByteStream;
    +
    +  typedef (DOMString or DOMString[]) StringDataItemValue;
    +
    +  typedef (ByteStream or ByteStream[]) ByteStreamDataItemValue;
    +
    +  typedef (MessagePortStringDataItem or MessagePortByteStreamDataItem) MessagePortDataItem;
    +
       [NoInterfaceObject] interface MessagePortManagerObject {
         readonly attribute MessagePortManager messageport;
       };
    @@ -717,9 +818,14 @@ array must not be duplicated or empty.
         void sendMessage(MessagePortDataItem[] data, optional LocalMessagePort? localMessagePort) raises(WebAPIException);
       };
     
    -  dictionary MessagePortDataItem {
    +  dictionary MessagePortStringDataItem {
    +    DOMString key;
    +    StringDataItemValue value;
    +  };
    +
    +  dictionary MessagePortByteStreamDataItem {
         DOMString key;
    -    DOMString value;
    +    ByteStreamDataItemValue value;
       };
     
       [Callback=FunctionOnly, NoInterfaceObject] interface MessagePortCallback {
    -- 
    2.7.4