-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherror_event.cpp
More file actions
171 lines (137 loc) · 6.09 KB
/
error_event.cpp
File metadata and controls
171 lines (137 loc) · 6.09 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
/*
* Copyright (c) AppDynamics, Inc., and its affiliates
* 2017
*
* 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.
*/
#include "error_event.hpp"
/**
* @brief Fills alert error event structure and <br>
* calls IoT CPP SDK API to add and send the event
*/
void send_error_event_alert(void)
{
appd_iot_error_event_t error_event;
appd_iot_error_code_t retcode;
appd_iot_init_to_zero(&error_event, sizeof(error_event));
error_event.name = "Warning Light";
error_event.message = "Oil Change Reminder";
error_event.severity = APPD_IOT_ERR_SEVERITY_ALERT;
error_event.timestamp_ms = ((int64_t)time(NULL) * 1000);
error_event.duration_ms = 0;
error_event.data_count = 1;
error_event.data = (appd_iot_data_t*)calloc(error_event.data_count, sizeof(appd_iot_data_t));
appd_iot_data_set_integer(&error_event.data[0], "Mileage", 27300);
retcode = appd_iot_add_error_event(error_event);
fprintf(stdout, "Add Alert Error Event Status :%s\n", appd_iot_error_code_to_str(retcode));
free(error_event.data);
if (retcode == APPD_IOT_SUCCESS)
{
retcode = appd_iot_send_all_events();
fprintf(stdout, "Send Alert Error Event Status :%s\n\n", appd_iot_error_code_to_str(retcode));
}
}
/**
* @brief Fills a critical event structure and <br>
* calls IoT CPP SDK API to add and send the event
*/
void send_error_event_critical(void)
{
appd_iot_error_event_t error_event;
appd_iot_error_code_t retcode;
appd_iot_init_to_zero(&error_event, sizeof(error_event));
error_event.name = "Bluetooth Connection Error";
error_event.message = "connection dropped during voice call due to bluetooth exception";
error_event.severity = APPD_IOT_ERR_SEVERITY_CRITICAL;
error_event.timestamp_ms = ((int64_t)time(NULL) * 1000);
error_event.duration_ms = 0;
error_event.data_count = 3;
error_event.data = (appd_iot_data_t*)calloc(error_event.data_count, sizeof(appd_iot_data_t));
appd_iot_data_set_string(&error_event.data[0], "UUID", "00001101-0000-1000-8000-00805f9b34fb");
appd_iot_data_set_string(&error_event.data[1], "Bluetooth Version", "3.0");
appd_iot_data_set_integer(&error_event.data[2], "Error Code", 43);
retcode = appd_iot_add_error_event(error_event);
fprintf(stdout, "Add Critical Error Event Status :%s\n", appd_iot_error_code_to_str(retcode));
free(error_event.data);
if (retcode == APPD_IOT_SUCCESS)
{
retcode = appd_iot_send_all_events();
fprintf(stdout, "Send Critical Error Event Status :%s\n\n", appd_iot_error_code_to_str(retcode));
}
}
/**
* @brief Fills a fatal event structure and <br>
* calls IoT CPP SDK API to add and send the event. <br>
* This event shows how a stack trace could be populated
*/
void send_error_event_fatal(void)
{
appd_iot_error_event_t error_event;
appd_iot_error_code_t retcode;
appd_iot_init_to_zero(&error_event, sizeof(error_event));
error_event.name = "I/O Exception";
error_event.message = "error while writing data to file";
error_event.severity = APPD_IOT_ERR_SEVERITY_FATAL;
error_event.timestamp_ms = ((int64_t)time(NULL) * 1000);
error_event.duration_ms = 0;
error_event.stack_trace_count = 1;
error_event.error_stack_trace_index = 0;
appd_iot_stack_trace_t* stack_trace = (appd_iot_stack_trace_t*)calloc(error_event.stack_trace_count,
sizeof(appd_iot_stack_trace_t));
stack_trace->stack_frame_count = 4;
stack_trace->thread = "main";
appd_iot_stack_frame_t* stack_frame = (appd_iot_stack_frame_t*)calloc(stack_trace->stack_frame_count,
sizeof(appd_iot_stack_frame_t));
stack_trace->stack_frame = stack_frame;
stack_frame[0].symbol_name = "_libc_start_main";
stack_frame[0].package_name = "/system/lib/libc.so";
stack_frame[0].absolute_addr = 0x7f8bd984876c;
stack_frame[1].symbol_name = "main";
stack_frame[1].package_name = "/home/native-app/mediaplayer/build/mediaplayer_main.so";
stack_frame[1].absolute_addr = 0x7f8bd984876c;
stack_frame[1].image_offset = 18861;
stack_frame[1].symbol_offset = 10;
stack_frame[1].file_name = "main.c";
stack_frame[1].lineno = 71;
stack_frame[2].symbol_name = "write_data";
stack_frame[2].package_name = "/home/native-app/mediaplayer/build/mediaplayer_main.so";
stack_frame[2].absolute_addr = 0x7f8bda3f915b;
stack_frame[2].image_offset = 116437;
stack_frame[2].symbol_offset = 12;
stack_frame[2].file_name = "writedata.c";
stack_frame[2].lineno = 271;
stack_frame[3].symbol_name = "write_to_file";
stack_frame[3].package_name = "/home/native-app/mediaplayer/build/mediaplayer_main.so";
stack_frame[3].absolute_addr = 0x7f8bda9f69d1;
stack_frame[3].image_offset = 287531;
stack_frame[3].symbol_offset = 34;
stack_frame[3].file_name = "writedata.c";
stack_frame[3].lineno = 524;
error_event.stack_trace = stack_trace;
error_event.data_count = 4;
error_event.data = (appd_iot_data_t*)calloc(error_event.data_count, sizeof(appd_iot_data_t));
appd_iot_data_set_string(&error_event.data[0], "filename", "buffer-126543.mp3");
appd_iot_data_set_integer(&error_event.data[1], "filesize", 120000000);
appd_iot_data_set_integer(&error_event.data[2], "signal number", 6);
appd_iot_data_set_string(&error_event.data[3], "mediaplayer_version", "1.1");
retcode = appd_iot_add_error_event(error_event);
fprintf(stdout, "Add Fatal Error Event Status :%s\n", appd_iot_error_code_to_str(retcode));
free(error_event.stack_trace->stack_frame);
free(error_event.stack_trace);
free(error_event.data);
if (retcode == APPD_IOT_SUCCESS)
{
retcode = appd_iot_send_all_events();
fprintf(stdout, "Send Fatal Error Event Status :%s\n\n", appd_iot_error_code_to_str(retcode));
}
}