Changeset 489 for XIOS/trunk/src/node


Ignore:
Timestamp:
09/22/14 14:17:33 (10 years ago)
Author:
mhnguyen
Message:

Ticket 50: Implementing the getting/setting methods for Fortran interface

+) Add some C and Fortran functions to set and get data to/from CVariable with an id
+) Add method to send, receive and dispatch in CVariable
+) Add dispatch method in server class

Test
-) On Curie
-) Test data: integer, float, double, boolean, string
-) File: one and multiple, using_server: ON and OFF
+) All test cases passed and had correct results

Location:
XIOS/trunk/src/node
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/variable.cpp

    r477 r489  
    77#include "xmlioserver_spl.hpp" 
    88#include "type.hpp" 
     9#include "context.hpp" 
     10#include "context_client.hpp" 
    911#include <boost/algorithm/string.hpp> 
    1012 
     
    4850   { 
    4951      return (this->content); 
     52   } 
     53 
     54   void CVariable::setContent(const StdString& contentStr) 
     55   { 
     56     this->content = contentStr; 
    5057   } 
    5158 
     
    6168      oss << "</" << CVariable::GetName() << " >"; 
    6269      return (oss.str()); 
    63    }  
    64     
     70   } 
     71 
    6572   CVariable::EVarType CVariable::getVarType(void) const 
    6673   { 
    6774     EVarType ret ; 
    68       
     75 
    6976     if (type.isEmpty()) ret=t_undefined ; 
    7077     else 
     
    8390     return ret ; 
    8491   } 
    85         
     92 
     93   /* 
     94   *\brief Sending value of a variable with its id from client to server 
     95   * 
     96   */ 
     97   void CVariable::sendValue() 
     98   { 
     99     CContext* context=CContext::getCurrent() ; 
     100     if (!context->hasServer) 
     101     { 
     102       CContextClient* client=context->client ; 
     103 
     104       CEventClient event(this->getType(),EVENT_ID_VARIABLE_VALUE) ; 
     105       if (client->isServerLeader()) 
     106       { 
     107         CMessage msg ; 
     108         msg<<this->getId() ; 
     109         msg<<content ; 
     110         event.push(client->getServerLeader(),1,msg) ; 
     111         client->sendEvent(event) ; 
     112       } 
     113       else client->sendEvent(event) ; 
     114    } 
     115   } 
     116 
     117   /* 
     118   *\brief Receive value of a variable with its id from client to server 
     119   * 
     120   */ 
     121   void CVariable::recvValue(CEventServer& event) 
     122   { 
     123      CBufferIn* buffer=event.subEvents.begin()->buffer; 
     124      string id; 
     125      *buffer>>id ; 
     126      get(id)->recvValue(*buffer); 
     127   } 
     128 
     129 
     130   /* 
     131   *\brief Receive value of a variable with its id from client to server 
     132   * 
     133   */ 
     134   void CVariable::recvValue(CBufferIn& buffer) 
     135   { 
     136      string str ; 
     137      buffer>>str; 
     138      setContent(str); 
     139   } 
     140 
     141   bool CVariable::dispatchEvent(CEventServer& event) 
     142   { 
     143    if (SuperClass::dispatchEvent(event)) return true ; 
     144    else 
     145    { 
     146      switch(event.type) 
     147      { 
     148        case EVENT_ID_VARIABLE_VALUE : 
     149          recvValue(event) ; 
     150          return true ; 
     151          break ; 
     152 
     153        default : 
     154          ERROR("bool CVariable::dispatchEvent(CEventServer& event)",<<"Unknown Event") ; 
     155          return false ; 
     156      } 
     157    } 
     158   } 
     159 
    86160/* 
    87161   void CVariable::toBinary(StdOStream & os) const 
  • XIOS/trunk/src/node/variable.hpp

    r472 r489  
    1515      class CVariableAttributes; 
    1616      class CVariable; 
    17  
     17      class CContext; 
    1818      ///-------------------------------------------------------------- 
    1919 
     
    2929         , public CVariableAttributes 
    3030      { 
     31            enum EEventId 
     32            { 
     33             EVENT_ID_VARIABLE_VALUE 
     34            }; 
     35 
    3136            /// typedef /// 
    3237            typedef CObjectTemplate<CVariable>   SuperClass; 
     
    5257            enum EVarType 
    5358            {  t_int, t_short_int, t_long_int, t_float, t_double, t_long_double, t_bool, t_string, t_undefined } ; 
    54                
    55                       
     59 
     60 
    5661            /// Autres /// 
    5762            virtual void parse(xml::CXMLNode & node); 
     
    6065            /// Accesseur /// 
    6166            const StdString & getContent (void) const; 
    62              
    63              
     67 
     68            void setContent(const StdString& content); 
     69 
     70 
    6471            template <typename T> inline T getData(void) const; 
    65              
     72            template <typename T> inline void setData(T data); 
     73 
    6674            template <typename T, StdSize N> 
    6775            inline void getData(CArray<T, N>& _data_array) const; 
    68              
     76 
    6977            EVarType getVarType(void) const ; 
    70              
     78 
     79            static bool dispatchEvent(CEventServer& event) ; 
     80 
     81            //! Sending a request to set up variable data 
     82            void sendValue(); 
     83 
     84            static void recvValue(CEventServer& event) ; 
     85            void recvValue(CBufferIn& buffer) ; 
     86 
    7187         public : 
    72           
     88 
    7389            /// Accesseurs statiques /// 
    7490            static StdString GetName(void); 
     
    85101      inline bool CVariable::getData(void) const 
    86102      { 
    87          if (content.compare("true")==0 || content.compare(".true.")==0 || content.compare(".TRUE.")==0) return true ;  
    88          else if (content.compare("false")==0 || content.compare(".false.")==0 || content.compare(".FALSE.")==0) return false ;  
     103         if (content.compare("true")==0 || content.compare(".true.")==0 || content.compare(".TRUE.")==0) return true ; 
     104         else if (content.compare("false")==0 || content.compare(".false.")==0 || content.compare(".FALSE.")==0) return false ; 
    89105         else ERROR("CVariable::getdata()", 
    90106               << "Cannot convert string <" << content << "> into type required" ); 
    91107         return false ; 
    92       }  
    93        
     108      } 
     109 
    94110      template <typename T> 
    95111      inline T CVariable::getData(void) const 
    96112      { 
    97113         T retval ; 
    98          std::stringstream sstr(std::stringstream::in | std::stringstream::out);  
     114         std::stringstream sstr(std::stringstream::in | std::stringstream::out); 
    99115         sstr<<content ; 
    100116         sstr>>retval ; 
     
    102118               << "Cannot convert string <" << content << "> into type required" ); 
    103119         return retval ; 
    104       }  
     120      } 
    105121 
     122      template<> 
     123      inline void CVariable::setData(bool data) 
     124      { 
     125        if (true == data) content.assign("true"); 
     126        else content.assign("false"); 
     127      } 
     128 
     129      template <typename T> 
     130      inline void CVariable::setData(T data) 
     131      { 
     132        std::stringstream sstr; 
     133        sstr<<data; 
     134        content = sstr.str(); 
     135      } 
    106136 
    107137      ///-------------------------------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.