Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / devfs / jspipe_node.h
blobc1bd820da4c453ea4c34030b76988f1de016fbdc
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>
9 #include <string>
11 #include "nacl_io/devfs/jspipe_event_emitter.h"
12 #include "nacl_io/stream/stream_node.h"
14 namespace nacl_io {
16 class MessagingInterface;
17 class VarInterface;
18 class VarArrayInterface;
19 class VarArrayBufferInterface;
20 class VarDictionaryInterface;
22 /**
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:
27 * 'write' and 'ack'.
28 * The messages are formated as JavaScript dictionary objects and take the
29 * following form:
30 * {
31 * pipe: <pipe_name>,
32 * operation: <operation_name>,
33 * payload: <operations_payload>
34 * }
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
37 * the other end.
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 {
44 public:
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,
56 void* buf,
57 size_t count,
58 int* out_bytes);
59 virtual Error Write(const HandleAttr& attr,
60 const void* buf,
61 size_t count,
62 int* out_bytes);
64 protected:
65 Error SendAck();
67 ScopedJSPipeEventEmitter pipe_;
70 } // namespace nacl_io
72 #endif // LIBRARIES_NACL_IO_DEVFS_JSPIPE_NODE_H_