blob: a1ef87a3f0a26d4185ca83af7fac663aefc139f7 [file] [log] [blame]
Ole Troan5f9dcff2016-08-01 04:59:13 +02001#
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:
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
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.
14
15#
16# Module storing all global variables, shared between main module and plugins
17#
18import threading
19
20#
21# Global variables
22#
23results = {}
24waiting_for_reply = False
25plugins = {}
26
27class ContextId(object):
28 def __init__(self):
29 self.context = 0
30 def __call__(self, id):
31 self.context += 1
32 return self.context
33get_context = ContextId()
34
35def waiting_for_reply_clear():
36 global waiting_for_reply
37 waiting_for_reply = False
38
39def waiting_for_reply_set():
40 global waiting_for_reply
41 waiting_for_reply = True
42
43def is_waiting_for_reply():
44 return waiting_for_reply
45
46def event_callback_set(callback):
47 global event_callback
48 event_callback = callback
49
50def event_callback_call(r):
51 global event_callback
52 event_callback(r)
53
54def results_event_set(context):
55 results[context]['e'].set()
56
57def results_event_clear(context):
58 results[context]['e'].clear()
59
60def results_event_wait(context, timeout):
61 results[context]['e'].wait(timeout)
62
63def results_set(context, r):
64 results[context]['r'] = r
65
66def results_append(context, r):
67 results[context]['r'].append(r)
68
69def is_results_context(context):
70 return context in results
71
72def is_results_more(context):
73 return 'm' in results[context]
74
75def results_more_set(context):
76 results[context]['m'] = True
77
78def results_prepare(context):
79 results[context] = {}
80 results[context]['e'] = threading.Event()
81 results[context]['e'].clear()
82 results[context]['r'] = []
83
84def results_get(context):
85 return results[context]['r']
86
87def plugin_register(name, func_table, name_to_id_table, version, msg_id_base_set):
88 plugins[name] = {}
89 p = plugins[name]
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
94
95def plugin_show():
96 for p in plugins:
97 print(p)