dnxClntProt.c

Go to the documentation of this file.
00001 /*--------------------------------------------------------------------------
00002 
00003    Copyright (c) 2006-2007, Intellectual Reserve, Inc. All rights reserved.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License version 2 as
00007    published by the Free Software Foundation.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software
00016    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018   --------------------------------------------------------------------------*/
00019 
00028 #include "dnxClntProt.h"
00029 #include "dnxXml.h"
00030 #include "dnxError.h"
00031 #include "dnxTransport.h"
00032 #include <assert.h>
00033 #include <string.h>
00034 
00035 //----------------------------------------------------------------------------
00036 
00049 int dnxSendNodeRequest(DnxChannel * channel, DnxNodeRequest * pReg)
00050 {
00051    DnxXmlBuf xbuf;
00052 
00053    assert(channel && pReg);
00054 
00055    // create the XML message
00056    dnxXmlOpen (&xbuf, "NodeRequest");
00057    dnxXmlAdd  (&xbuf, "XID",     DNX_XML_XID,  &pReg->xid);
00058    dnxXmlAdd  (&xbuf, "GUID",    DNX_XML_XID,  &pReg->xid);    // old format - for bc
00059    dnxXmlAdd  (&xbuf, "ReqType", DNX_XML_INT,  &pReg->reqType);
00060    dnxXmlAdd  (&xbuf, "JobCap",  DNX_XML_UINT, &pReg->jobCap);
00061    dnxXmlAdd  (&xbuf, "Capacity",DNX_XML_UINT, &pReg->jobCap); // old format - for bc
00062    dnxXmlAdd  (&xbuf, "TTL",     DNX_XML_UINT, &pReg->ttl);
00063    dnxXmlClose(&xbuf);
00064 
00065    dnxDebug(4, "dnxSendNodeRequest: XML msg(%d bytes)=%s.", xbuf.size, xbuf.buf);
00066 
00067    // send it on the specified channel
00068    return dnxPut(channel, xbuf.buf, xbuf.size, 0, 0);
00069 }
00070 
00071 //----------------------------------------------------------------------------
00072 
00086 int dnxWaitForJob(DnxChannel * channel, DnxJob * pJob, int timeout)
00087 {
00088    DnxXmlBuf xbuf;
00089    int ret;
00090 
00091    assert(channel && pJob);
00092    memset(pJob, 0, sizeof *pJob);
00093 
00094    // await a message from the specified channel
00095    xbuf.size = sizeof xbuf.buf - 1;
00096    if ((ret = dnxGet(channel, xbuf.buf, &xbuf.size, timeout, 0)) != DNX_OK)
00097       return ret;
00098 
00099    // decode the XML message
00100    xbuf.buf[xbuf.size] = 0;
00101    dnxDebug(4, "dnxWaitForJob: XML msg(%d bytes)=%s.", xbuf.size, xbuf.buf);
00102 
00103    // verify this is a "Job" message
00104    if ((ret = dnxXmlCmpStr(&xbuf, "Request", "Job")) != DNX_OK)
00105       return ret;
00106 
00107    // decode the job's XID (support older GUID format as well)
00108    if ((ret = dnxXmlGet(&xbuf, "XID", DNX_XML_XID, &pJob->xid)) != DNX_OK
00109          && (ret = dnxXmlGet(&xbuf, "GUID", DNX_XML_XID, &pJob->xid)) != DNX_OK)
00110       return ret;
00111 
00112    // decode the job's state
00113    if ((ret = dnxXmlGet(&xbuf, "State", DNX_XML_INT, &pJob->state)) != DNX_OK)
00114       return ret;
00115 
00116    // decode the job's priority
00117    if ((ret = dnxXmlGet(&xbuf, "Priority", DNX_XML_INT, &pJob->priority)) != DNX_OK)
00118       return ret;
00119 
00120    // decode the job's timeout
00121    if ((ret = dnxXmlGet(&xbuf, "Timeout", DNX_XML_INT, &pJob->timeout)) != DNX_OK)
00122       return ret;
00123 
00124    // decode the job's command
00125    return dnxXmlGet(&xbuf, "Command", DNX_XML_STR, &pJob->cmd);
00126 }
00127 
00128 //----------------------------------------------------------------------------
00129 
00139 int dnxSendResult(DnxChannel * channel, DnxResult * pResult)
00140 {
00141    DnxXmlBuf xbuf;
00142    char * resData;
00143 
00144    assert(channel && pResult);
00145 
00146    if ((resData = pResult->resData) == 0 || *resData == 0)
00147       resData = "(DNX: No Output!)";
00148 
00149    // create the XML message
00150    dnxXmlOpen (&xbuf, "Result");
00151    dnxXmlAdd  (&xbuf, "XID",        DNX_XML_XID,  &pResult->xid);
00152    dnxXmlAdd  (&xbuf, "GUID",       DNX_XML_XID,  &pResult->xid); // old format - for bc
00153    dnxXmlAdd  (&xbuf, "State",      DNX_XML_INT,  &pResult->state);
00154    dnxXmlAdd  (&xbuf, "Delta",      DNX_XML_UINT, &pResult->delta);
00155    dnxXmlAdd  (&xbuf, "ResultCode", DNX_XML_INT,  &pResult->resCode);
00156    dnxXmlAdd  (&xbuf, "ResultData", DNX_XML_STR,   resData);
00157    dnxXmlClose(&xbuf);
00158 
00159    dnxDebug(4, "dnxSendResult: XML msg(%d bytes)=%s.", xbuf.size, xbuf.buf);
00160 
00161    // send it on the specified channel
00162    return dnxPut(channel, xbuf.buf, xbuf.size, 0, 0);
00163 }
00164 
00165 //----------------------------------------------------------------------------
00166 

Generated on Tue Apr 13 15:48:07 2010 for DNX by  doxygen 1.5.6