public:
Service();
Service(string, string, string, string, string);
- static Result_Base *Resulturi;
Result_Base *Resultdevice;
position findServiceValue(string, char *);
static void getByURI(string, Result_Base*);
static void getByURI(string, long, Result_Base *result);
static void getById(string id, Result_Base *result);
- static int curl_service_calling(string uri, long, void *);
+ static int curl_service_calling(string uri, long, void *, Result_Base *);
//static Search *search();
static size_t createdata(char *buf, size_t size, size_t nmemb, void *up);
- static void createdata_process(string data, void *);
- static int json_parse_service(const char *in, void *);
+ static void createdata_process(string data, void *, Result_Base *);
+ static int json_parse_service(const char *in, void *, Result_Base *);
static Service create(ServiceInfo);
static Service create(map<string, string>);
Channel *createChannel(string uri);
string Service::TYPE_PROPERTY = "md";
string Service::ENDPOINT_PROPERTY = "se";
-Result_Base *Service::Resulturi = NULL;
-
Service Service::local_service;
bool Service::success_get_id = false;
void Service::getDeviceInfo(Result_Base *dev_result)
{
- curl_service_calling(uri, 5000, dev_result);
+ curl_service_calling(uri, 5000, dev_result, NULL);
}
string Service::getUniqueId(string address)
GetLocalServiceCallback r1Service;
string remote_uri = "http://" + address + "/api/v2/";
success_get_id = false;
+ MSF_DBG("calling getByUri");
getByURI(remote_uri, 5000, &r1Service);
+ MSF_DBG("called getByUri");
if (success_get_id) {
MSF_DBG("remote_device_id[%s] for address[%s]", remote_device_id.c_str(), address.c_str());
{
MSF_DBG("getByURI() uri = %s", uri.c_str());
- Resulturi = result;
+ MSF_DBG("calling curl_service_calling");
//Resultdevice = NULL;
- curl_service_calling(uri, timeout, NULL);
- Resulturi = NULL;
+ curl_service_calling(uri, timeout, NULL, result);
+ MSF_DBG("called curl_service_calling");
+ MSF_DBG("getByURI end");
}
-int Service::curl_service_calling(string uri, long timeout, void *dev_result_ptr)
+int Service::curl_service_calling(string uri, long timeout, void *dev_result_ptr, Result_Base *result)
{
+ MSF_DBG("curl_service_calling start");
CURL *curl;
CURLcode res;
struct curl_slist *headers = NULL;
if ((res != CURLE_OK) || (read_data == NULL)) {
MSF_DBG("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
- createdata_process("", dev_result_ptr);
+ createdata_process("", dev_result_ptr, result);
if (read_data) {
free(read_data);
}
} else {
- createdata_process(string(read_data), dev_result_ptr);
+ MSF_DBG("calling createdata_process");
+ createdata_process(string(read_data), dev_result_ptr, result);
free(read_data);
}
curl_easy_cleanup(curl);
}
-
+ MSF_DBG("curl_service_calling end");
return 0;
}
return size*nmemb;
}
-void Service::createdata_process(string data, void *dev_result_ptr)
+void Service::createdata_process(string data, void *dev_result_ptr, Result_Base* result)
{
if (data.length() != 0) {
- json_parse_service(data.c_str(), dev_result_ptr);
+ json_parse_service(data.c_str(), dev_result_ptr, result);
} else {
- if (Resulturi != NULL) {
- Resulturi->onError(Error::create("Timeout"));
+ if (result != NULL) {
+ result->onError(Error::create("Timeout"));
}
if (dev_result_ptr != NULL) {
(static_cast<Result_Base*> (dev_result_ptr))->onError(Error::create("Not Found"));
}
}
-int Service::json_parse_service(const char *in, void *ptr)
+int Service::json_parse_service(const char *in, void *ptr, Result_Base* result)
{
+ MSF_DBG("json_parse_service start");
JsonParser *parser = json_parser_new();
if (json_parser_load_from_data(parser, in, -1, NULL)) {
retService.SecureConnectionSupport = true;
}
- if ((Resulturi!= NULL)) {
- Resulturi->onSuccess(retService);
+ if ((result != NULL)) {
+ MSF_DBG("json_parse_service");
+ result->onSuccess(retService);
}
+ MSF_DBG("json_parse_service end");
+
return 0;
}