Languages

Menu
Sites
Language
Ecore_Timer cyclic recall libxml Parser - wearable Gear S3 Tizen 2.3.2

Hello everyone,

how is it possible to parse a XML file cyclical with the libxml Parser in a service App ( app for wearable, Gear S3 with Tizen 2.3.2)?

The service app shall cyclical parse an xml file and inform the user if the content of the xml file has changed.

I know that ecore_timer_add function can be used to invoke functions cyclical, but this only works if the function to be called by the ecore_timer is an Eina_Bool function.

I also know that the alarm API can be used to launch an application, e.g. I could set an Alarm in the UI-application to launch the service app frequently. 

But both of these options couldn´t help me so far, because:

1. If the service gets constantly new launched, all data is lost, and I can´t compare if the information from the XML file changed from the previous File parsing. 

2.  And the libxml Parser is a void function, so I can´t think of a possibility to use Ecore_Timer

void getParsedData(xmlNode * a_node, appdata_s *ad) {
	xmlNode *cur_node = NULL;
	xmlChar *value = NULL;
	for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
		if (!strcmp((const char*) cur_node->name, "tag"))
			ad->value_type = 1;
		if (!strcmp((const char*) cur_node->name, "price"))
			ad->value_type = 2;
		if (!strcmp((const char*) cur_node->name, "text")) {
			if (ad->value_type == 1) {
				value = cur_node->content;
				strcat(ad->buffer, "Name : ");
				strcat(ad->buffer, (char*) value);
				strcat(ad->buffer, "<br/>");
				dlog_print(DLOG_DEBUG, "GG", "%s\n", ad->buffer);
				ad->value_type = 0;
			} else if (ad->value_type == 2) {
				value = cur_node->content;
				strcat(ad->buffer, "  Price : ");
				strcat(ad->buffer, (char*) value);
				strcat(ad->buffer, "<br/>");
				ad->value_type = 0;
			}
			
		}
		getParsedData(cur_node->children, ad);
	}
}

 

 

 

Responses

5 Replies
GEUNSOO KIM

Well...

Let me correct on your assumptions first..

1. calling an app using app control doesn't mean that the app will launch newly always.

2. Ecore_Timer wants that the task callback return a boolean value to decide killing the timer or not. So you don't need to consider the return value of libxml. just return true if you want keep the timer.

 

And in my opinion, I think you'd better use alarm, because Samsung wearable devices can get into sleep mode even if you set timer unless you lock the cpu power.  So there is no guarrenty to wake up the device at your need if you use ecore_timer only.

If you get service app is launching newly, try the followings.

1. check bold part on your manifest file

<service-application appid="xxx.yyy.your_app" exec="/usr/apps/xxx.yyy.your_app/bin/your_app"
                        nodisplay="true" multiple="false" type="capp" taskmanage="false">

2. try operation APP_CONTROL_OPERATION_MAIN instead of APP_CONTROL_OPERATION_DEFAULT. or vice versa.

good luck.

 

wally

Thank you for your help!

I tried both options, but so far I couldn´t get it work.

With Ecore_Timer: But how can I call the get_Parsed_Data function with the Ecore_Timer ?  eg. ecore_timer_add(20, get_Parsed_Data, NULL).  Because a void function can´t return true?

I am able to call the Parser and the file location (see code) with the Timer, but then the get_Parsed_Data function call within the Eina_Bool parsdoc cb function can´t be executed, and results in dead_app_pid Error messages. 

Eina_Bool parsdoc (void *data EINA_UNUSED){
 appdata_s *ad;
 xmlDoc *doc = NULL;
 xmlNode *root_element = NULL;
 char *loc = "http://www.test.com/test.xml";
 doc = xmlReadFile(loc, NULL, 0);

 if (doc == NULL) {
    dlog_print(DLOG_ERROR, LOG_TAG, "error: could not parse file.");
	 }
root_element = xmlDocGetRootElement(doc);

/*Parsing */
		ad->buffer[0] = '\0';
		ad->value_type = 0;

getParsedData(root_element, ad);

			xmlFreeDoc(doc);
			xmlCleanupParser();

		return  ECORE_CALLBACK_RENEW;
}

 

2. Launch on Alarm:  Where can I define APP_CONTROL_OPERATION_MAIN for the launch on alarm?  Could you give an example? 

GEUNSOO KIM

1. I have corrected your code.

when you register timer,

Ecore_Timer myTimer = ecore_timer_add(20, parsdoc, ad);

and the definition of parsdoc()

Eina_Bool parsdoc (void *data)
{
    appdata_s *ad = (appdata_s *) data;
    
    if (!ad) {
        dlog_print(DLOG_ERROR, LOG_TAG, "error: ad is NULL.");
        // exit this time slot
        return  ECORE_CALLBACK_RENEW;
    }
    
    xmlDoc *doc = NULL;
    xmlNode *root_element = NULL;
    char *loc = "http://www.test.com/test.xml";
    
    doc = xmlReadFile(loc, NULL, 0);

    if (doc == NULL) {
        dlog_print(DLOG_ERROR, LOG_TAG, "error: could not parse file.");
        // exit this time slot
        return  ECORE_CALLBACK_RENEW;
    }
    
    root_element = xmlDocGetRootElement(doc);

    /*Parsing */
    ad->buffer[0] = '\0';
    ad->value_type = 0;

    getParsedData(root_element, ad);

    xmlFreeDoc(doc);
    xmlCleanupParser();

    return  ECORE_CALLBACK_RENEW;
}

 

2. APP_CONTROL_OPERATION_MAIN is pre-defined operation in tizen. so you don't need to define it again. refer the following link to implement alarm scheduling.

https://developer.tizen.org/development/guides/native-application/alarm-and-scheduling/alarm

wally

Thank you very much for your help and correction! Now it works.