2
2
3
3
#include < string.h>
4
4
5
+ std::mutex g_mutex;
6
+
5
7
service_method_table_t g_services;
6
- bool g_initialized = false ;
8
+ bool g_apiInitialized = false ;
7
9
8
10
swss::DBConnector *g_db = NULL ;
9
11
swss::DBConnector *g_dbNtf = NULL ;
10
12
swss::ProducerTable *g_asicState = NULL ;
11
13
12
14
// we probably don't need those to tables to access GET requests
15
+ swss::ProducerTable *g_notifySyncdProducer = NULL ;
13
16
swss::ProducerTable *g_redisGetProducer = NULL ;
14
17
swss::ConsumerTable *g_redisGetConsumer = NULL ;
15
18
swss::ConsumerTable *g_redisNotifications = NULL ;
19
+ swss::ConsumerTable *g_notifySyncdConsumer = NULL ;
16
20
17
21
swss::RedisClient *g_redisClient = NULL ;
18
22
19
23
sai_status_t sai_api_initialize (
20
24
_In_ uint64_t flags,
21
25
_In_ const service_method_table_t * services)
22
26
{
27
+ std::lock_guard<std::mutex> lock (g_mutex);
28
+
23
29
SWSS_LOG_ENTER ();
24
30
25
31
if ((NULL == services) || (NULL == services->profile_get_next_value ) || (NULL == services->profile_get_value ))
26
32
{
27
- SWSS_LOG_ERROR (" Invalid services handle passed to SAI API initialize\n " );
33
+ SWSS_LOG_ERROR (" Invalid services handle passed to SAI API initialize" );
28
34
return SAI_STATUS_INVALID_PARAMETER;
29
35
}
30
36
31
37
memcpy (&g_services, services, sizeof (g_services));
32
38
33
39
if (0 != flags)
34
40
{
35
- SWSS_LOG_ERROR (" Invalid flags passed to SAI API initialize\n " );
41
+ SWSS_LOG_ERROR (" Invalid flags passed to SAI API initialize" );
36
42
return SAI_STATUS_INVALID_PARAMETER;
37
43
}
38
44
@@ -51,11 +57,21 @@ sai_status_t sai_api_initialize(
51
57
52
58
g_asicState = new swss::ProducerTable (g_db, " ASIC_STATE" );
53
59
60
+ if (g_notifySyncdProducer != NULL )
61
+ delete g_notifySyncdProducer;
62
+
63
+ g_notifySyncdProducer = new swss::ProducerTable (g_db, " NOTIFYSYNCDREQUERY" );
64
+
54
65
if (g_redisGetProducer != NULL )
55
66
delete g_redisGetProducer;
56
67
57
68
g_redisGetProducer = new swss::ProducerTable (g_db, " GETREQUEST" );
58
69
70
+ if (g_notifySyncdConsumer != NULL )
71
+ delete g_notifySyncdConsumer;
72
+
73
+ g_notifySyncdConsumer = new swss::ConsumerTable (g_db, " NOTIFYSYNCRESPONSE" );
74
+
59
75
if (g_redisGetConsumer != NULL )
60
76
delete g_redisGetConsumer;
61
77
@@ -71,15 +87,17 @@ sai_status_t sai_api_initialize(
71
87
72
88
g_redisClient = new swss::RedisClient (g_db);
73
89
74
- g_initialized = true ;
90
+ g_apiInitialized = true ;
75
91
76
92
return SAI_STATUS_SUCCESS;
77
93
}
78
94
79
95
sai_status_t sai_log_set (
80
- _In_ sai_api_t sai_api_id,
96
+ _In_ sai_api_t sai_api_id,
81
97
_In_ sai_log_level_t log_level)
82
98
{
99
+ std::lock_guard<std::mutex> lock (g_mutex);
100
+
83
101
SWSS_LOG_ENTER ();
84
102
85
103
switch (log_level)
@@ -103,11 +121,11 @@ sai_status_t sai_log_set(
103
121
break ;
104
122
105
123
default :
106
- SWSS_LOG_ERROR (" Invalid log level %d\n " , log_level);
124
+ SWSS_LOG_ERROR (" Invalid log level %d" , log_level);
107
125
return SAI_STATUS_INVALID_PARAMETER;
108
126
}
109
127
110
- switch (sai_api_id)
128
+ switch (sai_api_id)
111
129
{
112
130
case SAI_API_SWITCH:
113
131
break ;
@@ -158,28 +176,30 @@ sai_status_t sai_log_set(
158
176
break ;
159
177
160
178
default :
161
- SWSS_LOG_ERROR (" Invalid API type %d\n " , sai_api_id);
179
+ SWSS_LOG_ERROR (" Invalid API type %d" , sai_api_id);
162
180
return SAI_STATUS_INVALID_PARAMETER;
163
181
}
164
182
165
183
return SAI_STATUS_SUCCESS;
166
184
}
167
185
168
186
sai_status_t sai_api_query (
169
- _In_ sai_api_t sai_api_id,
187
+ _In_ sai_api_t sai_api_id,
170
188
_Out_ void ** api_method_table)
171
189
{
190
+ std::lock_guard<std::mutex> lock (g_mutex);
191
+
172
192
SWSS_LOG_ENTER ();
173
193
174
- if (NULL == api_method_table)
194
+ if (NULL == api_method_table)
175
195
{
176
- SWSS_LOG_ERROR (" NULL method table passed to SAI API initialize\n " );
196
+ SWSS_LOG_ERROR (" NULL method table passed to SAI API initialize" );
177
197
return SAI_STATUS_INVALID_PARAMETER;
178
198
}
179
199
180
- if (!g_initialized)
200
+ if (!g_apiInitialized)
181
201
{
182
- SWSS_LOG_ERROR (" SAI API not initialized before calling API query\n " );
202
+ SWSS_LOG_ERROR (" SAI API not initialized before calling API query" );
183
203
return SAI_STATUS_UNINITIALIZED;
184
204
}
185
205
@@ -285,8 +305,20 @@ sai_status_t sai_api_query(
285
305
return SAI_STATUS_SUCCESS;
286
306
287
307
default :
288
- SWSS_LOG_ERROR (" Invalid API type %d\n " , sai_api_id);
308
+ SWSS_LOG_ERROR (" Invalid API type %d" , sai_api_id);
289
309
return SAI_STATUS_INVALID_PARAMETER;
290
310
}
291
311
}
292
312
313
+ sai_status_t sai_api_uninitialize (void )
314
+ {
315
+ std::lock_guard<std::mutex> lock (g_mutex);
316
+
317
+ SWSS_LOG_ENTER ();
318
+
319
+ g_apiInitialized = false ;
320
+
321
+ SWSS_LOG_ERROR (" not implemented" );
322
+
323
+ return SAI_STATUS_NOT_IMPLEMENTED;
324
+ }
0 commit comments