+ STG_RESULT result = {NULL, NULL};
+ return result;
+}
+
+std::string toString(const char* value)
+{
+ if (value == NULL)
+ return "";
+ else
+ return value;
+}
+
+STG_RESULT stgRequest(STG_CLIENT::TYPE type, const char* userName, const char* password, const STG_PAIR* pairs)
+{
+ STG_CLIENT* client = STG_CLIENT::get();
+ if (client == NULL) {
+ RadLog("Client is not configured.");
+ return emptyResult();
+ }
+ try {
+ if (!client->connected())
+ {
+ if (!STG_CLIENT::reconnect())
+ return emptyResult();
+ client = STG_CLIENT::get();
+ }
+ response.done = false;
+ client->request(type, toString(userName), toString(password), fromSTGPairs(pairs));
+ pthread_mutex_lock(&response.mutex);
+ timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ ts.tv_sec += 5;
+ int res = 0;
+ while (!response.done && res == 0)
+ res = pthread_cond_timedwait(&response.cond, &response.mutex, &ts);
+ pthread_mutex_unlock(&response.mutex);
+ if (res != 0 || !response.status)
+ return emptyResult();
+ return toResult(response.result);
+ } catch (const STG_CLIENT::Error& ex) {
+ RadLog("Error: '%s'.", ex.what());
+ return emptyResult();
+ }
+}
+
+}
+
+int stgInstantiateImpl(const char* address)
+{
+ pthread_mutex_init(&response.mutex, NULL);
+ pthread_cond_init(&response.cond, NULL);
+ response.done = false;
+
+ if (STG_CLIENT::configure(toString(address), &Response::callback, &response))
+ return 1;
+
+ return 0;