3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPC_CORE_LIB_TRANSPORT_CONNECTIVITY_STATE_H
20 #define GRPC_CORE_LIB_TRANSPORT_CONNECTIVITY_STATE_H
22 #include <grpc/support/port_platform.h>
24 #include <grpc/grpc.h>
25 #include "src/core/lib/debug/trace.h"
26 #include "src/core/lib/iomgr/closure.h"
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 */
33 /** the current state as believed by the watcher */
34 grpc_connectivity_state* current;
35 } grpc_connectivity_state_watcher;
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 */
44 } grpc_connectivity_state_tracker;
46 extern grpc_core::TraceFlag grpc_connectivity_state_trace;
48 /** enum --> string conversion */
49 const char* grpc_connectivity_state_name(grpc_connectivity_state state);
51 void grpc_connectivity_state_init(grpc_connectivity_state_tracker* tracker,
52 grpc_connectivity_state init_state,
54 void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker);
56 /** Set connectivity state; not thread safe; access must be serialized with an
58 void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker,
59 grpc_connectivity_state state,
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);
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);
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
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);
79 #endif /* GRPC_CORE_LIB_TRANSPORT_CONNECTIVITY_STATE_H */