anbox-platform-sdk  1.23.0
Anbox Platform SDK API documentation
anbox_proxy.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_SDK_ANBOX_PROXY_H_
20 #define ANBOX_SDK_ANBOX_PROXY_H_
21 
23 
24 #include <errno.h>
25 #include <stdint.h>
26 #include <unistd.h>
27 
32 typedef int (*AnboxChangeScreenOrientationCallback)(AnboxScreenOrientationType orientation_type, void* user_data);
33 
38 typedef int (*AnboxChangeDisplayDensityCallback)(uint32_t density, void* user_data);
39 
44 typedef int (*AnboxChangeDisplaySizeCallback)(uint32_t width, uint32_t height, void* user_data);
45 
51 typedef int (*AnboxTriggerActionCallback)(const char* name, const char **args, size_t args_len, void* user_data);
52 
57 typedef int (*AnboxCreateADBConnectionCallback)(const char* id, void* user_data);
58 
59 namespace anbox {
65 class AnboxProxy {
66  public:
67  AnboxProxy() = default;
68  virtual ~AnboxProxy() = default;
69  AnboxProxy(const AnboxProxy &) = delete;
70  AnboxProxy& operator=(const AnboxProxy &) = delete;
71 
79  if (!change_screen_orientation_callback_)
80  return -EINVAL;
81  return change_screen_orientation_callback_(orientation_type, screen_orientation_callback_user_data_);
82  }
83 
86  void* user_data) {
87  change_screen_orientation_callback_ = callback;
88  screen_orientation_callback_user_data_ = user_data;
89  }
90 
97  int change_display_density(uint32_t density) {
98  if (!change_display_density_callback_)
99  return -EINVAL;
100  return change_display_density_callback_(density, display_density_callback_user_data_);
101  }
102 
105  void* user_data) {
106  change_display_density_callback_ = callback;
107  display_density_callback_user_data_ = user_data;
108  }
109 
117  int change_display_size(uint32_t width, uint32_t height) {
118  if (!change_display_size_callback_)
119  return -EINVAL;
120  return change_display_size_callback_(width, height, display_size_callback_user_data_);
121  }
122 
125  void* user_data) {
126  change_display_size_callback_ = callback;
127  display_size_callback_user_data_ = user_data;
128  }
129 
146  int trigger_action(const char* name, const char** args, size_t args_len) {
147  if (!trigger_action_callback_)
148  return -EINVAL;
149  return trigger_action_callback_(name, args, args_len, trigger_action_callback_user_data_);
150  }
151 
154  void* user_data) {
155  trigger_action_callback_ = callback;
156  trigger_action_callback_user_data_ = user_data;
157  }
158 
168  virtual int send_message(const char* type, size_t type_size,
169  const char* data, size_t data_size) {
170  (void) type;
171  (void) type_size;
172  (void) data;
173  (void) data_size;
174  return -EIO;
175  }
176 
184  int create_adb_connection(const char* id) {
185  if (!create_adb_connection_callback_)
186  return -EINVAL;
187  return create_adb_connection_callback_(id, create_adb_connection_callback_user_data_);
188  }
189 
192  void* user_data) {
193  create_adb_connection_callback_ = callback;
194  create_adb_connection_callback_user_data_ = user_data;
195  }
196 
197  private:
198  AnboxChangeScreenOrientationCallback change_screen_orientation_callback_{nullptr};
199  AnboxChangeDisplayDensityCallback change_display_density_callback_{nullptr};
200  AnboxChangeDisplaySizeCallback change_display_size_callback_{nullptr};
201  AnboxTriggerActionCallback trigger_action_callback_{nullptr};
202  AnboxCreateADBConnectionCallback create_adb_connection_callback_{nullptr};
203 
204  void* screen_orientation_callback_user_data_{nullptr};
205  void* display_density_callback_user_data_{nullptr};
206  void* display_size_callback_user_data_{nullptr};
207  void* trigger_action_callback_user_data_{nullptr};
208  void* create_adb_connection_callback_user_data_{nullptr};
209 };
210 } // namespace anbox
211 
212 #endif
int(* AnboxCreateADBConnectionCallback)(const char *id, void *user_data)
AnboxCreateADBConnectionCallback is invoked when creating ADB connection.
Definition: anbox_proxy.h:57
int(* AnboxChangeDisplaySizeCallback)(uint32_t width, uint32_t height, void *user_data)
AnboxChangeDisplaySizeCallback is invoked when changing the display size.
Definition: anbox_proxy.h:44
int(* AnboxTriggerActionCallback)(const char *name, const char **args, size_t args_len, void *user_data)
AnboxTriggerActionCallback is invoked when an action is triggered within the Android system.
Definition: anbox_proxy.h:51
int(* AnboxChangeScreenOrientationCallback)(AnboxScreenOrientationType orientation_type, void *user_data)
AnboxChangeScreenOrientationCallback is invoked when changing the screen orientation.
Definition: anbox_proxy.h:32
int(* AnboxChangeDisplayDensityCallback)(uint32_t density, void *user_data)
AnboxChangeDisplayDensityCallback is invoked when changing the display density.
Definition: anbox_proxy.h:38
AnboxProxy provides a proxy layer which encapsulates callbacks that can be used by a platform to chan...
Definition: anbox_proxy.h:65
void set_change_display_size_callback(const AnboxChangeDisplaySizeCallback &callback, void *user_data)
Set the display size change callback.
Definition: anbox_proxy.h:124
AnboxProxy()=default
AnboxProxy(const AnboxProxy &)=delete
void set_change_screen_orientation_callback(const AnboxChangeScreenOrientationCallback &callback, void *user_data)
Set the screen orientation change callback.
Definition: anbox_proxy.h:85
int trigger_action(const char *name, const char **args, size_t args_len)
Trigger an action which is executed within the Android container.
Definition: anbox_proxy.h:146
void set_create_adb_connection_callback(const AnboxCreateADBConnectionCallback &callback, void *user_data)
Set the ADB connection creation callback.
Definition: anbox_proxy.h:191
int change_display_size(uint32_t width, uint32_t height)
Change the display size.
Definition: anbox_proxy.h:117
virtual int send_message(const char *type, size_t type_size, const char *data, size_t data_size)
Send a message from Anbox to the platform.
Definition: anbox_proxy.h:168
int change_screen_orientation(AnboxScreenOrientationType orientation_type)
Change the screen orientation.
Definition: anbox_proxy.h:78
virtual ~AnboxProxy()=default
void set_change_display_density_callback(const AnboxChangeDisplayDensityCallback &callback, void *user_data)
Set the display density change callback.
Definition: anbox_proxy.h:104
void set_trigger_action_callback(const AnboxTriggerActionCallback &callback, void *user_data)
Set the trigger action callback.
Definition: anbox_proxy.h:153
int change_display_density(uint32_t density)
Change the display density.
Definition: anbox_proxy.h:97
int create_adb_connection(const char *id)
Create ADB connection.
Definition: anbox_proxy.h:184
AnboxProxy & operator=(const AnboxProxy &)=delete
AnboxScreenOrientationType
AnboxScreenOrientationType describes the type of display orientation.
Definition: types.h:680