data_dispatcher.h revision 3605c802486424c2fe22b3474c941f224cd56419
13605c802486424c2fe22b3474c941f224cd56419Zach Johnson/******************************************************************************
23605c802486424c2fe22b3474c941f224cd56419Zach Johnson *
33605c802486424c2fe22b3474c941f224cd56419Zach Johnson *  Copyright (C) 2014 Google, Inc.
43605c802486424c2fe22b3474c941f224cd56419Zach Johnson *
53605c802486424c2fe22b3474c941f224cd56419Zach Johnson *  Licensed under the Apache License, Version 2.0 (the "License");
63605c802486424c2fe22b3474c941f224cd56419Zach Johnson *  you may not use this file except in compliance with the License.
73605c802486424c2fe22b3474c941f224cd56419Zach Johnson *  You may obtain a copy of the License at:
83605c802486424c2fe22b3474c941f224cd56419Zach Johnson *
93605c802486424c2fe22b3474c941f224cd56419Zach Johnson *  http://www.apache.org/licenses/LICENSE-2.0
103605c802486424c2fe22b3474c941f224cd56419Zach Johnson *
113605c802486424c2fe22b3474c941f224cd56419Zach Johnson *  Unless required by applicable law or agreed to in writing, software
123605c802486424c2fe22b3474c941f224cd56419Zach Johnson *  distributed under the License is distributed on an "AS IS" BASIS,
133605c802486424c2fe22b3474c941f224cd56419Zach Johnson *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
143605c802486424c2fe22b3474c941f224cd56419Zach Johnson *  See the License for the specific language governing permissions and
153605c802486424c2fe22b3474c941f224cd56419Zach Johnson *  limitations under the License.
163605c802486424c2fe22b3474c941f224cd56419Zach Johnson *
173605c802486424c2fe22b3474c941f224cd56419Zach Johnson ******************************************************************************/
183605c802486424c2fe22b3474c941f224cd56419Zach Johnson
193605c802486424c2fe22b3474c941f224cd56419Zach Johnson#pragma once
203605c802486424c2fe22b3474c941f224cd56419Zach Johnson
213605c802486424c2fe22b3474c941f224cd56419Zach Johnson#include <stdbool.h>
223605c802486424c2fe22b3474c941f224cd56419Zach Johnson#include <stdint.h>
233605c802486424c2fe22b3474c941f224cd56419Zach Johnson
243605c802486424c2fe22b3474c941f224cd56419Zach Johnson#include "fixed_queue.h"
253605c802486424c2fe22b3474c941f224cd56419Zach Johnson
263605c802486424c2fe22b3474c941f224cd56419Zach Johnson#define DISPATCHER_NAME_MAX 16
273605c802486424c2fe22b3474c941f224cd56419Zach Johnson
283605c802486424c2fe22b3474c941f224cd56419Zach Johnsontypedef struct data_dispatcher_t data_dispatcher_t;
293605c802486424c2fe22b3474c941f224cd56419Zach Johnsontypedef uint32_t data_dispatcher_type_t;
303605c802486424c2fe22b3474c941f224cd56419Zach Johnson
313605c802486424c2fe22b3474c941f224cd56419Zach Johnson// Creates a new data dispatcher object, with the given name.
323605c802486424c2fe22b3474c941f224cd56419Zach Johnson// The returned object must be freed by calling |data_dispatcher_free|.
333605c802486424c2fe22b3474c941f224cd56419Zach Johnson// Returns NULL on failure. |name| may not be NULL.
343605c802486424c2fe22b3474c941f224cd56419Zach Johnsondata_dispatcher_t *data_dispatcher_new(const char *name);
353605c802486424c2fe22b3474c941f224cd56419Zach Johnson
363605c802486424c2fe22b3474c941f224cd56419Zach Johnson// Frees a data dispatcher object created by |data_dispatcher_new|.
373605c802486424c2fe22b3474c941f224cd56419Zach Johnson// |data_dispatcher| may be NULL.
383605c802486424c2fe22b3474c941f224cd56419Zach Johnsonvoid data_dispatcher_free(data_dispatcher_t *dispatcher);
393605c802486424c2fe22b3474c941f224cd56419Zach Johnson
403605c802486424c2fe22b3474c941f224cd56419Zach Johnson// Registers |type| and |queue| with the data dispatcher so that data
413605c802486424c2fe22b3474c941f224cd56419Zach Johnson// sent under |type| ends up in |queue|. If |type| is already registered,
423605c802486424c2fe22b3474c941f224cd56419Zach Johnson// it is replaced. If |queue| is NULL, the existing registration is
433605c802486424c2fe22b3474c941f224cd56419Zach Johnson// removed, if it exists. |dispatcher| may not be NULL.
443605c802486424c2fe22b3474c941f224cd56419Zach Johnsonvoid data_dispatcher_register(data_dispatcher_t *dispatcher, data_dispatcher_type_t type, fixed_queue_t *queue);
453605c802486424c2fe22b3474c941f224cd56419Zach Johnson
463605c802486424c2fe22b3474c941f224cd56419Zach Johnson// Registers a default queue to send data to when there is not a specific
473605c802486424c2fe22b3474c941f224cd56419Zach Johnson// type/queue relationship registered. If a default queue is already registered,
483605c802486424c2fe22b3474c941f224cd56419Zach Johnson// it is replaced. If |queue| is NULL, the existing registration is
493605c802486424c2fe22b3474c941f224cd56419Zach Johnson// removed, if it exists. |dispatcher| may not be NULL.
503605c802486424c2fe22b3474c941f224cd56419Zach Johnsonvoid data_dispatcher_register_default(data_dispatcher_t *dispatcher, fixed_queue_t *queue);
513605c802486424c2fe22b3474c941f224cd56419Zach Johnson
523605c802486424c2fe22b3474c941f224cd56419Zach Johnson// Dispatches |data| to the queue registered for |type|. If no such registration
533605c802486424c2fe22b3474c941f224cd56419Zach Johnson// exists, it is dispatched to the default queue if it exists.
543605c802486424c2fe22b3474c941f224cd56419Zach Johnson// Neither |dispatcher| nor |data| may be NULL.
553605c802486424c2fe22b3474c941f224cd56419Zach Johnson// Returns true if data dispatch was successful.
563605c802486424c2fe22b3474c941f224cd56419Zach Johnsonbool data_dispatcher_dispatch(data_dispatcher_t *dispatcher, data_dispatcher_type_t type, void *data);
57