anbox-platform-sdk  1.29.0
Anbox Platform SDK API documentation
platform.h
Go to the documentation of this file.
1 /*
2  * This file is part of Anbox Platform SDK
3  *
4  * Copyright 2021 Canonical Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef ANBOX_PLATFORM_SDK_PLATFORM_H_
20 #define ANBOX_PLATFORM_SDK_PLATFORM_H_
21 
34 
35 #include <iostream>
36 #include <exception>
37 
38 namespace anbox {
39 
48 class Platform {
49  public:
50  Platform() = default;
51  virtual ~Platform() = default;
52  Platform(const Platform &) = delete;
53  Platform& operator=(const Platform &) = delete;
54 
65 
76 
87  virtual GraphicsProcessor* graphics_processor() { return nullptr; }
88 
98  virtual SensorProcessor* sensor_processor() { return nullptr; }
99 
109  virtual GpsProcessor* gps_processor() { return nullptr; }
110 
121  virtual CameraProcessor* camera_processor() { return nullptr; }
122 
131  virtual AnboxProxy* anbox_proxy() { return &anbox_proxy_; }
132 
140  (void) codec_type;
141  return nullptr;
142  }
143 
154  virtual VhalConnector* vhal_connector() { return &vhal_connector_; }
155 
163  virtual bool ready() const = 0;
164 
173  virtual int wait_until_ready() = 0;
174 
190  virtual int get_config_item(AnboxPlatformConfigurationKey key, void* data, size_t data_size) = 0;
191 
205  virtual int stop() { return 0; }
206 
216  virtual void handle_event(AnboxEventType type) { (void)type; }
217 
235  virtual int set_config_item(AnboxPlatformConfigurationKey key, void* data, size_t data_size) {
236  (void)key;
237  (void)data;
238  (void)data_size;
239  return 0;
240  }
241 
266  virtual int set_config_items(const AnboxPlatformConfigurationItem* items, size_t count) {
267  (void)items;
268  (void)count;
269  return 0;
270  }
271 
278  virtual void setup_event_tracer(
279  AnboxTracerGetCategoryEnabledFunc get_category_enabled_callback,
280  AnboxTracerAddEventFunc add_event_callback) {
281  (void) get_category_enabled_callback;
282  (void) add_event_callback;
283  }
284 
285  private:
286  AnboxProxy anbox_proxy_;
287  VhalConnector vhal_connector_;
288 };
289 }
290 
305 #define ANBOX_PLATFORM_PLUGIN_DESCRIBE(platform_type, name, vendor, \
306  description) \
307  AnboxPlatformDescriptor anbox_platform_descriptor \
308  __attribute((section(ANBOX_PLATFORM_DESCRIPTOR_SECTION))) = { \
309  name, vendor, description, ANBOX_PLATFORM_VERSION}; \
310  extern "C" { \
311  ANBOX_EXPORT AnboxPlatform* anbox_initialize( \
312  const AnboxPlatformConfiguration* configuration) { \
313  try { \
314  auto platform = std::make_unique<platform_type>(configuration); \
315  return anbox_platform_plugin_register(std::move(platform)); \
316  } catch (const std::exception& e) { \
317  std::cerr << "Anbox Platform SDK caught exception: " << e.what() \
318  << std::endl; \
319  return nullptr; \
320  } catch (...) { \
321  std::cerr << "Anbox Platform SDK caught unknown exception." \
322  << std::endl; \
323  return nullptr; \
324  } \
325  } \
326  \
327  ANBOX_EXPORT void anbox_deinitialize(AnboxPlatform* platform) { \
328  anbox_platform_plugin_unregister(platform); \
329  } \
330  }
331 
332 #endif
AnboxProxy provides a proxy layer which encapsulates callbacks that can be used by a platform to chan...
Definition: anbox_proxy.h:71
AudioProcessor allows processing audio data from the Android container and perform audio processing l...
CameraProcessor allows a plugin to respond to the camera actions triggered from Anobx and post video ...
GpsProcessor allows forwarding the gps data from platform plugin to Android container and process gps...
Definition: gps_processor.h:38
GraphicsProcessor allows integration with the graphics engine inside Anbox.
InputProcessor allows a plugin to propagate input events to Anbox which will forward them to the Andr...
Platform defines the custom Anbox platform implemented by a plugin.
Definition: platform.h:48
virtual InputProcessor * input_processor()=0
Retrieve the platform input processor instance.
virtual AnboxProxy * anbox_proxy()
Retrieve the platform anbox proxy.
Definition: platform.h:131
Platform()=default
virtual CameraProcessor * camera_processor()
Retrieve the platform camera processor instance.
Definition: platform.h:121
virtual GpsProcessor * gps_processor()
Retrieve the platform gps processor instance.
Definition: platform.h:109
virtual GraphicsProcessor * graphics_processor()
Retrieve the platform graphics processor instance.
Definition: platform.h:87
virtual void handle_event(AnboxEventType type)
Handle an event sending from Anbox.
Definition: platform.h:216
virtual bool ready() const =0
Query the platform for its ready status.
virtual AudioProcessor * audio_processor()=0
Retrieve the platform audio processor instance.
virtual int set_config_items(const AnboxPlatformConfigurationItem *items, size_t count)
Set multiple configuration options to the platform in a single transaction.
Definition: platform.h:266
virtual VideoDecoder * create_video_decoder(AnboxVideoCodecType codec_type)
Create a video decoder instances for a codec of the given name.
Definition: platform.h:139
virtual ~Platform()=default
virtual int wait_until_ready()=0
Wait for platform plugin to be initialized.
virtual VhalConnector * vhal_connector()
Retrieve the platform vhal connector instance.
Definition: platform.h:154
virtual int get_config_item(AnboxPlatformConfigurationKey key, void *data, size_t data_size)=0
Retrieve the configuration options provided by the platform plugin.
Platform & operator=(const Platform &)=delete
virtual int set_config_item(AnboxPlatformConfigurationKey key, void *data, size_t data_size)
Set the configuration options by Anbox to the platform.
Definition: platform.h:235
Platform(const Platform &)=delete
virtual void setup_event_tracer(AnboxTracerGetCategoryEnabledFunc get_category_enabled_callback, AnboxTracerAddEventFunc add_event_callback)
Register an external event tracing implementation withe platform.
Definition: platform.h:278
virtual SensorProcessor * sensor_processor()
Retrieve the platform sensor processor instance.
Definition: platform.h:98
virtual int stop()
Ask the platform to stop any pending work it has to prepare for Anbox to terminate.
Definition: platform.h:205
SensorProcessor allows processing sensor events from the Android container and perform sensor process...
Connects a platform with the Android VHAL interface. The platform can invoke the callbacks which are ...
Provides access to a video decoder which will be used by both Anbox and the Android instance for hard...
Definition: video_decoder.h:29
Represents a single configuration item.
Definition: types.h:674
AnboxPlatformConfigurationKey
AnboxPlatformConfigurationKey specifies configuration items which allow to influence the behavior and...
Definition: types.h:482
AnboxVideoCodecType
AnboxVideoCodecType describes the type of a video codec.
Definition: types.h:1653
const unsigned char *(* AnboxTracerGetCategoryEnabledFunc)(const char *name)
Method prototype which will be used to determine if the given tracing category is enabled for tracing...
Definition: types.h:1710
void(* AnboxTracerAddEventFunc)(char phase, const unsigned char *category, const char *name, unsigned long long id, int num_args, const char **arg_names, const unsigned char *arg_types, const unsigned long long *arg_values, unsigned char flags)
Method prototype which will be used by the platform to submit trace events to the tracing implementat...
Definition: types.h:1750
AnboxEventType
AnboxEventType describes the type of event sent from Anbox.
Definition: types.h:728