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_EVENT_EMITTER_H_
6 #define LIBRARIES_NACL_IO_DEVFS_JSPIPE_EVENT_EMITTER_H_
9 #include <ppapi/c/pp_var.h>
15 #include "nacl_io/fifo_char.h"
16 #include "nacl_io/pipe/pipe_event_emitter.h"
18 #include "sdk_util/auto_lock.h"
19 #include "sdk_util/macros.h"
23 class PepperInterface
;
24 class MessagingInterface
;
26 class VarArrayInterface
;
27 class VarArrayBufferInterface
;
28 class VarDictionaryInterface
;
30 class JSPipeEventEmitter
;
31 typedef sdk_util::ScopedRef
<JSPipeEventEmitter
> ScopedJSPipeEventEmitter
;
33 class JSPipeEventEmitter
: public EventEmitter
{
35 JSPipeEventEmitter(PepperInterface
* ppapi
, size_t size
);
36 virtual void Destroy();
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
);
42 return post_message_buffer_size_
- BytesOutstanding();
45 return input_fifo_
.WriteAvailable();
47 Error
SetName(const char* name
);
48 Error
HandleJSMessage(PP_Var message
);
51 size_t HandleJSWrite(const char* data
, size_t len
);
52 void HandleJSAck(size_t byte_count
);
53 Error
HandleJSWrite(PP_Var message
);
54 Error
HandleJSAck(PP_Var message
);
55 void UpdateStatus_Locked();
56 PP_Var
VarFromCStr(const char* string
);
57 Error
SendAckMessage(size_t byte_count
);
58 size_t BytesOutstanding() { return bytes_sent_
- bytes_acked_
; }
59 Error
SendMessageToJS(PP_Var operation
, PP_Var payload
);
60 Error
SendWriteMessage(const void* buf
, size_t count
);
61 int VarStrcmp(PP_Var a
, PP_Var b
);
67 // Number of bytes that to send via PostMessage before and ACK
69 size_t post_message_buffer_size_
;
74 PepperInterface
* ppapi_
;
75 MessagingInterface
* messaging_iface_
;
76 VarInterface
* var_iface_
;
77 VarArrayInterface
* array_iface_
;
78 VarArrayBufferInterface
* buffer_iface_
;
79 VarDictionaryInterface
* dict_iface_
;
81 PP_Var pipe_name_var_
;
83 PP_Var operation_key_
;
88 DISALLOW_COPY_AND_ASSIGN(JSPipeEventEmitter
);
91 } // namespace nacl_io
93 #endif // LIBRARIES_NACL_IO_DEVFS_JSPIPE_EVENT_EMITTER_H_