-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathctrlm_network.h
More file actions
335 lines (290 loc) · 15.8 KB
/
ctrlm_network.h
File metadata and controls
335 lines (290 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
* If not stated otherwise in this file or this component's license file the
* following copyright and licenses apply:
*
* Copyright 2014 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _CTRLM_NETWORK_H_
#define _CTRLM_NETWORK_H_
#include <string>
#include <map>
#include <vector>
#include <memory>
#include <glib.h>
#include "ctrlm.h"
#include "ctrlm_rcu.h"
#include "ctrlm_controller.h"
#include "ctrlm_recovery.h"
#include "ctrlm_validation.h"
#include "ctrlm_ipc_device_update.h"
#include "ctrlm_voice_types.h"
#include "ctrlm_voice_obj.h"
#include "ctrlm_rcp_ipc_event.h"
#define THREAD_ID_VALIDATE() thread_id_validate(__FUNCTION__)
typedef struct : public ctrlm_network_all_ipc_result_wrapper_t {
unsigned char api_revision;
unsigned int timeout;
bool screen_bind_enable;
bool scan_enable;
std::vector<uint64_t> ieee_address_list;
} ctrlm_iarm_call_StartPairing_params_t;
typedef struct : public ctrlm_network_all_ipc_result_wrapper_t {
unsigned char api_revision;
bool screen_bind_disable;
bool scan_disable;
} ctrlm_iarm_call_StopPairing_params_t;
typedef struct : public ctrlm_network_all_ipc_result_wrapper_t {
ctrlm_fmr_alarm_level_t level;
unsigned int duration;
} ctrlm_iarm_call_FindMyRemote_params_t;
typedef struct : public ctrlm_network_all_ipc_result_wrapper_t {
uint64_t ieee_address;
uint8_t percent_increment;
std::string filetype;
std::string filename;
std::shared_ptr<std::vector<std::string>> upgrade_sessions;
} ctrlm_iarm_call_StartUpgrade_params_t;
typedef struct : public ctrlm_network_all_ipc_result_wrapper_t {
std::string session_id;
} ctrlm_iarm_call_CancelUpgrade_params_t;
typedef struct : public ctrlm_network_all_ipc_result_wrapper_t {
std::vector<uint64_t> ieee_address_list;
} ctrlm_iarm_call_Unpair_params_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
ctrlm_hal_network_property_t property;
void * value;
} ctrlm_main_queue_msg_network_property_set_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
ctrlm_voice_iarm_call_voice_session_t *params;
sem_t * semaphore;
} ctrlm_main_queue_msg_voice_session_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
std::shared_ptr<ctrlm_network_all_ipc_reply_wrapper_t<ctrlm_rcp_ipc_net_status_t>> params;
sem_t * semaphore;
} ctrlm_main_queue_msg_get_rcu_status_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
std::shared_ptr<ctrlm_network_all_ipc_reply_wrapper_t<ctrlm_main_iarm_call_last_key_info_t>> params;
sem_t * semaphore;
} ctrlm_main_queue_msg_get_last_keypress_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
std::shared_ptr<ctrlm_iarm_call_StartPairing_params_t> params;
sem_t * semaphore;
} ctrlm_main_queue_msg_start_pairing_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
std::shared_ptr<ctrlm_iarm_call_StopPairing_params_t> params;
sem_t * semaphore;
} ctrlm_main_queue_msg_stop_pairing_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
ctrlm_iarm_call_StartPairWithCode_params_t *params;
sem_t * semaphore;
} ctrlm_main_queue_msg_pair_with_code_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
std::shared_ptr<ctrlm_iarm_call_FindMyRemote_params_t> params;
sem_t * semaphore;
} ctrlm_main_queue_msg_find_my_remote_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
ctrlm_iarm_call_WriteRcuWakeupConfig_params_t *params;
sem_t * semaphore;
} ctrlm_main_queue_msg_write_advertising_config_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
std::shared_ptr<ctrlm_iarm_call_StartUpgrade_params_t> params;
sem_t * semaphore;
} ctrlm_main_queue_msg_start_controller_upgrade_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
std::shared_ptr<ctrlm_iarm_call_CancelUpgrade_params_t> params;
sem_t * semaphore;
} ctrlm_main_queue_msg_cancel_controller_upgrade_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
std::shared_ptr<ctrlm_rcp_ipc_upgrade_status_t> params;
sem_t * semaphore;
} ctrlm_main_queue_msg_status_controller_upgrade_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
std::shared_ptr<ctrlm_iarm_call_Unpair_params_t> params;
sem_t * semaphore;
} ctrlm_main_queue_msg_unpair_t;
typedef struct {
ctrlm_main_queue_msg_header_t header;
bool * network_managing_upgrade;
char archive_file_path[CTRLM_DEVICE_UPDATE_PATH_LENGTH];
char temp_dir_path[CTRLM_DEVICE_UPDATE_PATH_LENGTH];
sem_t * semaphore;
} ctrlm_main_queue_msg_network_fw_upgrade_t;
typedef struct {
sem_t *semaphore;
ctrlm_hal_req_term_t term;
GThread *hal_thread;
} ctrlm_network_term_hal_t;
void ctrlm_network_property_set(ctrlm_network_id_t network_id, ctrlm_hal_network_property_t property, void *value, guint32 length);
typedef void *(*ctrlm_hal_network_main_t)(ctrlm_hal_main_init_t *main_init);
typedef ctrlm_hal_result_t (*ctrlm_hal_req_network_term_t)(void);
class ctrlm_obj_network_t
{
public:
ctrlm_obj_network_t(ctrlm_network_type_t type, ctrlm_network_id_t id, const char *name, gboolean mask_key_codes, GThread *original_thread);
ctrlm_obj_network_t();
virtual ~ctrlm_obj_network_t();
// External methods
ctrlm_network_id_t network_id_get() const;
ctrlm_network_type_t type_get() const;
const char * name_get() const;
const char * version_get() const;
virtual std::string db_name_get() const;
virtual void device_id_set(const std::string& device_id);
std::string device_id_get() const;
void service_account_id_set(const std::string& service_account_id);
std::string service_account_id_get() const;
void partner_id_set(const std::string& partner_id);
std::string partner_id_get() const;
void experience_set(const std::string& experience);
std::string experience_get() const;
void mask_key_codes_set(gboolean mask_key_codes);
gboolean mask_key_codes_get() const;
void stb_name_set(const std::string& stb_name);
std::string stb_name_get() const;
void validation_result_set(ctrlm_rcu_validation_result_t result);
void validation_key_set(ctrlm_key_code_t key);
void validation_status_get(ctrlm_rcu_validation_result_t *result, ctrlm_key_code_t *key) const;
virtual ctrlm_hal_result_t network_init(GThread *ctrlm_main_thread);
virtual void network_destroy();
void hal_api_main_set(ctrlm_hal_network_main_t main);
void hal_api_set(ctrlm_hal_req_property_get_t property_get,
ctrlm_hal_req_property_set_t property_set,
ctrlm_hal_req_term_t term);
virtual ctrlm_hal_result_t hal_init_request(GThread *ctrlm_main_thread);
void hal_init_confirm(ctrlm_hal_result_t result, const char *version);
virtual void hal_init_cfm(void *data, int size);
ctrlm_hal_result_t property_get(ctrlm_hal_network_property_t property, void **value);
ctrlm_hal_result_t property_set(ctrlm_hal_network_property_t property, void *value);
virtual void thread_monitor_poll(ctrlm_thread_monitor_response_t *response);
bool is_ready() const;
virtual void disable_hal_calls();
virtual bool message_dispatch(gpointer msg);
virtual void hal_init_complete();
virtual void start(GMainLoop* main_loop);
virtual void controller_list_get(std::vector<ctrlm_controller_id_t>& list) const;
virtual ctrlm_rcu_controller_type_t ctrlm_controller_type_get(ctrlm_controller_id_t controller_id);
virtual ctrlm_rcu_binding_type_t ctrlm_binding_type_get(ctrlm_controller_id_t controller_id);
virtual void ctrlm_controller_status_get(ctrlm_controller_id_t controller_id, void *status);
virtual bool controller_exists(ctrlm_controller_id_t controller_id);
virtual void controller_exists(void *data, int size);
virtual void controller_unbind(ctrlm_controller_id_t controller_id, ctrlm_unbind_reason_t reason);
virtual void ind_process_voice_session_request(void *data, int size);
virtual void ind_process_voice_session_first_audio_packet(void *data, int size);
virtual void ind_process_voice_session_stop(void *data, int size);
virtual void ind_process_voice_session_begin(void *data, int size);
virtual void ind_process_voice_session_end(void *data, int size);
virtual void ind_process_voice_session_result(void *data, int size);
virtual void process_voice_controller_metrics(void *data, int size);
virtual void voice_command_status_set(void *data, int size);
virtual gboolean terminate_voice_session(ctrlm_voice_session_termination_reason_t reason);
virtual void set_timers();
virtual void xconf_configuration();
virtual json_t * xconf_export_controllers();
virtual bool is_fmr_supported() const;
virtual ctrlm_controller_status_cmd_result_t req_process_reverse_cmd(ctrlm_main_queue_msg_rcu_reverse_cmd_t *dqm);
virtual void factory_reset();
virtual bool binding_config_set(ctrlm_controller_bind_config_t conf);
virtual bool discovery_config_set(ctrlm_controller_discovery_config_t conf);
virtual void cs_values_set(const ctrlm_cs_values_t *values, bool db_load);
virtual void recovery_set(ctrlm_recovery_type_t recovery);
virtual bool backup_hal_nvm();
virtual void bind_validation_begin(ctrlm_main_queue_msg_bind_validation_begin_t *dqm);
virtual void bind_validation_key(ctrlm_main_queue_msg_bind_validation_key_t *dqm);
virtual void bind_validation_end(ctrlm_main_queue_msg_bind_validation_end_t *dqm);
virtual bool bind_validation_timeout(ctrlm_controller_id_t controller_id);
virtual std::vector<ctrlm_obj_controller_t *> get_controller_obj_list() const;
virtual ctrlm_ir_state_t get_ir_prog_state() const;
virtual void set_rf_pair_state(ctrlm_rf_pair_state_t rf_pair_state);
virtual ctrlm_rf_pair_state_t get_rf_pair_state() const;
virtual void req_process_network_status(void *data, int size);
virtual void req_process_chip_status(void *data, int size);
virtual void req_process_controller_link_key(void *data, int size);
virtual void req_process_controller_status(void *data, int size);
virtual void req_process_controller_product_name(void *data, int size);
virtual void req_process_voice_session_begin(void *data, int size);
virtual void req_process_voice_session_end(void *data, int size);
virtual void req_process_start_pairing(void *data, int size);
virtual void req_process_stop_pairing(void *data, int size);
virtual void req_process_pair_with_code(void *data, int size);
virtual void req_process_get_rcu_status(void *data, int size);
virtual void req_process_get_last_keypress(void *data, int size);
virtual void req_process_write_rcu_wakeup_config(void *data, int size);
virtual void req_process_unpair(void *data, int size);
virtual void req_process_program_ir_codes(void *data, int size);
virtual void req_process_ir_clear_codes(void *data, int size);
virtual void req_process_find_my_remote(void *data, int size);
virtual void req_process_rib_set(void *data, int size);
virtual void req_process_rib_get(void *data, int size);
virtual void req_process_polling_action_push(void *data, int size);
virtual void req_process_network_managed_upgrade(void *data, int size);
virtual void req_process_upgrade_controllers(void *data, int size);
virtual void req_process_start_controller_upgrade(void *data, int size);
virtual void req_process_cancel_controller_upgrade(void *data, int size);
virtual void req_process_status_controller_upgrade(void *data, int size);
virtual bool analyze_assert_reason(const char *assert_info );
bool is_failed_state() const;
virtual void power_state_change(gboolean waking_up);
time_t stale_remote_time_threshold_get();
virtual void iarm_event_rcu_status(void);
virtual void iarm_event_rcu_validation_status(void);
virtual void iarm_event_rcu_firmware_status(const ctrlm_obj_controller_t &rcu);
virtual void start_controller_audio_streaming(ctrlm_voice_start_audio_params_t *params);
// Internal methods
std::string version_;
ctrlm_hal_result_t init_result_ = CTRLM_HAL_RESULT_ERROR;
gboolean ready_ = false;
GThread *hal_thread_ = NULL;
bool failed_state_ = false;
protected:
GThread * original_thread_ = NULL;
GThread * ctrlm_main_thread_ = NULL;
sem_t semaphore_;
ctrlm_network_type_t type_ = CTRLM_NETWORK_TYPE_INVALID;
ctrlm_network_id_t id_ = 0;
std::string name_;
ctrlm_rf_pair_state_t state_ = CTRLM_RF_PAIR_STATE_INITIALIZING;
ctrlm_ir_state_t ir_state_ = CTRLM_IR_STATE_IDLE;
const char * get_thread_name(const GThread *thread_id) const;
void thread_id_validate(const char *pCallingFunction) const;
virtual gboolean key_event_hook(ctrlm_network_id_t network_id, ctrlm_controller_id_t controller_id, ctrlm_key_status_t key_status, ctrlm_key_code_t key_code);
private:
gboolean mask_key_codes_ = true;
std::string device_id_;
std::string service_account_id_;
std::string partner_id_;
std::string experience_;
std::string stb_name_;
ctrlm_rcu_validation_result_t validation_result_ = CTRLM_RCU_VALIDATION_RESULT_MAX;
ctrlm_key_code_t validation_key_ = CTRLM_KEY_CODE_INVALID;
ctrlm_hal_network_main_t hal_api_main_ = NULL;
ctrlm_hal_req_property_get_t hal_api_property_get_ = NULL;
ctrlm_hal_req_property_set_t hal_api_property_set_ = NULL;
ctrlm_hal_req_term_t hal_api_term_ = NULL;
static gpointer terminate_hal(gpointer data);
};
#endif