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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/devfs/jspipe_event_emitter.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
(Empty)
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.
4
5 #ifndef LIBRARIES_NACL_IO_DEVFS_JSPIPE_EVENT_EMITTER_H_
6 #define LIBRARIES_NACL_IO_DEVFS_JSPIPE_EVENT_EMITTER_H_
7
8 #include <poll.h>
9 #include <ppapi/c/pp_var.h>
10 #include <stdint.h>
11 #include <stdlib.h>
12
13 #include <string>
14
15 #include "nacl_io/fifo_char.h"
16 #include "nacl_io/pipe/pipe_event_emitter.h"
17
18 #include "sdk_util/auto_lock.h"
19 #include "sdk_util/macros.h"
20
21 namespace nacl_io {
22
23 class PepperInterface;
24 class MessagingInterface;
25 class VarInterface;
26 class VarArrayInterface;
27 class VarArrayBufferInterface;
28 class VarDictionaryInterface;
29
30 class JSPipeEventEmitter;
31 typedef sdk_util::ScopedRef<JSPipeEventEmitter> ScopedJSPipeEventEmitter;
32
33 class JSPipeEventEmitter : public EventEmitter {
34 public:
35 JSPipeEventEmitter(PepperInterface* ppapi, size_t size);
36 virtual void Destroy();
37
38 Error Read_Locked(char* data, size_t len, int* out_bytes);
39 Error Write_Locked(const char* data, size_t len, int* out_bytes);
40
41 size_t GetOSpace() { return post_message_buffer_size_ - BytesOutstanding(); };
42 size_t GetISpace() { return input_fifo_.WriteAvailable(); };
43 Error SetName(const char* name);
44 Error HandleJSMessage(PP_Var message);
45
46 protected:
47 size_t HandleJSWrite(const char* data, size_t len);
48 void HandleJSAck(size_t byte_count);
49 Error HandleJSWrite(PP_Var message);
50 Error HandleJSAck(PP_Var message);
51 void UpdateStatus_Locked();
52 PP_Var VarFromCStr(const char* string);
53 Error SendAckMessage(size_t byte_count);
54 size_t BytesOutstanding() { return bytes_sent_ - bytes_acked_; }
55 Error SendMessageToJS(PP_Var operation, PP_Var payload);
56 Error SendWriteMessage(const void* buf, size_t count);
57 int VarStrcmp(PP_Var a, PP_Var b);
58
59 private:
60 std::string name_;
61 FIFOChar input_fifo_;
62
63 // Number of bytes that to send via PostMessage before and ACK
64 // is required.
65 size_t post_message_buffer_size_;
66 size_t bytes_sent_;
67 size_t bytes_acked_;
68 size_t bytes_read_;
69
70 PepperInterface* ppapi_;
71 MessagingInterface* messaging_iface_;
72 VarInterface* var_iface_;
73 VarArrayInterface* array_iface_;
74 VarArrayBufferInterface* buffer_iface_;
75 VarDictionaryInterface* dict_iface_;
76
77 PP_Var pipe_name_var_;
78 PP_Var pipe_key_;
79 PP_Var operation_key_;
80 PP_Var payload_key_;
81 PP_Var write_var_;
82 PP_Var ack_var_;
83
84 DISALLOW_COPY_AND_ASSIGN(JSPipeEventEmitter);
85 };
86
87 } // namespace nacl_io
88
89 #endif // LIBRARIES_NACL_IO_DEVFS_JSPIPE_EVENT_EMITTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698