2 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 #ifndef LTTNG_SESSIOND_AGENT_H
19 #define LTTNG_SESSIOND_AGENT_H
24 #include <common/hashtable/hashtable.h>
25 #include <lttng/lttng.h>
27 /* Agent protocol version that is verified during the agent registration. */
28 #define AGENT_MAJOR_VERSION 1
29 #define AGENT_MINOR_VERSION 0
32 * Hash table that contains the agent app created upon registration indexed by
33 * socket. Global to the session daemon.
35 extern struct lttng_ht
*agent_apps_ht_by_sock
;
40 enum lttng_loglevel_type loglevel_type
;
44 * Registration message payload from an agent application. The PID is used to
45 * find back the corresponding UST app object so both socket can be linked.
47 struct agent_register_msg
{
48 /* This maps to a lttng_domain_type. */
51 uint32_t major_version
;
52 uint32_t minor_version
;
56 * Agent application object created after a successful registration. This
57 * object is linked to its associated UST app by their PID through hash table
62 * PID sent during registration of an agent application.
66 /* Domain of the application. */
67 enum lttng_domain_type domain
;
70 * AGENT TCP socket that was created upon registration.
72 struct lttcomm_sock
*sock
;
74 /* Initialized with the AGENT sock value. */
75 struct lttng_ht_node_ulong node
;
79 * Agent event representation.
82 /* Name of the event. */
83 char name
[LTTNG_SYMBOL_NAME_LEN
];
85 enum lttng_loglevel_type loglevel_type
;
88 * Tells if the event is enabled or not on the agent.
90 unsigned int enabled
:1;
92 /* Hash table node of the agent domain object. */
93 struct lttng_ht_node_str node
;
95 /* Filter associated with the event. NULL if none. */
96 struct lttng_filter_bytecode
*filter
;
97 char *filter_expression
;
98 struct lttng_event_exclusion
*exclusion
;
102 * Agent object containing events enabled/disabled for it.
106 * This indicates if that domain is being used meaning if at least one
107 * event has been at some point in time added to it. This is used so when
108 * listing domains for a session, we can tell or not if the agent is
111 unsigned int being_used
:1;
113 /* What domain this agent is. */
114 enum lttng_domain_type domain
;
116 /* Contains event indexed by name. */
117 struct lttng_ht
*events
;
119 /* Node used for the hash table indexed by domain type. */
120 struct lttng_ht_node_u64 node
;
123 /* Allocate agent apps hash table */
124 int agent_app_ht_alloc(void);
125 /* Clean-up agent apps hash table */
126 void agent_app_ht_clean(void);
128 /* Initialize an already allocated agent domain. */
129 int agent_init(struct agent
*agt
);
130 struct agent
*agent_create(enum lttng_domain_type domain
);
131 void agent_destroy(struct agent
*agt
);
132 void agent_add(struct agent
*agt
, struct lttng_ht
*ht
);
134 /* Agent event API. */
135 struct agent_event
*agent_create_event(const char *name
,
136 enum lttng_loglevel_type loglevel_type
, int loglevel_value
,
137 struct lttng_filter_bytecode
*filter
,
138 char *filter_expression
);
139 void agent_add_event(struct agent_event
*event
, struct agent
*agt
);
141 struct agent_event
*agent_find_event(const char *name
,
142 enum lttng_loglevel_type loglevel_type
, int loglevel_value
,
144 void agent_find_events_by_name(const char *name
, struct agent
*agt
,
145 struct lttng_ht_iter
* iter
);
146 void agent_event_next_duplicate(const char *name
,
147 struct agent
*agt
, struct lttng_ht_iter
* iter
);
148 void agent_delete_event(struct agent_event
*event
, struct agent
*agt
);
149 void agent_destroy_event(struct agent_event
*event
);
152 struct agent_app
*agent_create_app(pid_t pid
, enum lttng_domain_type domain
,
153 struct lttcomm_sock
*sock
);
154 void agent_add_app(struct agent_app
*app
);
155 void agent_delete_app(struct agent_app
*app
);
156 struct agent_app
*agent_find_app_by_sock(int sock
);
157 void agent_destroy_app(struct agent_app
*app
);
158 void agent_destroy_app_by_sock(int sock
);
159 int agent_send_registration_done(struct agent_app
*app
);
161 /* Agent action API */
162 int agent_enable_event(struct agent_event
*event
,
163 enum lttng_domain_type domain
);
164 int agent_disable_event(struct agent_event
*event
,
165 enum lttng_domain_type domain
);
166 void agent_update(struct agent
*agt
, int sock
);
167 int agent_list_events(struct lttng_event
**events
,
168 enum lttng_domain_type domain
);
170 #endif /* LTTNG_SESSIOND_AGENT_H */