[MessagePort] - improving examples
authorAndrzej Popowski <a.popowski@samsung.com>
Thu, 28 Jan 2016 10:17:15 +0000 (11:17 +0100)
committerAndrzej Popowski <a.popowski@samsung.com>
Wed, 3 Feb 2016 08:03:18 +0000 (09:03 +0100)
Change-Id: I03aec60bd313d97914caa3ca91967337b9ccefd4
Signed-off-by: Andrzej Popowski <a.popowski@samsung.com>
org.tizen.web.apireference/html/device_api/mobile/tizen/messageport.html

index 575f294..36b6aa1 100644 (file)
@@ -23,22 +23,35 @@ For more information on the MessagePort features, see <a href="../../../../../or
         </p>
 <h2>Table of Contents</h2>
 <ul class="toc">
-<li>1. <a href="#interfaces-section">Interfaces</a><ul class="toc">
-<li>1.1. <a href="#MessagePortManagerObject">MessagePortManagerObject</a>
+<li>1. <a href="#typedefs-section">Type Definitions</a><ul class="toc">
+<li>1.1. <a href="#ByteStream">ByteStream</a>
 </li>
-<li>1.2. <a href="#MessagePortManager">MessagePortManager</a>
+<li>1.2. <a href="#StringDataItemValue">StringDataItemValue</a>
 </li>
-<li>1.3. <a href="#LocalMessagePort">LocalMessagePort</a>
+<li>1.3. <a href="#ByteStreamDataItemValue">ByteStreamDataItemValue</a>
 </li>
-<li>1.4. <a href="#RemoteMessagePort">RemoteMessagePort</a>
+<li>1.4. <a href="#MessagePortDataItem">MessagePortDataItem</a>
 </li>
-<li>1.5. <a href="#MessagePortDataItem">MessagePortDataItem</a>
+</ul>
+</li>
+<li>2. <a href="#interfaces-section">Interfaces</a><ul class="toc">
+<li>2.1. <a href="#MessagePortManagerObject">MessagePortManagerObject</a>
+</li>
+<li>2.2. <a href="#MessagePortManager">MessagePortManager</a>
+</li>
+<li>2.3. <a href="#LocalMessagePort">LocalMessagePort</a>
 </li>
-<li>1.6. <a href="#MessagePortCallback">MessagePortCallback</a>
+<li>2.4. <a href="#RemoteMessagePort">RemoteMessagePort</a>
+</li>
+<li>2.5. <a href="#MessagePortStringDataItem">MessagePortStringDataItem</a>
+</li>
+<li>2.6. <a href="#MessagePortByteStreamDataItem">MessagePortByteStreamDataItem</a>
+</li>
+<li>2.7. <a href="#MessagePortCallback">MessagePortCallback</a>
 </li>
 </ul>
 </li>
-<li>2. <a href="#full-webidl">Full WebIDL</a>
+<li>3. <a href="#full-webidl">Full WebIDL</a>
 </li>
 </ul>
 <hr>
@@ -71,7 +84,11 @@ For more information on the MessagePort features, see <a href="../../../../../or
 <td>void <a href="#RemoteMessagePort::sendMessage">sendMessage</a> (<a href="#MessagePortDataItem">MessagePortDataItem</a>[] data, optional <a href="#LocalMessagePort">LocalMessagePort</a>? localMessagePort)</td>
 </tr>
 <tr>
-<td><a href="#MessagePortDataItem">MessagePortDataItem</a></td>
+<td><a href="#MessagePortStringDataItem">MessagePortStringDataItem</a></td>
+<td></td>
+</tr>
+<tr>
+<td><a href="#MessagePortByteStreamDataItem">MessagePortByteStreamDataItem</a></td>
 <td></td>
 </tr>
 <tr>
@@ -80,10 +97,57 @@ For more information on the MessagePort features, see <a href="../../../../../or
 </tr>
 </tbody>
 </table>
+<div class="typedefs" id="typedefs-section">
+<h2>1. Type Definitions</h2>
+<div class="typedef" id="ByteStream">
+<a class="backward-compatibility-anchor" name="::MessagePort::ByteStream"></a><h3>1.1. ByteStream</h3>
+<div class="brief">
+ The byte stream.
+          </div>
+<pre class="webidl prettyprint">  typedef octet[] ByteStream;</pre>
+<p><span class="version">
+            Since: </span>
+ 3.0
+          </p>
+</div>
+<div class="typedef" id="StringDataItemValue">
+<a class="backward-compatibility-anchor" name="::MessagePort::StringDataItemValue"></a><h3>1.2. StringDataItemValue</h3>
+<div class="brief">
+ The string data item value, which can either be a DOMString or a DOMString array.
+          </div>
+<pre class="webidl prettyprint">  typedef (DOMString or DOMString[]) StringDataItemValue;</pre>
+<p><span class="version">
+            Since: </span>
+ 3.0
+          </p>
+</div>
+<div class="typedef" id="ByteStreamDataItemValue">
+<a class="backward-compatibility-anchor" name="::MessagePort::ByteStreamDataItemValue"></a><h3>1.3. ByteStreamDataItemValue</h3>
+<div class="brief">
+ The byte stream data item value, which can either be a ByteStream or a ByteStream array.
+          </div>
+<pre class="webidl prettyprint">  typedef (<a href="#ByteStream">ByteStream</a> or <a href="#ByteStream">ByteStream</a>[]) ByteStreamDataItemValue;</pre>
+<p><span class="version">
+            Since: </span>
+ 3.0
+          </p>
+</div>
+<div class="typedef" id="MessagePortDataItem">
+<a class="backward-compatibility-anchor" name="::MessagePort::MessagePortDataItem"></a><h3>1.4. MessagePortDataItem</h3>
+<div class="brief">
+ The data item value identifier, which can either be a MessagePortStringDataItem or a MessagePortByteStreamDataItem.
+          </div>
+<pre class="webidl prettyprint">  typedef (<a href="#MessagePortStringDataItem">MessagePortStringDataItem</a> or <a href="#MessagePortByteStreamDataItem">MessagePortByteStreamDataItem</a>) MessagePortDataItem;</pre>
+<p><span class="version">
+            Since: </span>
+ 3.0
+          </p>
+</div>
+</div>
 <div class="interfaces" id="interfaces-section">
-<h2>1. Interfaces</h2>
+<h2>2. Interfaces</h2>
 <div class="interface" id="MessagePortManagerObject">
-<a class="backward-compatibility-anchor" name="::MessagePort::MessagePortManagerObject"></a><h3>1.1. MessagePortManagerObject</h3>
+<a class="backward-compatibility-anchor" name="::MessagePort::MessagePortManagerObject"></a><h3>2.1. MessagePortManagerObject</h3>
 <div class="brief">
  The <em>MessagePortManagerObject</em> interface defines what is instantiated by the Tizen object from the Tizen Platform.
           </div>
@@ -102,7 +166,7 @@ The <em>tizen.messageport</em> object allows access to the functionality of the
          </div>
 </div>
 <div class="interface" id="MessagePortManager">
-<a class="backward-compatibility-anchor" name="::MessagePort::MessagePortManager"></a><h3>1.2. MessagePortManager</h3>
+<a class="backward-compatibility-anchor" name="::MessagePort::MessagePortManager"></a><h3>2.2. MessagePortManager</h3>
 <div class="brief">
  The <em>MessagePortManager</em> interface provides methods to request message port to communicate.
           </div>
@@ -336,7 +400,7 @@ Trusted remote message port can communicate with applications that are signed wi
 </div>
 </div>
 <div class="interface" id="LocalMessagePort">
-<a class="backward-compatibility-anchor" name="::MessagePort::LocalMessagePort"></a><h3>1.3. LocalMessagePort</h3>
+<a class="backward-compatibility-anchor" name="::MessagePort::LocalMessagePort"></a><h3>2.3. LocalMessagePort</h3>
 <div class="brief">
  The <em>LocalMessagePort</em> interface provides methods to receive data.
           </div>
@@ -485,7 +549,7 @@ Trusted remote message port can communicate with applications that are signed wi
 </div>
 </div>
 <div class="interface" id="RemoteMessagePort">
-<a class="backward-compatibility-anchor" name="::MessagePort::RemoteMessagePort"></a><h3>1.4. RemoteMessagePort</h3>
+<a class="backward-compatibility-anchor" name="::MessagePort::RemoteMessagePort"></a><h3>2.4. RemoteMessagePort</h3>
 <div class="brief">
  The <em>RemoteMessagePort</em> interface provides methods to send messages.
           </div>
@@ -568,11 +632,9 @@ The sent messages will be ignored without any notice, unless the target applicat
                 </li>
           <li class="param">
 <span class="name">localMessagePort</span><span class="optional"> [optional]</span><span class="optional"> [nullable]</span>: 
- <em>LocalMessagePort<em> 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 <em>key</em> within this
+ <em>LocalMessagePort</em> object that gives local message port of the current application<br>It can be used to receive reply messages from the other end of the message port.<br>The order of items in this array is not guaranteed to be preserved during data transfer, and values of <em>key</em> within this
 array must not be duplicated or empty.
-</em></em>                </li>
+                </li>
         </ul>
 </div>
 <div class="exceptionlist">
@@ -594,9 +656,8 @@ array must not be duplicated or empty.
 </li></ul>
         </div>
 <div class="example">
-<span class="example"><p>Code example:</p></span><pre name="code" class="examplecode prettyprint"> // Sends message
+<span class="example"><p>Code example:</p></span><pre name="code" class="examplecode prettyprint"> // 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);
  </pre>
 </div>
 </dd>
 </dl>
 </div>
 </div>
-<div class="dictionary" id="MessagePortDataItem">
-<a class="backward-compatibility-anchor" name="::MessagePort::MessagePortDataItem"></a><h3>1.5. MessagePortDataItem</h3>
+<div class="dictionary" id="MessagePortStringDataItem">
+<a class="backward-compatibility-anchor" name="::MessagePort::MessagePortStringDataItem"></a><h3>2.5. MessagePortStringDataItem</h3>
 <div class="brief">
- The dictionary that specifies the data item that is transferred.
+ The dictionary that specifies the string data item that is transferred.
           </div>
-<pre class="webidl prettyprint">  dictionary MessagePortDataItem {
+<pre class="webidl prettyprint">  dictionary MessagePortStringDataItem {
     DOMString key;
-    DOMString value;
+    <a href="#StringDataItemValue">StringDataItemValue</a> value;
   };</pre>
 <p><span class="version">
             Since: </span>
- 2.1
+ 3.0
+          </p>
+</div>
+<div class="dictionary" id="MessagePortByteStreamDataItem">
+<a class="backward-compatibility-anchor" name="::MessagePort::MessagePortByteStreamDataItem"></a><h3>2.6. MessagePortByteStreamDataItem</h3>
+<div class="brief">
+ The dictionary that specifies the byte stream data item that is transferred.
+          </div>
+<pre class="webidl prettyprint">  dictionary MessagePortByteStreamDataItem {
+    DOMString key;
+    <a href="#ByteStreamDataItemValue">ByteStreamDataItemValue</a> value;
+  };</pre>
+<p><span class="version">
+            Since: </span>
+ 3.0
           </p>
 </div>
 <div class="interface" id="MessagePortCallback">
-<a class="backward-compatibility-anchor" name="::MessagePort::MessagePortCallback"></a><h3>1.6. MessagePortCallback</h3>
+<a class="backward-compatibility-anchor" name="::MessagePort::MessagePortCallback"></a><h3>2.7. MessagePortCallback</h3>
 <div class="brief">
  The MessagePortCallback interface defines notification callbacks for receiving data from other applications.
           </div>
@@ -671,14 +754,32 @@ array must not be duplicated or empty.
                 </li>
         </ul>
 </div>
+<div class="example">
+<span class="example"><p>Code example:</p></span><pre name="code" class="examplecode prettyprint"> // MessagePortCallback instance
+ function onreceived(data, remoteMsgPort) {
+   console.log('Received data to \'' + remoteMsgPort.messagePortName + '\'');
+ }
+
+ var localMsgPort = tizen.messageport.requestLocalMessagePort('MessagePortA');
+ var watchId = localMsgPort.addMessagePortListener(onreceived);
+ </pre>
+</div>
 </dd>
 </dl>
 </div>
 </div>
 </div>
-<h2 id="full-webidl">2. Full WebIDL</h2>
+<h2 id="full-webidl">3. Full WebIDL</h2>
 <pre class="webidl prettyprint">module MessagePort {
 
+  typedef octet[] ByteStream;
+
+  typedef (DOMString or DOMString[]) StringDataItemValue;
+
+  typedef (<a href="#ByteStream">ByteStream</a> or <a href="#ByteStream">ByteStream</a>[]) ByteStreamDataItemValue;
+
+  typedef (<a href="#MessagePortStringDataItem">MessagePortStringDataItem</a> or <a href="#MessagePortByteStreamDataItem">MessagePortByteStreamDataItem</a>) MessagePortDataItem;
+
   [NoInterfaceObject] interface MessagePortManagerObject {
     readonly attribute <a href="#MessagePortManager">MessagePortManager</a> messageport;
   };
@@ -717,9 +818,14 @@ array must not be duplicated or empty.
     void sendMessage(<a href="#MessagePortDataItem">MessagePortDataItem</a>[] data, optional <a href="#LocalMessagePort">LocalMessagePort</a>? localMessagePort) raises(<a href="tizen.html#WebAPIException">WebAPIException</a>);
   };
 
-  dictionary MessagePortDataItem {
+  dictionary MessagePortStringDataItem {
+    DOMString key;
+    <a href="#StringDataItemValue">StringDataItemValue</a> value;
+  };
+
+  dictionary MessagePortByteStreamDataItem {
     DOMString key;
-    DOMString value;
+    <a href="#ByteStreamDataItemValue">ByteStreamDataItemValue</a> value;
   };
 
   [Callback=FunctionOnly, NoInterfaceObject] interface MessagePortCallback {