Add missing permission notice in each source file
[babeltrace.git] / formats / ctf / callbacks.c
index f4e0a1451c84974deba2b279563ba663e71aac14..71e3248868239fd806d6cceb2bdcce48e9e06886 100644 (file)
  *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
  */
 
 #include <babeltrace/babeltrace.h>
@@ -73,8 +81,12 @@ int bt_ctf_iter_add_callback(struct bt_ctf_iter *iter,
        int i, stream_id;
        gpointer *event_id_ptr;
        unsigned long event_id;
-       struct trace_collection *tc = iter->parent.ctx->tc;
+       struct trace_collection *tc;
+
+       if (!iter || !callback)
+               return -EINVAL;
 
+       tc = iter->parent.ctx->tc;
        for (i = 0; i < tc->array->len; i++) {
                struct ctf_trace *tin;
                struct trace_descriptor *td_read;
@@ -83,7 +95,7 @@ int bt_ctf_iter_add_callback(struct bt_ctf_iter *iter,
                tin = container_of(td_read, struct ctf_trace, parent);
 
                for (stream_id = 0; stream_id < tin->streams->len; stream_id++) {
-                       struct ctf_stream_class *stream;
+                       struct ctf_stream_declaration *stream;
                        struct bt_stream_callbacks *bt_stream_cb = NULL;
                        struct bt_callback_chain *bt_chain = NULL;
                        struct bt_callback new_callback;
@@ -106,7 +118,7 @@ int bt_ctf_iter_add_callback(struct bt_ctf_iter *iter,
                                                (gconstpointer) (unsigned long) event);
                                /* event not found in this stream class */
                                if (!event_id_ptr) {
-                                       fprintf(stderr, "event not found\n");
+                                       fprintf(stderr, "[error] Event ID not found in stream class\n");
                                        continue;
                                }
                                event_id = (uint64_t)(unsigned long) *event_id_ptr;
@@ -146,33 +158,33 @@ int bt_ctf_iter_add_callback(struct bt_ctf_iter *iter,
 }
 
 static
-struct ctf_stream_event *extract_ctf_stream_event(struct ctf_stream *stream)
+int extract_ctf_stream_event(struct ctf_stream_definition *stream,
+               struct bt_ctf_event *event)
 {
-       struct ctf_stream_class *stream_class = stream->stream_class;
-       struct ctf_event *event_class;
-       struct ctf_stream_event *event;
+       struct ctf_stream_declaration *stream_class = stream->stream_class;
+       struct ctf_event_declaration *event_class;
        uint64_t id = stream->event_id;
 
        if (id >= stream_class->events_by_id->len) {
                fprintf(stderr, "[error] Event id %" PRIu64 " is outside range.\n", id);
-               return NULL;
+               return -1;
        }
-       event = g_ptr_array_index(stream->events_by_id, id);
-       if (!event) {
+       event->parent = g_ptr_array_index(stream->events_by_id, id);
+       if (!event->parent) {
                fprintf(stderr, "[error] Event id %" PRIu64 " is unknown.\n", id);
-               return NULL;
+               return -1;
        }
        event_class = g_ptr_array_index(stream_class->events_by_id, id);
        if (!event_class) {
                fprintf(stderr, "[error] Event id %" PRIu64 " is unknown.\n", id);
-               return NULL;
+               return -1;
        }
 
-       return event;
+       return 0;
 }
 
 void process_callbacks(struct bt_ctf_iter *iter,
-                      struct ctf_stream *stream)
+                      struct ctf_stream_definition *stream)
 {
        struct bt_stream_callbacks *bt_stream_cb;
        struct bt_callback_chain *bt_chain;
@@ -181,8 +193,11 @@ void process_callbacks(struct bt_ctf_iter *iter,
        enum bt_cb_ret ret;
        struct bt_ctf_event ctf_data;
 
-       ctf_data.event = extract_ctf_stream_event(stream);
-       ctf_data.stream = stream;
+       assert(iter && stream);
+
+       ret = extract_ctf_stream_event(stream, &ctf_data);
+       if (ret)
+               goto end;
 
        /* process all events callback first */
        if (iter->main_callbacks.callback) {
This page took 0.024107 seconds and 4 git commands to generate.