Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc / deps / grpc / src / core / lib / transport / connectivity_state.h
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_LIB_TRANSPORT_CONNECTIVITY_STATE_H
20 #define GRPC_CORE_LIB_TRANSPORT_CONNECTIVITY_STATE_H
21
22 #include <grpc/support/port_platform.h>
23
24 #include <grpc/grpc.h>
25 #include "src/core/lib/debug/trace.h"
26 #include "src/core/lib/iomgr/closure.h"
27
28 typedef struct grpc_connectivity_state_watcher {
29   /** we keep watchers in a linked list */
30   struct grpc_connectivity_state_watcher* next;
31   /** closure to notify on change */
32   grpc_closure* notify;
33   /** the current state as believed by the watcher */
34   grpc_connectivity_state* current;
35 } grpc_connectivity_state_watcher;
36
37 typedef struct {
38   /** current grpc_connectivity_state */
39   gpr_atm current_state_atm;
40   /** all our watchers */
41   grpc_connectivity_state_watcher* watchers;
42   /** a name to help debugging */
43   char* name;
44 } grpc_connectivity_state_tracker;
45
46 extern grpc_core::TraceFlag grpc_connectivity_state_trace;
47
48 /** enum --> string conversion */
49 const char* grpc_connectivity_state_name(grpc_connectivity_state state);
50
51 void grpc_connectivity_state_init(grpc_connectivity_state_tracker* tracker,
52                                   grpc_connectivity_state init_state,
53                                   const char* name);
54 void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker);
55
56 /** Set connectivity state; not thread safe; access must be serialized with an
57  *  external lock */
58 void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker,
59                                  grpc_connectivity_state state,
60                                  const char* reason);
61
62 /** Return true if this connectivity state has watchers.
63     Access must be serialized with an external lock. */
64 bool grpc_connectivity_state_has_watchers(
65     grpc_connectivity_state_tracker* tracker);
66
67 /** Return the last seen connectivity state. No need to synchronize access. */
68 grpc_connectivity_state grpc_connectivity_state_check(
69     grpc_connectivity_state_tracker* tracker);
70
71 /** Return 1 if the channel should start connecting, 0 otherwise.
72     If current==NULL cancel notify if it is already queued (success==0 in that
73     case).
74     Access must be serialized with an external lock. */
75 bool grpc_connectivity_state_notify_on_state_change(
76     grpc_connectivity_state_tracker* tracker, grpc_connectivity_state* current,
77     grpc_closure* notify);
78
79 #endif /* GRPC_CORE_LIB_TRANSPORT_CONNECTIVITY_STATE_H */