Hi All
Here is a note to say that some additional support for generation of dynamic web content (eg. HTML and Java script) is being added to the HTTP interface.
There is a new demo of this on-line at
http://demo.uTasker.com which includes this. Take a look at the statistic page which has been replaced by a side which can generate a muliplication table with user defined number of rows and columns. The interface allows multiple users to generate tables of various sizes at the same time.
This is not a PHP (or similar) server built into the uTasker project but it does allow user code to generate such things without having to get involved with the details of HTTP or TCP. The user code simply has a reference to a 'chunk' of content to be generated. This starts at number 1 and continues counting until the user decides that there is no more work to do. The user code doesn't need to know details about how much space is available in the present TCP frame being constructed or whether it is a repeat due to a previous TCP timeout.
The user code can be inserted into
fnInsertString() and the code used to generate the on-line multiplication table is below as reference. This support is being further tested and will certainly be included in future service pack releases:
if (ptrBuffer == 0) { // special case when session is terminating. This is used to clear any session specific data and onl yoccurs when there is a valid user data pointer
uMemset(http_session->ptrUserData, 0, sizeof(MULTIPLICATION_TABLE)); // clear content
return 0;
}
if (*ptrBuffer == '0') {
MULTIPLICATION_TABLE *ptrMulTable;
unsigned short usChunk = (usTxLength - 1);
unsigned short usX, usY;
if (http_session->ptrUserData == 0) {
http_session->ucDymamicFlags = NO_DYNAMIC_CONTENT_TO_ADD;// inform that we don't want to generate anything this time
*usLengthToSend = 0;
return cValue; // user session unknown so don't generate anything. This occurs when the window is first opened
}
ptrMulTable = (MULTIPLICATION_TABLE *)http_session->ptrUserData;
if (usTxLength > (ptrMulTable->ucColumns * ptrMulTable->usRows)) {
if (ptrMulTable->ucColumns == 0) { // no valid input data
http_session->ucDymamicFlags = NO_DYNAMIC_CONTENT_TO_ADD;// inform that we don't want to generate anything this time
*usLengthToSend = 0;
return cValue;
}
return 0; // complete table content generated
}
usX = (usChunk%ptrMulTable->ucColumns);
usY = ((usChunk/ptrMulTable->ucColumns) + 1);
if (usX == 0) {
if (usY == 1) {
cPtr = (uStrcpy(cValue, "<tr style=""background-color:white""><th width=""60"">") - 1); // start a new table row
}
else {
cPtr = (uStrcpy(cValue, "<tr><th style=""background-color:white"" width=""60"">") - 1); // start a new table row
}
}
else {
cPtr = (uStrcpy(cValue, "<th width=""60"">") - 1); // start a new column
usY *= (usX + 1); // the multiplication result
}
cPtr = fnDebugDec(usY, (WITH_TERMINATOR), cPtr); // insert the result
if (usX == ptrMulTable->ucColumns) { // end of this row
cPtr = uStrcpy(cPtr, "</tr></th>"); // close table row
}
else {
cPtr = uStrcpy(cPtr, "</th>"); // close a single column
}
*usLengthToSend = (cPtr - cValue - 1); // length of code to insert
}
The example adds a single table element on each execution (its definition of 'chunk' to be added) but could also generate a complete line instead.
I hope that you agree that this allows for a flexible interface to user code to perform a variety of similar tasks.
Regards
Mark