blob: 838ee31effbe22c08e50138cff3533fefe15f375 [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.
38data_dispatcher_t *data_dispatcher_new(const char *name);
39
40// Frees a data dispatcher object created by |data_dispatcher_new|.
41// |data_dispatcher| may be NULL.
42void data_dispatcher_free(data_dispatcher_t *dispatcher);
43
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.
48void data_dispatcher_register(data_dispatcher_t *dispatcher, data_dispatcher_type_t type, fixed_queue_t *queue);
49
50// Registers a default queue to send data to when there is not a specific
51// type/queue relationship registered. If a default queue is already registered,
52// it is replaced. If |queue| is NULL, the existing registration is
53// removed, if it exists. |dispatcher| may not be NULL.
54void data_dispatcher_register_default(data_dispatcher_t *dispatcher, fixed_queue_t *queue);
55
56// Dispatches |data| to the queue registered for |type|. If no such registration
57// exists, it is dispatched to the default queue if it exists.
58// Neither |dispatcher| nor |data| may be NULL.
59// Returns true if data dispatch was successful.
60bool data_dispatcher_dispatch(data_dispatcher_t *dispatcher, data_dispatcher_type_t type, void *data);
Jakub Pawlowski2b56e012016-05-26 10:13:40 -070061
62#ifdef __cplusplus
63}
64#endif