Can I start a new task in a CGI callback function?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can I start a new task in a CGI callback function?

972 Views
danielchai
Senior Contributor I

Hi All,

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?

Thank you.

0 Kudos
Reply
3 Replies

637 Views
soledad
NXP Employee
NXP Employee

Hi Daniel,

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)

{

  TIME_STRUCT time;

  int min, hour;

  

  _time_get(&time);

  

  min = time.SECONDS / 60;

  hour = min / 60;

  min %= 60;

  

session->response.contenttype = CONTENT_TYPE_PLAIN;

  httpd_sendhdr(session, 0, 0);

  

  CGI_SEND_NUM(hour);

  CGI_SEND_NUM(min);

  CGI_SEND_NUM(time.SECONDS % 60);

  return session->request.content_len;

}

Regards

Sol

0 Kudos
Reply

637 Views
danielchai
Senior Contributor I

Hi Sol,

Thank you for your reply.

The question is that in this callback function, can I have call function _task_create to start a task?

Thanks.

-Daniel

0 Kudos
Reply

637 Views
pbanta
Contributor IV

Hi Daniel,

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)..

Best regards,

Paul

0 Kudos
Reply