1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef LIBRARIES_NACL_IO_DEVFS_JSPIPE_NODE_H_
6 #define LIBRARIES_NACL_IO_DEVFS_JSPIPE_NODE_H_
8 #include <ppapi/c/pp_var.h>
11 #include "nacl_io/devfs/jspipe_event_emitter.h"
12 #include "nacl_io/stream/stream_node.h"
16 class MessagingInterface
;
18 class VarArrayInterface
;
19 class VarArrayBufferInterface
;
20 class VarDictionaryInterface
;
23 * JSPipeNode represents a two-way channel for communicating with JavaScript
24 * via calls to PostMessage. In order to use these some amount of logic on
25 * the JavaScript side is also required. The protocol to the communication
26 * looks the same in both directions and consists of two message types:
28 * The messages are formated as JavaScript dictionary objects and take the
32 * operation: <operation_name>,
33 * payload: <operations_payload>
35 * The payload for 'write' message is a ArrayBuffer containing binary data.
36 * The payload for 'ack' messages is the total number of bytes recieved at
38 * For example: { pipe: 'jspipe1', operation: 'ack', payload: 234 }
40 * Messages coming from JavaScript must be delivered using the
41 * NACL_IOC_HANDLEMESSAGE ioctl on the file handle.
43 class JSPipeNode
: public Node
{
45 explicit JSPipeNode(Filesystem
* filesystem
);
47 virtual void Destroy() {
48 LOG_TRACE("JSPipeNode: Destroy");
51 virtual JSPipeEventEmitter
* GetEventEmitter();
53 virtual Error
VIoctl(int request
, va_list args
);
55 virtual Error
Read(const HandleAttr
& attr
,
59 virtual Error
Write(const HandleAttr
& attr
,
67 ScopedJSPipeEventEmitter pipe_
;
70 } // namespace nacl_io
72 #endif // LIBRARIES_NACL_IO_DEVFS_JSPIPE_NODE_H_