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 : // initialize post-message sub-system for use with sel_universal
8 : // for now we just print the post-message content on the screen for debugging
9 :
10 :
11 : #include <string>
12 : #include <iostream>
13 :
14 : #include "ppapi/c/pp_input_event.h"
15 :
16 : #include "native_client/src/shared/platform/nacl_check.h"
17 : #include "native_client/src/shared/platform/nacl_log.h"
18 : #include "native_client/src/shared/srpc/nacl_srpc.h"
19 : #include "native_client/src/trusted/sel_universal/pepper_emu.h"
20 : #include "native_client/src/trusted/sel_universal/pepper_emu_helper.h"
21 : #include "native_client/src/trusted/sel_universal/primitives.h"
22 : #include "native_client/src/trusted/sel_universal/rpc_universal.h"
23 : #include "native_client/src/trusted/sel_universal/srpc_helper.h"
24 :
25 : namespace {
26 :
27 : IMultimedia* GlobalMultiMediaInterface = 0;
28 22 : std::string GlobalQuitMessage;
29 :
30 : // PPB_Messaging_PostMessage:iC:
31 0 : void PPB_Messaging_PostMessage(SRPC_PARAMS) {
32 : UNREFERENCED_PARAMETER(outs);
33 : // NOTE: only string supported for now
34 0 : std::string message = GetMarshalledJSString(ins[1]);
35 0 : std::cout << "POST_MESSAGE: [" << message << "]\n";
36 0 : rpc->result = NACL_SRPC_RESULT_OK;
37 0 : done->Run(done);
38 :
39 : // automatic termination mechanism used for testing
40 0 : if (GlobalQuitMessage.size() > 0 && GlobalQuitMessage == message) {
41 0 : NaClLog(LOG_INFO, "'quit message' triggered termination\n");
42 0 : UserEvent* event = MakeTerminationEvent();
43 0 : GlobalMultiMediaInterface->PushUserEvent(event);
44 0 : }
45 0 : }
46 :
47 : } // end namespace
48 :
49 : #define TUPLE(a, b) #a #b, a
50 0 : void PepperEmuInitPostMessage(NaClCommandLoop* ncl, IMultimedia* im) {
51 0 : GlobalMultiMediaInterface = im;
52 0 : NaClLog(LOG_INFO, "HandlerPostMessageInitialize\n");
53 :
54 0 : ncl->AddUpcallRpc(TUPLE(PPB_Messaging_PostMessage, :iC:));
55 0 : }
56 :
57 :
58 : bool HandlerPepperEmuSetQuitMessage(NaClCommandLoop* ncl,
59 0 : const std::vector<std::string>& args) {
60 : UNREFERENCED_PARAMETER(ncl);
61 0 : if (args.size() < 2) {
62 0 : NaClLog(LOG_ERROR, "Insufficient arguments to 'rpc' command.\n");
63 0 : return false;
64 : }
65 : // drop quotes - no escaping yet
66 0 : GlobalQuitMessage = args[1].substr(1, args[1].size() - 2);
67 : NaClLog(LOG_INFO, "Setting 'quit message' to [%s]\n",
68 0 : GlobalQuitMessage.c_str());
69 :
70 :
71 0 : return true;
72 22 : }
|