blob: 7349444efc3c3dfad8e241c9f85a891fd87dc32d [file] [log] [blame]
Zach Johnson3605c802014-07-29 16:25:02 -07001/******************************************************************************
2 *
3 * Copyright (C) 2014 Google, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19#pragma once
20
21#include <stdbool.h>
22#include <stdint.h>
23
Pavlin Radoslavovc196f212015-09-23 20:39:53 -070024#include "osi/include/fixed_queue.h"
Zach Johnson3605c802014-07-29 16:25:02 -070025
Jakub Pawlowski2b56e012016-05-26 10:13:40 -070026#ifdef __cplusplus
27extern "C" {
28#endif
29
Zach Johnson3605c802014-07-29 16:25:02 -070030#define DISPATCHER_NAME_MAX 16
31
32typedef struct data_dispatcher_t data_dispatcher_t;
Nitin Aroraa74fcdf2015-03-24 17:15:50 -070033typedef uintptr_t data_dispatcher_type_t;
Zach Johnson3605c802014-07-29 16:25:02 -070034
35// Creates a new data dispatcher object, with the given name.
36// The returned object must be freed by calling |data_dispatcher_free|.
37// Returns NULL on failure. |name| may not be NULL.
Myles Watsonb55040c2016-10-19 13:15:34 -070038data_dispatcher_t* data_dispatcher_new(const char* name);
Zach Johnson3605c802014-07-29 16:25:02 -070039
40// Frees a data dispatcher object created by |data_dispatcher_new|.
41// |data_dispatcher| may be NULL.
Myles Watsonb55040c2016-10-19 13:15:34 -070042void data_dispatcher_free(data_dispatcher_t* dispatcher);
Zach Johnson3605c802014-07-29 16:25:02 -070043
44// Registers |type| and |queue| with the data dispatcher so that data
45// sent under |type| ends up in |queue|. If |type| is already registered,
46// it is replaced. If |queue| is NULL, the existing registration is
47// removed, if it exists. |dispatcher| may not be NULL.
Myles Watsonb55040c2016-10-19 13:15:34 -070048void data_dispatcher_register(data_dispatcher_t* dispatcher,
49 data_dispatcher_type_t type,
50 fixed_queue_t* queue);
Zach Johnson3605c802014-07-29 16:25:02 -070051
52// Registers a default queue to send data to when there is not a specific
53// type/queue relationship registered. If a default queue is already registered,
54// it is replaced. If |queue| is NULL, the existing registration is
55// removed, if it exists. |dispatcher| may not be NULL.
Myles Watsonb55040c2016-10-19 13:15:34 -070056void data_dispatcher_register_default(data_dispatcher_t* dispatcher,
57 fixed_queue_t* queue);
Zach Johnson3605c802014-07-29 16:25:02 -070058
59// Dispatches |data| to the queue registered for |type|. If no such registration
60// exists, it is dispatched to the default queue if it exists.
61// Neither |dispatcher| nor |data| may be NULL.
62// Returns true if data dispatch was successful.
Myles Watsonb55040c2016-10-19 13:15:34 -070063bool data_dispatcher_dispatch(data_dispatcher_t* dispatcher,
64 data_dispatcher_type_t type, void* data);
Jakub Pawlowski2b56e012016-05-26 10:13:40 -070065
66#ifdef __cplusplus
67}
68#endif