2 # Copyright (c) 2016 Cisco and/or its affiliates.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 # Module storing all global variables, shared between main module and plugins
24 waiting_for_reply = False
27 class ContextId(object):
30 def __call__(self, id):
33 get_context = ContextId()
35 def waiting_for_reply_clear():
36 global waiting_for_reply
37 waiting_for_reply = False
39 def waiting_for_reply_set():
40 global waiting_for_reply
41 waiting_for_reply = True
43 def is_waiting_for_reply():
44 return waiting_for_reply
46 def event_callback_set(callback):
48 event_callback = callback
50 def event_callback_call(r):
54 def results_event_set(context):
55 results[context]['e'].set()
57 def results_event_clear(context):
58 results[context]['e'].clear()
60 def results_event_wait(context, timeout):
61 results[context]['e'].wait(timeout)
63 def results_set(context, r):
64 results[context]['r'] = r
66 def results_append(context, r):
67 results[context]['r'].append(r)
69 def is_results_context(context):
70 return context in results
72 def is_results_more(context):
73 return 'm' in results[context]
75 def results_more_set(context):
76 results[context]['m'] = True
78 def results_prepare(context):
80 results[context]['e'] = threading.Event()
81 results[context]['e'].clear()
82 results[context]['r'] = []
84 def results_get(context):
85 return results[context]['r']
87 def plugin_register(name, func_table, name_to_id_table, version, msg_id_base_set):
90 p['func_table'] = func_table
91 p['name_to_id_table'] = name_to_id_table
92 p['version'] = version
93 p['msg_id_base_set'] = msg_id_base_set