blob: 009f968fac4a814d8ed5e52c8300695f2ad179b5 [file] [log] [blame]
David Garcia Quintasf72eb972016-05-03 18:28:09 -07001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
David Garcia Quintasf72eb972016-05-03 18:28:09 -07004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * 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
David Garcia Quintasf72eb972016-05-03 18:28:09 -07008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
David Garcia Quintasf72eb972016-05-03 18:28:09 -070010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * 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.
David Garcia Quintasf72eb972016-05-03 18:28:09 -070016 *
17 */
18
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070019#ifndef GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H
20#define GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H
David Garcia Quintasf72eb972016-05-03 18:28:09 -070021
22#include "src/core/lib/iomgr/pollset.h"
23#include "src/core/lib/iomgr/pollset_set.h"
24
Yash Tibrewala7e6d652017-09-20 18:56:37 -070025#ifdef __cplusplus
26extern "C" {
27#endif
28
Yash Tibrewal97dab512017-09-12 14:27:46 -070029typedef enum grpc_pollset_tag {
30 GRPC_POLLS_NONE,
31 GRPC_POLLS_POLLSET,
32 GRPC_POLLS_POLLSET_SET
33} grpc_pollset_tag;
Yash Tibrewal52778c42017-09-11 15:00:11 -070034
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070035/* A grpc_polling_entity is a pollset-or-pollset_set container. It allows
David Garcia Quintas87d5a312017-06-06 19:45:58 -070036 * functions that accept a pollset XOR a pollset_set to do so through an
37 * abstract interface. No ownership is taken. */
David Garcia Quintasf72eb972016-05-03 18:28:09 -070038
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070039typedef struct grpc_polling_entity {
David Garcia Quintas60449092016-05-04 20:20:04 -070040 union {
41 grpc_pollset *pollset;
42 grpc_pollset_set *pollset_set;
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070043 } pollent;
Yash Tibrewal97dab512017-09-12 14:27:46 -070044 grpc_pollset_tag tag;
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070045} grpc_polling_entity;
David Garcia Quintasf72eb972016-05-03 18:28:09 -070046
David Garcia Quintasc4d51122016-06-06 14:56:02 -070047grpc_polling_entity grpc_polling_entity_create_from_pollset_set(
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070048 grpc_pollset_set *pollset_set);
David Garcia Quintas69ff63d2016-06-06 16:39:47 -070049grpc_polling_entity grpc_polling_entity_create_from_pollset(
50 grpc_pollset *pollset);
David Garcia Quintasf72eb972016-05-03 18:28:09 -070051
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070052/** If \a pollent contains a pollset, return it. Otherwise, return NULL */
David Garcia Quintasc4d51122016-06-06 14:56:02 -070053grpc_pollset *grpc_polling_entity_pollset(grpc_polling_entity *pollent);
David Garcia Quintasf72eb972016-05-03 18:28:09 -070054
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070055/** If \a pollent contains a pollset_set, return it. Otherwise, return NULL */
David Garcia Quintasc4d51122016-06-06 14:56:02 -070056grpc_pollset_set *grpc_polling_entity_pollset_set(grpc_polling_entity *pollent);
David Garcia Quintasf72eb972016-05-03 18:28:09 -070057
David Garcia Quintasc4d51122016-06-06 14:56:02 -070058bool grpc_polling_entity_is_empty(const grpc_polling_entity *pollent);
David Garcia Quintasf72eb972016-05-03 18:28:09 -070059
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070060/** Add the pollset or pollset_set in \a pollent to the destination pollset_set
David Garcia Quintas87d5a312017-06-06 19:45:58 -070061 * \a * pss_dst */
David Garcia Quintasc4d51122016-06-06 14:56:02 -070062void grpc_polling_entity_add_to_pollset_set(grpc_exec_ctx *exec_ctx,
David Garcia Quintas69ff63d2016-06-06 16:39:47 -070063 grpc_polling_entity *pollent,
64 grpc_pollset_set *pss_dst);
David Garcia Quintasf72eb972016-05-03 18:28:09 -070065
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070066/** Delete the pollset or pollset_set in \a pollent from the destination
David Garcia Quintas87d5a312017-06-06 19:45:58 -070067 * pollset_set \a * pss_dst */
David Garcia Quintasc4d51122016-06-06 14:56:02 -070068void grpc_polling_entity_del_from_pollset_set(grpc_exec_ctx *exec_ctx,
David Garcia Quintas69ff63d2016-06-06 16:39:47 -070069 grpc_polling_entity *pollent,
70 grpc_pollset_set *pss_dst);
Yash Tibrewala7e6d652017-09-20 18:56:37 -070071#ifdef __cplusplus
72}
73#endif
74
Yash Tibrewal12fc6d42017-10-09 16:43:34 -070075#endif /* GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H */