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 24c196f214c5ae349ec2022f8d3cbaf56910b3b9f8Pavlin Radoslavov#include "osi/include/fixed_queue.h" 253605c802486424c2fe22b3474c941f224cd56419Zach Johnson 263605c802486424c2fe22b3474c941f224cd56419Zach Johnson#define DISPATCHER_NAME_MAX 16 273605c802486424c2fe22b3474c941f224cd56419Zach Johnson 283605c802486424c2fe22b3474c941f224cd56419Zach Johnsontypedef struct data_dispatcher_t data_dispatcher_t; 29a74fcdfe46726cf629ba6887cb6971bb2c4b8675Nitin Aroratypedef uintptr_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. 34b55040cc6448a8847490da807d2b6362aa8cb8d9Myles Watsondata_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. 38b55040cc6448a8847490da807d2b6362aa8cb8d9Myles Watsonvoid 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. 44b55040cc6448a8847490da807d2b6362aa8cb8d9Myles Watsonvoid data_dispatcher_register(data_dispatcher_t* dispatcher, 45b55040cc6448a8847490da807d2b6362aa8cb8d9Myles Watson data_dispatcher_type_t type, 46b55040cc6448a8847490da807d2b6362aa8cb8d9Myles Watson fixed_queue_t* queue); 473605c802486424c2fe22b3474c941f224cd56419Zach Johnson 483605c802486424c2fe22b3474c941f224cd56419Zach Johnson// Registers a default queue to send data to when there is not a specific 493605c802486424c2fe22b3474c941f224cd56419Zach Johnson// type/queue relationship registered. If a default queue is already registered, 503605c802486424c2fe22b3474c941f224cd56419Zach Johnson// it is replaced. If |queue| is NULL, the existing registration is 513605c802486424c2fe22b3474c941f224cd56419Zach Johnson// removed, if it exists. |dispatcher| may not be NULL. 52b55040cc6448a8847490da807d2b6362aa8cb8d9Myles Watsonvoid data_dispatcher_register_default(data_dispatcher_t* dispatcher, 53b55040cc6448a8847490da807d2b6362aa8cb8d9Myles Watson fixed_queue_t* queue); 543605c802486424c2fe22b3474c941f224cd56419Zach Johnson 553605c802486424c2fe22b3474c941f224cd56419Zach Johnson// Dispatches |data| to the queue registered for |type|. If no such registration 563605c802486424c2fe22b3474c941f224cd56419Zach Johnson// exists, it is dispatched to the default queue if it exists. 573605c802486424c2fe22b3474c941f224cd56419Zach Johnson// Neither |dispatcher| nor |data| may be NULL. 583605c802486424c2fe22b3474c941f224cd56419Zach Johnson// Returns true if data dispatch was successful. 59b55040cc6448a8847490da807d2b6362aa8cb8d9Myles Watsonbool data_dispatcher_dispatch(data_dispatcher_t* dispatcher, 60b55040cc6448a8847490da807d2b6362aa8cb8d9Myles Watson data_dispatcher_type_t type, void* data); 61