22
33#include < string.h>
44
5+ std::mutex g_mutex;
6+
57service_method_table_t g_services;
6- bool g_initialized = false ;
8+ bool g_apiInitialized = false ;
79
810swss::DBConnector *g_db = NULL ;
911swss::DBConnector *g_dbNtf = NULL ;
1012swss::ProducerTable *g_asicState = NULL ;
1113
1214// we probably don't need those to tables to access GET requests
15+ swss::ProducerTable *g_notifySyncdProducer = NULL ;
1316swss::ProducerTable *g_redisGetProducer = NULL ;
1417swss::ConsumerTable *g_redisGetConsumer = NULL ;
1518swss::ConsumerTable *g_redisNotifications = NULL ;
19+ swss::ConsumerTable *g_notifySyncdConsumer = NULL ;
1620
1721swss::RedisClient *g_redisClient = NULL ;
1822
1923sai_status_t sai_api_initialize (
2024 _In_ uint64_t flags,
2125 _In_ const service_method_table_t * services)
2226{
27+ std::lock_guard<std::mutex> lock (g_mutex);
28+
2329 SWSS_LOG_ENTER ();
2430
2531 if ((NULL == services) || (NULL == services->profile_get_next_value ) || (NULL == services->profile_get_value ))
2632 {
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" );
2834 return SAI_STATUS_INVALID_PARAMETER;
2935 }
3036
3137 memcpy (&g_services, services, sizeof (g_services));
3238
3339 if (0 != flags)
3440 {
35- SWSS_LOG_ERROR (" Invalid flags passed to SAI API initialize\n " );
41+ SWSS_LOG_ERROR (" Invalid flags passed to SAI API initialize" );
3642 return SAI_STATUS_INVALID_PARAMETER;
3743 }
3844
@@ -51,11 +57,21 @@ sai_status_t sai_api_initialize(
5157
5258 g_asicState = new swss::ProducerTable (g_db, " ASIC_STATE" );
5359
60+ if (g_notifySyncdProducer != NULL )
61+ delete g_notifySyncdProducer;
62+
63+ g_notifySyncdProducer = new swss::ProducerTable (g_db, " NOTIFYSYNCDREQUERY" );
64+
5465 if (g_redisGetProducer != NULL )
5566 delete g_redisGetProducer;
5667
5768 g_redisGetProducer = new swss::ProducerTable (g_db, " GETREQUEST" );
5869
70+ if (g_notifySyncdConsumer != NULL )
71+ delete g_notifySyncdConsumer;
72+
73+ g_notifySyncdConsumer = new swss::ConsumerTable (g_db, " NOTIFYSYNCRESPONSE" );
74+
5975 if (g_redisGetConsumer != NULL )
6076 delete g_redisGetConsumer;
6177
@@ -71,15 +87,17 @@ sai_status_t sai_api_initialize(
7187
7288 g_redisClient = new swss::RedisClient (g_db);
7389
74- g_initialized = true ;
90+ g_apiInitialized = true ;
7591
7692 return SAI_STATUS_SUCCESS;
7793}
7894
7995sai_status_t sai_log_set (
80- _In_ sai_api_t sai_api_id,
96+ _In_ sai_api_t sai_api_id,
8197 _In_ sai_log_level_t log_level)
8298{
99+ std::lock_guard<std::mutex> lock (g_mutex);
100+
83101 SWSS_LOG_ENTER ();
84102
85103 switch (log_level)
@@ -103,11 +121,11 @@ sai_status_t sai_log_set(
103121 break ;
104122
105123 default :
106- SWSS_LOG_ERROR (" Invalid log level %d\n " , log_level);
124+ SWSS_LOG_ERROR (" Invalid log level %d" , log_level);
107125 return SAI_STATUS_INVALID_PARAMETER;
108126 }
109127
110- switch (sai_api_id)
128+ switch (sai_api_id)
111129 {
112130 case SAI_API_SWITCH:
113131 break ;
@@ -158,28 +176,30 @@ sai_status_t sai_log_set(
158176 break ;
159177
160178 default :
161- SWSS_LOG_ERROR (" Invalid API type %d\n " , sai_api_id);
179+ SWSS_LOG_ERROR (" Invalid API type %d" , sai_api_id);
162180 return SAI_STATUS_INVALID_PARAMETER;
163181 }
164182
165183 return SAI_STATUS_SUCCESS;
166184}
167185
168186sai_status_t sai_api_query (
169- _In_ sai_api_t sai_api_id,
187+ _In_ sai_api_t sai_api_id,
170188 _Out_ void ** api_method_table)
171189{
190+ std::lock_guard<std::mutex> lock (g_mutex);
191+
172192 SWSS_LOG_ENTER ();
173193
174- if (NULL == api_method_table)
194+ if (NULL == api_method_table)
175195 {
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" );
177197 return SAI_STATUS_INVALID_PARAMETER;
178198 }
179199
180- if (!g_initialized)
200+ if (!g_apiInitialized)
181201 {
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" );
183203 return SAI_STATUS_UNINITIALIZED;
184204 }
185205
@@ -285,8 +305,20 @@ sai_status_t sai_api_query(
285305 return SAI_STATUS_SUCCESS;
286306
287307 default :
288- SWSS_LOG_ERROR (" Invalid API type %d\n " , sai_api_id);
308+ SWSS_LOG_ERROR (" Invalid API type %d" , sai_api_id);
289309 return SAI_STATUS_INVALID_PARAMETER;
290310 }
291311}
292312
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