anbox-platform-sdk  1.22.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 
53 namespace anbox {
59 class AnboxProxy {
60  public:
61  AnboxProxy() = default;
62  virtual ~AnboxProxy() = default;
63  AnboxProxy(const AnboxProxy &) = delete;
64  AnboxProxy& operator=(const AnboxProxy &) = delete;
65 
73  if (!change_screen_orientation_callback_)
74  return -EINVAL;
75  return change_screen_orientation_callback_(orientation_type, screen_orientation_callback_user_data_);
76  }
77 
80  void* user_data) {
81  change_screen_orientation_callback_ = callback;
82  screen_orientation_callback_user_data_ = user_data;
83  }
84 
91  int change_display_density(uint32_t density) {
92  if (!change_display_density_callback_)
93  return -EINVAL;
94  return change_display_density_callback_(density, display_density_callback_user_data_);
95  }
96 
99  void* user_data) {
100  change_display_density_callback_ = callback;
101  display_density_callback_user_data_ = user_data;
102  }
103 
111  int change_display_size(uint32_t width, uint32_t height) {
112  if (!change_display_size_callback_)
113  return -EINVAL;
114  return change_display_size_callback_(width, height, display_size_callback_user_data_);
115  }
116 
119  void* user_data) {
120  change_display_size_callback_ = callback;
121  display_size_callback_user_data_ = user_data;
122  }
123 
140  int trigger_action(const char* name, const char** args, size_t args_len) {
141  if (!trigger_action_callback_)
142  return -EINVAL;
143  return trigger_action_callback_(name, args, args_len, trigger_action_callback_user_data_);
144  }
145 
148  void* user_data) {
149  trigger_action_callback_ = callback;
150  trigger_action_callback_user_data_ = user_data;
151  }
152 
162  virtual int send_message(const char* type, size_t type_size,
163  const char* data, size_t data_size) {
164  (void) type;
165  (void) type_size;
166  (void) data;
167  (void) data_size;
168  return -EIO;
169  }
170 
171  private:
172  AnboxChangeScreenOrientationCallback change_screen_orientation_callback_{nullptr};
173  AnboxChangeDisplayDensityCallback change_display_density_callback_{nullptr};
174  AnboxChangeDisplaySizeCallback change_display_size_callback_{nullptr};
175  AnboxTriggerActionCallback trigger_action_callback_{nullptr};
176  void* screen_orientation_callback_user_data_{nullptr};
177  void* display_density_callback_user_data_{nullptr};
178  void* display_size_callback_user_data_{nullptr};
179  void* trigger_action_callback_user_data_{nullptr};
180 };
181 } // namespace anbox
182 
183 #endif
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:59
void set_change_display_size_callback(const AnboxChangeDisplaySizeCallback &callback, void *user_data)
Set the display size change callback.
Definition: anbox_proxy.h:118
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:79
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:140
int change_display_size(uint32_t width, uint32_t height)
Change the display size.
Definition: anbox_proxy.h:111
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:162
int change_screen_orientation(AnboxScreenOrientationType orientation_type)
Change the screen orientation.
Definition: anbox_proxy.h:72
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:98
void set_trigger_action_callback(const AnboxTriggerActionCallback &callback, void *user_data)
Set the trigger action callback.
Definition: anbox_proxy.h:147
int change_display_density(uint32_t density)
Change the display density.
Definition: anbox_proxy.h:91
AnboxProxy & operator=(const AnboxProxy &)=delete
AnboxScreenOrientationType
AnboxScreenOrientationType describes the type of display orientation.
Definition: types.h:650