blob: d0bb065c8f68358976a45d851b97e1caf8984de7 [file] [log] [blame]
Sree Kuchibhotlabf184282017-03-21 15:18:58 -07001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2017 gRPC authors.
Sree Kuchibhotlabf184282017-03-21 15:18:58 -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
Sree Kuchibhotlabf184282017-03-21 15:18:58 -07008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Sree Kuchibhotlabf184282017-03-21 15:18:58 -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.
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070016 *
17 */
18
19#include "src/core/lib/surface/completion_queue_factory.h"
20#include "src/core/lib/surface/completion_queue.h"
21
22#include <grpc/support/log.h>
23
Sree Kuchibhotla2abbf8a2017-03-21 17:31:03 -070024/*
25 * == Default completion queue factory implementation ==
26 */
27
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070028static grpc_completion_queue* default_create(
29 const grpc_completion_queue_factory* factory,
Sree Kuchibhotla2abbf8a2017-03-21 17:31:03 -070030 const grpc_completion_queue_attributes* attr) {
Sree Kuchibhotlab5b6bfd2017-03-22 02:32:01 -070031 return grpc_completion_queue_create_internal(attr->cq_completion_type,
Sree Kuchibhotla2abbf8a2017-03-21 17:31:03 -070032 attr->cq_polling_type);
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070033}
34
35static grpc_completion_queue_factory_vtable default_vtable = {default_create};
36
37static const grpc_completion_queue_factory g_default_cq_factory = {
Craig Tiller4782d922017-11-10 09:53:21 -080038 "Default Factory", nullptr, &default_vtable};
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070039
Sree Kuchibhotla2abbf8a2017-03-21 17:31:03 -070040/*
41 * == Completion queue factory APIs
42 */
43
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070044const grpc_completion_queue_factory* grpc_completion_queue_factory_lookup(
45 const grpc_completion_queue_attributes* attributes) {
Sree Kuchibhotla2abbf8a2017-03-21 17:31:03 -070046 GPR_ASSERT(attributes->version >= 1 &&
47 attributes->version <= GRPC_CQ_CURRENT_VERSION);
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070048
49 /* The default factory can handle version 1 of the attributes structure. We
50 may have to change this as more fields are added to the structure */
51 return &g_default_cq_factory;
52}
53
Sree Kuchibhotla2abbf8a2017-03-21 17:31:03 -070054/*
55 * == Completion queue creation APIs ==
56 */
57
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070058grpc_completion_queue* grpc_completion_queue_create_for_next(void* reserved) {
59 GPR_ASSERT(!reserved);
60 grpc_completion_queue_attributes attr = {1, GRPC_CQ_NEXT,
61 GRPC_CQ_DEFAULT_POLLING};
62 return g_default_cq_factory.vtable->create(&g_default_cq_factory, &attr);
63}
64
65grpc_completion_queue* grpc_completion_queue_create_for_pluck(void* reserved) {
66 GPR_ASSERT(!reserved);
Sree Kuchibhotlab5b6bfd2017-03-22 02:32:01 -070067 grpc_completion_queue_attributes attr = {1, GRPC_CQ_PLUCK,
Sree Kuchibhotlabf184282017-03-21 15:18:58 -070068 GRPC_CQ_DEFAULT_POLLING};
69 return g_default_cq_factory.vtable->create(&g_default_cq_factory, &attr);
70}
Sree Kuchibhotla2abbf8a2017-03-21 17:31:03 -070071
72grpc_completion_queue* grpc_completion_queue_create(
73 const grpc_completion_queue_factory* factory,
74 const grpc_completion_queue_attributes* attr, void* reserved) {
75 GPR_ASSERT(!reserved);
76 return factory->vtable->create(factory, attr);
77}