1 : /*
2 : * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 : // This file provides utilty functions for creating custom pepper events
8 : // which do not interfere with regualar pepper events.
9 :
10 : #include <sstream>
11 : #include <string>
12 : #include "native_client/src/trusted/sel_universal/primitives.h"
13 :
14 :
15 0 : bool IsInvalidEvent(const UserEvent* event) {
16 0 : return event->type == EVENT_TYPE_INVALID;
17 : }
18 :
19 :
20 0 : bool IsInputEvent(const UserEvent* event) {
21 0 : return event->type == EVENT_TYPE_INPUT;
22 : }
23 :
24 :
25 0 : bool IsTerminationEvent(const UserEvent* event) {
26 0 : return event->type == EVENT_TYPE_TERMINATION;
27 : }
28 :
29 :
30 : UserEvent* MakeUserEvent(EVENT_TYPE type,
31 : int callback,
32 : int result,
33 : void* pointer,
34 0 : int size) {
35 0 : UserEvent* event = new UserEvent;
36 0 : event->type = type;
37 0 : event->callback = callback;
38 0 : event->result = result;
39 0 : event->pointer = pointer;
40 0 : event->size = size;
41 0 : return event;
42 : }
43 :
44 :
45 0 : UserEvent* MakeInvalidEvent() {
46 0 : return MakeUserEvent(EVENT_TYPE_INVALID, 0, 0, NULL, 0);
47 : }
48 :
49 :
50 0 : UserEvent* MakeTerminationEvent() {
51 0 : return MakeUserEvent(EVENT_TYPE_TERMINATION, 0, 0, NULL, 0);
52 : }
53 :
54 :
55 0 : std::string StringifyEventType(const UserEvent* event) {
56 0 : std::stringstream s;
57 0 : switch (event->type) {
58 : default:
59 0 : s << "UNKNOWN(" << event->type << ")";
60 0 : return s.str();
61 : case EVENT_TYPE_TERMINATION:
62 0 : return "TERMINATION";
63 : case EVENT_TYPE_OPEN_CALLBACK:
64 0 : return "OPEN_CALLBACK";
65 : case EVENT_TYPE_TIMER_CALLBACK:
66 0 : return "TIMER_CALLBACK";
67 : case EVENT_TYPE_READ_CALLBACK:
68 0 : return "READ_CALLBACK";
69 : case EVENT_TYPE_FLUSH_CALLBACK:
70 0 : return "FLUSH_CALLBACK";
71 : case EVENT_TYPE_INVALID:
72 0 : return "INVALID";
73 : case EVENT_TYPE_INIT_AUDIO:
74 0 : return "INIT_AUDIO";
75 : case EVENT_TYPE_INPUT:
76 0 : return "TYPE_INPUT";
77 0 : }
78 : }
79 :
80 :
81 0 : std::string StringifyEvent(const UserEvent* event) {
82 0 : std::stringstream s;
83 : s << "type: " << StringifyEventType(event)
84 : << " cb: " << event->callback
85 : << " res: " << event->result
86 : << " p: " << reinterpret_cast<void*>(event->pointer)
87 0 : << " size: " << event->size;
88 0 : return s.str();
89 : }
|