Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/devfs/jspipe_node.h

Issue 242533005: [NaCl SDK] nacl_io: Add flow control the JavaScript pipes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef LIBRARIES_NACL_IO_DEVFS_JSPIPE_NODE_H_ 5 #ifndef LIBRARIES_NACL_IO_DEVFS_JSPIPE_NODE_H_
6 #define LIBRARIES_NACL_IO_DEVFS_JSPIPE_NODE_H_ 6 #define LIBRARIES_NACL_IO_DEVFS_JSPIPE_NODE_H_
7 7
8 #include "nacl_io/pipe/pipe_node.h" 8 #include <ppapi/c/pp_var.h>
9 #include <string>
9 10
10 #include <string> 11 #include "nacl_io/devfs/jspipe_event_emitter.h"
12 #include "nacl_io/stream/stream_node.h"
11 13
12 namespace nacl_io { 14 namespace nacl_io {
13 15
14 class JSPipeNode : public PipeNode { 16 class MessagingInterface;
17 class VarInterface;
18 class VarArrayInterface;
19 class VarArrayBufferInterface;
20 class VarDictionaryInterface;
21
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 }
39 *
40 * Messages coming from JavaScript must be delivered using the
41 * NACL_IOC_HANDLEMESSAGE ioctl on the file handle.
42 */
43 class JSPipeNode : public Node {
15 public: 44 public:
16 explicit JSPipeNode(Filesystem* filesystem) : PipeNode(filesystem) {} 45 explicit JSPipeNode(Filesystem* filesystem);
46
47 virtual void Destroy() { LOG_TRACE("JSPipeNode: Destroy"); };
48
49 virtual JSPipeEventEmitter* GetEventEmitter();
17 50
18 virtual Error VIoctl(int request, va_list args); 51 virtual Error VIoctl(int request, va_list args);
19 52
20 // Writes go directly to PostMessage, reads come from a pipe 53 virtual Error Read(const HandleAttr& attr,
21 // that gets populated by incoming messages 54 void* buf,
55 size_t count,
56 int* out_bytes);
22 virtual Error Write(const HandleAttr& attr, 57 virtual Error Write(const HandleAttr& attr,
23 const void* buf, 58 const void* buf,
24 size_t count, 59 size_t count,
25 int* out_bytes); 60 int* out_bytes);
26 61
27 private: 62 protected:
28 std::string name_; 63 Error SendAck();
64
65 ScopedJSPipeEventEmitter pipe_;
29 }; 66 };
30 67
31 } // namespace nacl_io 68 } // namespace nacl_io
32 69
33 #endif // LIBRARIES_NACL_IO_DEVFS_JSPIPE_NODE_H_ 70 #endif // LIBRARIES_NACL_IO_DEVFS_JSPIPE_NODE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698