+/*
+ * Add UST context to channel.
+ */
+static int add_uctx_to_channel(struct ltt_ust_session *usess, int domain,
+ struct ltt_ust_channel *uchan, struct lttng_event_context *ctx)
+{
+ int ret;
+ struct ltt_ust_context *uctx;
+
+ /* Create ltt UST context */
+ uctx = trace_ust_create_context(ctx);
+ if (uctx == NULL) {
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
+
+ switch (domain) {
+ case LTTNG_DOMAIN_UST:
+ ret = ust_app_add_ctx_channel_glb(usess, uchan, uctx);
+ if (ret < 0) {
+ goto error;
+ }
+ break;
+ default:
+ ret = LTTCOMM_NOT_IMPLEMENTED;
+ goto error;
+ }
+
+ /* Add ltt UST context node to ltt UST channel */
+ hashtable_add_unique(uchan->ctx, &uctx->node);
+
+ return LTTCOMM_OK;
+
+error:
+ free(uctx);
+ return ret;
+}
+
+/*
+ * Add UST context to event.
+ */
+static int add_uctx_to_event(struct ltt_ust_session *usess, int domain,
+ struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent,
+ struct lttng_event_context *ctx)
+{
+ int ret;
+ struct ltt_ust_context *uctx;
+
+ /* Create ltt UST context */
+ uctx = trace_ust_create_context(ctx);
+ if (uctx == NULL) {
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
+
+ switch (domain) {
+ case LTTNG_DOMAIN_UST:
+ ret = ust_app_add_ctx_event_glb(usess, uchan, uevent, uctx);
+ if (ret < 0) {
+ goto error;
+ }
+ break;
+ default:
+ ret = LTTCOMM_NOT_IMPLEMENTED;
+ goto error;
+ }
+
+ /* Add ltt UST context node to ltt UST event */
+ hashtable_add_unique(uevent->ctx, &uctx->node);
+
+ return LTTCOMM_OK;
+
+error:
+ free(uctx);
+ return ret;
+}
+