rllib  1
rlopcxmlda.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           rlopcxmlda.cpp  -  description
00003                              -------------------
00004     begin                : Mon Aug 27 2007
00005     copyright            : (C) 20071 by pvbrowser
00006     email                : lehrig@t-online.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
00013  *   published by the Free Software Foundation                             *
00014  *                                                                         *
00015  ***************************************************************************/
00016 #include "rlopcxmlda.h"
00017 #include <stdio.h>
00018 #include <string.h>
00019 #include <ctype.h>
00020 
00021 rlOpcXmlDa::rlOpcXmlDa(const char *mailbox, const char *shared_memory, long shared_memory_size)
00022 {
00023   mbx = new rlMailbox(mailbox);
00024   shm = new rlSharedMemory(shared_memory,shared_memory_size);
00025   shmheader = (SHM_HEADER *) shm->getUserAdr();
00026   shmvalues = ((const char *)shmheader) + sizeof(SHM_HEADER);
00027 }
00028 
00029 rlOpcXmlDa::~rlOpcXmlDa()
00030 {
00031   delete mbx;
00032   delete shm;
00033 }
00034 
00035 const char *rlOpcXmlDa::stringValue(const char *variable)
00036 {
00037   int value_offset, delta_index, nmax, i;
00038   const char *cptr;
00039 
00040   if(shmheader == NULL) return "OPCXMLDA_ERROR";
00041   if(strcmp(shmheader->ident,"opc") != 0) return "OPCXMLDA_ERROR";
00042   value_offset = shmheader->maxItemNameLength + 1;
00043   delta_index  = value_offset + shmheader->maxNameLength + 1;
00044   nmax         = shmheader->numItems;
00045 
00046   cptr = shmvalues;
00047   for(i=0; i<nmax; i++)
00048   {
00049     if(strcmp(cptr,variable) == 0)
00050     {
00051       return cptr + value_offset;
00052     }
00053     cptr += delta_index;
00054   }
00055 
00056   return "OPCXMLDA_ERROR";
00057 }
00058 
00059 int rlOpcXmlDa::intValue(const char *variable)
00060 {
00061   const char *cptr;
00062   int ret;
00063 
00064   cptr = stringValue(variable);
00065   if(isdigit(*cptr))
00066   {
00067     ret = OPCXMLDA_ERROR;
00068     sscanf(cptr,"%d",&ret);
00069     return ret;
00070   }
00071   return OPCXMLDA_ERROR;
00072 }
00073 
00074 float rlOpcXmlDa::floatValue(const char *variable)
00075 {
00076   const char *cptr;
00077   float ret;
00078 
00079   cptr = stringValue(variable);
00080   if(isdigit(*cptr) || *cptr == '-')
00081   {
00082     ret = OPCXMLDA_ERROR;
00083     sscanf(cptr,"%f",&ret);
00084     return ret;
00085   }
00086   return OPCXMLDA_ERROR;
00087 }
00088 
00089 int rlOpcXmlDa::writeStringValue(const char *variable, const char *value)
00090 {
00091   mbx->printf("%s,%s\n",variable,value);
00092   return 0;
00093 }
00094 
00095 int rlOpcXmlDa::writeIntValue(const char *variable, int value)
00096 {
00097   mbx->printf("%s,%d\n",variable,value);
00098   return 0;
00099 }
00100 
00101 int rlOpcXmlDa::writeFloatValue(const char *variable, float value)
00102 {
00103   mbx->printf("%s,%f\n",variable,value);
00104   return 0;
00105 }
00106 
00107 int rlOpcXmlDa::readErrorCount()
00108 {
00109   if(shmheader == NULL) return OPCXMLDA_ERROR;
00110   return shmheader->readErrorCount;
00111 }
00112 
00113 int rlOpcXmlDa::writeErrorCount()
00114 {
00115   if(shmheader == NULL) return OPCXMLDA_ERROR;
00116   return shmheader->writeErrorCount;
00117 }
00118 
00119 int rlOpcXmlDa::shmStatus()
00120 {
00121   if(shmheader == NULL) return OPCXMLDA_ERROR;
00122   if(shm->status == rlSharedMemory::OK) return 0;
00123   return OPCXMLDA_ERROR;
00124 }
00125 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines