• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include "vm_operations.h"
18 #include "multi_display_agent.h"
19 #include "window_agent.h"
20 #include "record_screen_agent.h"
21 
22 typedef int (*LineConsumerCallback)(void* opaque, const char* buff, int len);
23 
24 #define ANDROID_CONSOLE_AGENTS_LIST(X)          \
25     X(QAndroidEmulatorWindowAgent, emu)         \
26     X(QAndroidDisplayAgent, display)         \
27     X(QAndroidRecordScreenAgent, record)        \
28     X(QAndroidMultiDisplayAgent, multi_display) \
29     X(QAndroidVmOperations, vm)                 \
30 
31 namespace android {
32 namespace emulation {
33 #define ANDROID_DEFINE_CONSOLE_GETTER(typ, name) \
34     virtual const typ* const android_get_##typ() const;
35 
36 // The default android console factory will not do anything, it will
37 // leave the console agents intact.
38 //
39 // You an call injectConsoleAgents multiple times with this factory.
40 //
41 // If you want to override existing agents you can subclass this factory,
42 // override the method of interest and call injectConsoleAgents, it will replace
43 // the existing agents with the one your factory provides.
44 class AndroidConsoleFactory {
45 public:
46     virtual ~AndroidConsoleFactory() = default;
47     ANDROID_CONSOLE_AGENTS_LIST(ANDROID_DEFINE_CONSOLE_GETTER)
48 };
49 
50 
51 // Call this method to inject the console agents into the emulator. You usally
52 // want to call this function *BEFORE* any calls to getConsoleAgents are made.
53 //
54 // You can provide a factory that will be used to construct all the individual
55 // agents.
56 //
57 // Note: It is currently not safe to inject agents after the first injection has
58 // taken place.
59 void injectConsoleAgents(
60         const AndroidConsoleFactory& factory);
61 
62 }  // namespace emulation
63 }  // namespace android
64 
65 extern "C" {
66 
67 #define ANDROID_CONSOLE_DEFINE_POINTER(type, name) const type* name;
68 typedef struct AndroidConsoleAgents {
69     ANDROID_CONSOLE_AGENTS_LIST(ANDROID_CONSOLE_DEFINE_POINTER)
70 } AndroidConsoleAgents;
71 
72 const AndroidConsoleAgents* getConsoleAgents();
73 
74 } // extern "C"
75