1 /*
2  * Copyright 2016 MongoDB, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MONGOC_APM_PRIVATE_H
18 #define MONGOC_APM_PRIVATE_H
19 
20 #if !defined(MONGOC_INSIDE) && !defined(MONGOC_COMPILATION)
21 #error "Only <mongoc.h> can be included directly."
22 #endif
23 
24 #include <bson.h>
25 #include "mongoc-apm.h"
26 
27 BSON_BEGIN_DECLS
28 
29 struct _mongoc_apm_callbacks_t {
30    mongoc_apm_command_started_cb_t started;
31    mongoc_apm_command_succeeded_cb_t succeeded;
32    mongoc_apm_command_failed_cb_t failed;
33    mongoc_apm_server_changed_cb_t server_changed;
34    mongoc_apm_server_opening_cb_t server_opening;
35    mongoc_apm_server_closed_cb_t server_closed;
36    mongoc_apm_topology_changed_cb_t topology_changed;
37    mongoc_apm_topology_opening_cb_t topology_opening;
38    mongoc_apm_topology_closed_cb_t topology_closed;
39    mongoc_apm_server_heartbeat_started_cb_t server_heartbeat_started;
40    mongoc_apm_server_heartbeat_succeeded_cb_t server_heartbeat_succeeded;
41    mongoc_apm_server_heartbeat_failed_cb_t server_heartbeat_failed;
42 };
43 
44 /*
45  * command monitoring events
46  */
47 
48 struct _mongoc_apm_command_started_t {
49    bson_t *command;
50    bool command_owned;
51    const char *database_name;
52    const char *command_name;
53    int64_t request_id;
54    int64_t operation_id;
55    const mongoc_host_list_t *host;
56    uint32_t server_id;
57    void *context;
58 };
59 
60 struct _mongoc_apm_command_succeeded_t {
61    int64_t duration;
62    const bson_t *reply;
63    const char *command_name;
64    int64_t request_id;
65    int64_t operation_id;
66    const mongoc_host_list_t *host;
67    uint32_t server_id;
68    void *context;
69 };
70 
71 struct _mongoc_apm_command_failed_t {
72    int64_t duration;
73    const char *command_name;
74    const bson_error_t *error;
75    int64_t request_id;
76    int64_t operation_id;
77    const mongoc_host_list_t *host;
78    uint32_t server_id;
79    void *context;
80 };
81 
82 /*
83  * SDAM monitoring events
84  */
85 
86 struct _mongoc_apm_server_changed_t {
87    const mongoc_host_list_t *host;
88    bson_oid_t topology_id;
89    const mongoc_server_description_t *previous_description;
90    const mongoc_server_description_t *new_description;
91    void *context;
92 };
93 
94 struct _mongoc_apm_server_opening_t {
95    const mongoc_host_list_t *host;
96    bson_oid_t topology_id;
97    void *context;
98 };
99 
100 struct _mongoc_apm_server_closed_t {
101    const mongoc_host_list_t *host;
102    bson_oid_t topology_id;
103    void *context;
104 };
105 
106 struct _mongoc_apm_topology_changed_t {
107    bson_oid_t topology_id;
108    const mongoc_topology_description_t *previous_description;
109    const mongoc_topology_description_t *new_description;
110    void *context;
111 };
112 
113 struct _mongoc_apm_topology_opening_t {
114    bson_oid_t topology_id;
115    void *context;
116 };
117 
118 struct _mongoc_apm_topology_closed_t {
119    bson_oid_t topology_id;
120    void *context;
121 };
122 
123 struct _mongoc_apm_server_heartbeat_started_t {
124    const mongoc_host_list_t *host;
125    void *context;
126 };
127 
128 struct _mongoc_apm_server_heartbeat_succeeded_t {
129    int64_t duration_usec;
130    const bson_t *reply;
131    const mongoc_host_list_t *host;
132    void *context;
133 };
134 
135 struct _mongoc_apm_server_heartbeat_failed_t {
136    int64_t duration_usec;
137    const bson_error_t *error;
138    const mongoc_host_list_t *host;
139    void *context;
140 };
141 
142 void
143 mongoc_apm_command_started_init (mongoc_apm_command_started_t *event,
144                                  const bson_t *command,
145                                  const char *database_name,
146                                  const char *command_name,
147                                  int64_t request_id,
148                                  int64_t operation_id,
149                                  const mongoc_host_list_t *host,
150                                  uint32_t server_id,
151                                  void *context);
152 
153 void
154 mongoc_apm_command_started_cleanup (mongoc_apm_command_started_t *event);
155 
156 void
157 mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event,
158                                    int64_t duration,
159                                    const bson_t *reply,
160                                    const char *command_name,
161                                    int64_t request_id,
162                                    int64_t operation_id,
163                                    const mongoc_host_list_t *host,
164                                    uint32_t server_id,
165                                    void *context);
166 
167 void
168 mongoc_apm_command_succeeded_cleanup (mongoc_apm_command_succeeded_t *event);
169 
170 void
171 mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event,
172                                 int64_t duration,
173                                 const char *command_name,
174                                 const bson_error_t *error,
175                                 int64_t request_id,
176                                 int64_t operation_id,
177                                 const mongoc_host_list_t *host,
178                                 uint32_t server_id,
179                                 void *context);
180 
181 void
182 mongoc_apm_command_failed_cleanup (mongoc_apm_command_failed_t *event);
183 
184 BSON_END_DECLS
185 
186 #endif /* MONGOC_APM_PRIVATE_H */
187