Home | History | Annotate | Download | only in client_channel
      1 /*
      2  *
      3  * Copyright 2015 gRPC authors.
      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 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CLIENT_CHANNEL_FACTORY_H
     20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CLIENT_CHANNEL_FACTORY_H
     21 
     22 #include <grpc/support/port_platform.h>
     23 
     24 #include <grpc/impl/codegen/grpc_types.h>
     25 
     26 #include "src/core/ext/filters/client_channel/subchannel.h"
     27 #include "src/core/lib/channel/channel_stack.h"
     28 
     29 // Channel arg key for client channel factory.
     30 #define GRPC_ARG_CLIENT_CHANNEL_FACTORY "grpc.client_channel_factory"
     31 
     32 typedef struct grpc_client_channel_factory grpc_client_channel_factory;
     33 typedef struct grpc_client_channel_factory_vtable
     34     grpc_client_channel_factory_vtable;
     35 
     36 typedef enum {
     37   GRPC_CLIENT_CHANNEL_TYPE_REGULAR, /** for the user-level regular calls */
     38   GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, /** for communication with a load
     39                                               balancing service */
     40 } grpc_client_channel_type;
     41 
     42 /** Constructor for new configured channels.
     43     Creating decorators around this type is encouraged to adapt behavior. */
     44 struct grpc_client_channel_factory {
     45   const grpc_client_channel_factory_vtable* vtable;
     46 };
     47 
     48 struct grpc_client_channel_factory_vtable {
     49   void (*ref)(grpc_client_channel_factory* factory);
     50   void (*unref)(grpc_client_channel_factory* factory);
     51   grpc_subchannel* (*create_subchannel)(grpc_client_channel_factory* factory,
     52                                         const grpc_subchannel_args* args);
     53   grpc_channel* (*create_client_channel)(grpc_client_channel_factory* factory,
     54                                          const char* target,
     55                                          grpc_client_channel_type type,
     56                                          const grpc_channel_args* args);
     57 };
     58 
     59 void grpc_client_channel_factory_ref(grpc_client_channel_factory* factory);
     60 void grpc_client_channel_factory_unref(grpc_client_channel_factory* factory);
     61 
     62 /** Create a new grpc_subchannel */
     63 grpc_subchannel* grpc_client_channel_factory_create_subchannel(
     64     grpc_client_channel_factory* factory, const grpc_subchannel_args* args);
     65 
     66 /** Create a new grpc_channel */
     67 grpc_channel* grpc_client_channel_factory_create_channel(
     68     grpc_client_channel_factory* factory, const char* target,
     69     grpc_client_channel_type type, const grpc_channel_args* args);
     70 
     71 grpc_arg grpc_client_channel_factory_create_channel_arg(
     72     grpc_client_channel_factory* factory);
     73 
     74 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CLIENT_CHANNEL_FACTORY_H */
     75