Now I have a http server task, and is it possible to start a task in CGI callback function when I get a http request from the client?
For a cgi, application callback functions are define in HTTPD_CGI_LINK_STRUCT.
So when requested a cgi web page, the RTCS library calls the cgi_ callback function linked to this web page by the HTTPD_CGI_LINK_STRUCT.
From the cgi callback function, we can request the RTCS to send a header. An example for this in MQX 4.0, in /rtcs/examples/httpsrv/cgi.c, cgi callback functions should look like this:
static _mqx_int cgi_rtc_data(HTTPD_SESSION_STRUCT *session)
int min, hour;
min = time.SECONDS / 60;
hour = min / 60;
min %= 60;
session->response.contenttype = CONTENT_TYPE_PLAIN;
httpd_sendhdr(session, 0, 0);
CGI_SEND_NUM(time.SECONDS % 60);
Thank you for your reply.
The question is that in this callback function, can I have call function _task_create to start a task?
Apologies for a late reply, but I have done this. I just made sure the task I was creating was in my MQX_template_list and that is was not MQX_AUTO_START_TASK. You need take care with the priority of the new task so that it doesn't consume the CPU and prevent the CGI callback from returning. In my case, I passed a delay parameter to the new task. The first function call in the new task was _time_delay_ticks(param)..
Retrieving data ...