[219] | 1 | #ifndef __XMLIO_CContext__ |
---|
| 2 | #define __XMLIO_CContext__ |
---|
| 3 | |
---|
[335] | 4 | /// xios headers /// |
---|
[219] | 5 | #include "xmlioserver_spl.hpp" |
---|
[352] | 6 | //#include "node_type.hpp" |
---|
[219] | 7 | #include "calendar.hpp" |
---|
| 8 | |
---|
| 9 | #include "declare_group.hpp" |
---|
[300] | 10 | //#include "context_client.hpp" |
---|
| 11 | //#include "context_server.hpp" |
---|
| 12 | #include "data_output.hpp" |
---|
[219] | 13 | |
---|
[382] | 14 | #include "mpi.hpp" |
---|
[300] | 15 | |
---|
[219] | 16 | |
---|
[335] | 17 | namespace xios { |
---|
[300] | 18 | class CContextClient ; |
---|
| 19 | class CContextServer ; |
---|
[509] | 20 | |
---|
| 21 | |
---|
[219] | 22 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
| 23 | class CContextGroup; |
---|
| 24 | class CContextAttributes; |
---|
| 25 | class CContext; |
---|
[352] | 26 | class CFile; |
---|
[219] | 27 | ///-------------------------------------------------------------- |
---|
| 28 | |
---|
| 29 | // Declare/Define CFileAttribute |
---|
| 30 | BEGIN_DECLARE_ATTRIBUTE_MAP(CContext) |
---|
| 31 | # include "context_attribute.conf" |
---|
| 32 | END_DECLARE_ATTRIBUTE_MAP(CContext) |
---|
| 33 | |
---|
| 34 | ///-------------------------------------------------------------- |
---|
[509] | 35 | /*! |
---|
| 36 | \class CContext |
---|
| 37 | This class corresponds to the concrete presentation of context in xml file and in play an essential role in XIOS |
---|
| 38 | Each object of this class contains all root definition of elements: files, fiels, domains, axis, etc, ... from which |
---|
| 39 | we can have access to each element. |
---|
| 40 | In fact, every thing must a be inside a particuliar context. After the xml file (iodef.xml) is parsed, |
---|
| 41 | object of the class is created and its contains all information of other elements in the xml file. |
---|
| 42 | */ |
---|
[219] | 43 | class CContext |
---|
| 44 | : public CObjectTemplate<CContext> |
---|
| 45 | , public CContextAttributes |
---|
| 46 | { |
---|
[300] | 47 | public : |
---|
| 48 | enum EEventId |
---|
| 49 | { |
---|
| 50 | EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR, |
---|
[509] | 51 | EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE, |
---|
| 52 | EVENT_ID_POST_PROCESS |
---|
[300] | 53 | } ; |
---|
[509] | 54 | |
---|
[219] | 55 | /// typedef /// |
---|
| 56 | typedef CObjectTemplate<CContext> SuperClass; |
---|
| 57 | typedef CContextAttributes SuperClassAttribute; |
---|
| 58 | |
---|
| 59 | public : |
---|
| 60 | |
---|
| 61 | typedef CContextAttributes RelAttributes; |
---|
| 62 | typedef CContext RelGroup; |
---|
| 63 | |
---|
| 64 | //--------------------------------------------------------- |
---|
| 65 | |
---|
| 66 | public : |
---|
| 67 | |
---|
| 68 | /// Constructeurs /// |
---|
| 69 | CContext(void); |
---|
| 70 | explicit CContext(const StdString & id); |
---|
| 71 | CContext(const CContext & context); // Not implemented yet. |
---|
| 72 | CContext(const CContext * const context); // Not implemented yet. |
---|
| 73 | |
---|
| 74 | /// Destructeur /// |
---|
| 75 | virtual ~CContext(void); |
---|
| 76 | |
---|
| 77 | //--------------------------------------------------------- |
---|
| 78 | |
---|
| 79 | public : |
---|
[509] | 80 | |
---|
[219] | 81 | /// Mutateurs /// |
---|
[343] | 82 | void setCalendar(boost::shared_ptr<CCalendar> newCalendar); |
---|
[509] | 83 | |
---|
[219] | 84 | /// Accesseurs /// |
---|
[343] | 85 | boost::shared_ptr<CCalendar> getCalendar(void) const; |
---|
[219] | 86 | |
---|
| 87 | public : |
---|
[509] | 88 | // Initialize server or client |
---|
| 89 | void initServer(MPI_Comm intraComm, MPI_Comm interComm) ; |
---|
[511] | 90 | void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer=0) ; |
---|
[509] | 91 | bool isInitialized(void) ; |
---|
[219] | 92 | |
---|
[509] | 93 | // Put sever or client into loop state |
---|
[300] | 94 | bool eventLoop(void) ; |
---|
| 95 | bool serverLoop(void) ; |
---|
| 96 | void clientLoop(void) ; |
---|
[509] | 97 | |
---|
| 98 | // Process all information of calendar |
---|
| 99 | void solveCalendar(void); |
---|
| 100 | |
---|
| 101 | // Finalize a context |
---|
[300] | 102 | void finalize(void) ; |
---|
| 103 | void closeDefinition(void) ; |
---|
[509] | 104 | |
---|
| 105 | // Some functions to process context |
---|
[300] | 106 | void findAllEnabledFields(void); |
---|
[459] | 107 | void processEnabledFiles(void) ; |
---|
[445] | 108 | void solveAllInheritance(bool apply=true) ; |
---|
[300] | 109 | void findEnabledFiles(void); |
---|
| 110 | void closeAllFile(void) ; |
---|
| 111 | void updateCalendar(int step) ; |
---|
| 112 | void createFileHeader(void ) ; |
---|
[509] | 113 | void solveAllRefOfEnabledFields(bool sendToServer); |
---|
| 114 | void buildAllExpressionOfEnabledFields(); |
---|
| 115 | void postProcessing(); |
---|
| 116 | |
---|
| 117 | std::map<int, StdSize>& getDataSize(); |
---|
| 118 | void setClientServerBuffer(); |
---|
| 119 | |
---|
| 120 | // Send context close definition |
---|
[300] | 121 | void sendCloseDefinition(void) ; |
---|
[509] | 122 | // There are something to send on closing context defintion |
---|
[300] | 123 | void sendUpdateCalendar(int step) ; |
---|
| 124 | void sendCreateFileHeader(void) ; |
---|
[509] | 125 | void sendEnabledFiles(); |
---|
| 126 | void sendEnabledFields(); |
---|
| 127 | void sendRefDomainsAxis(); |
---|
| 128 | void sendRefGrid(); |
---|
| 129 | void sendPostProcessing(); |
---|
| 130 | |
---|
[511] | 131 | const StdString& getIdServer(); |
---|
| 132 | |
---|
[509] | 133 | // Client side: Receive and process messages |
---|
[300] | 134 | static void recvUpdateCalendar(CEventServer& event) ; |
---|
| 135 | void recvUpdateCalendar(CBufferIn& buffer) ; |
---|
| 136 | static void recvCloseDefinition(CEventServer& event) ; |
---|
| 137 | static void recvCreateFileHeader(CEventServer& event) ; |
---|
| 138 | void recvCreateFileHeader(CBufferIn& buffer) ; |
---|
[509] | 139 | static void recvSolveInheritanceContext(CEventServer& event); |
---|
| 140 | void recvSolveInheritanceContext(CBufferIn& buffer); |
---|
| 141 | static void recvPostProcessing(CEventServer& event); |
---|
| 142 | void recvPostProcessing(CBufferIn& buffer); |
---|
| 143 | |
---|
| 144 | // dispatch event |
---|
| 145 | static bool dispatchEvent(CEventServer& event) ; |
---|
| 146 | |
---|
| 147 | public: |
---|
| 148 | // Get current context |
---|
| 149 | static CContext* getCurrent(void); |
---|
| 150 | |
---|
| 151 | // Get context root |
---|
| 152 | static CContextGroup* getRoot(void); |
---|
| 153 | |
---|
| 154 | // Set current context |
---|
| 155 | static void setCurrent(const string& id); |
---|
| 156 | |
---|
| 157 | // Create new context |
---|
| 158 | static CContext* create(const string& id = ""); |
---|
| 159 | |
---|
| 160 | /// Accesseurs statiques /// |
---|
| 161 | static StdString GetName(void); |
---|
| 162 | static StdString GetDefName(void); |
---|
| 163 | static ENodeType GetType(void); |
---|
| 164 | |
---|
| 165 | static CContextGroup* GetContextGroup(void); |
---|
| 166 | |
---|
| 167 | // Some functions to visualize structure of current context |
---|
| 168 | static void ShowTree(StdOStream & out = std::clog); |
---|
| 169 | static void CleanTree(void); |
---|
| 170 | |
---|
[219] | 171 | public : |
---|
[509] | 172 | // Parse xml node and write all info into context |
---|
[219] | 173 | virtual void parse(xml::CXMLNode & node); |
---|
| 174 | |
---|
[509] | 175 | // Visualize a context |
---|
[219] | 176 | virtual StdString toString(void) const; |
---|
[509] | 177 | |
---|
| 178 | |
---|
| 179 | // Solve all inheritance relation in current context |
---|
| 180 | virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0); |
---|
| 181 | |
---|
| 182 | // Verify if all root definition in a context have children |
---|
| 183 | virtual bool hasChild(void) const; |
---|
| 184 | |
---|
[300] | 185 | public : |
---|
[509] | 186 | // Calendar of context |
---|
| 187 | boost::shared_ptr<CCalendar> calendar; |
---|
| 188 | |
---|
| 189 | // List of all enabled files (files on which fields are written) |
---|
[347] | 190 | std::vector<CFile*> enabledFiles; |
---|
[509] | 191 | |
---|
| 192 | // Context root |
---|
[346] | 193 | static shared_ptr<CContextGroup> root ; |
---|
[219] | 194 | |
---|
[509] | 195 | // Determine context on client or not |
---|
| 196 | bool hasClient ; |
---|
[300] | 197 | |
---|
[509] | 198 | // Determine context on server or not |
---|
| 199 | bool hasServer ; |
---|
| 200 | |
---|
| 201 | // Concrete context server |
---|
| 202 | CContextServer* server ; |
---|
| 203 | |
---|
| 204 | // Concrete contex client |
---|
| 205 | CContextClient* client ; |
---|
| 206 | |
---|
| 207 | private: |
---|
| 208 | bool isPostProcessed; |
---|
| 209 | std::map<int, StdSize> dataSize_; |
---|
[511] | 210 | StdString idServer_; |
---|
[509] | 211 | |
---|
| 212 | |
---|
| 213 | public: // Some function maybe removed in the near future |
---|
| 214 | // virtual void toBinary (StdOStream & os) const; |
---|
| 215 | // virtual void fromBinary(StdIStream & is); |
---|
| 216 | // void solveAllGridRef(void); |
---|
| 217 | // void solveAllOperation(void); |
---|
| 218 | // void solveAllExpression(void); |
---|
| 219 | // void solveFieldRefInheritance(bool apply); |
---|
| 220 | |
---|
[219] | 221 | }; // class CContext |
---|
| 222 | |
---|
| 223 | ///-------------------------------------------------------------- |
---|
| 224 | |
---|
| 225 | // Declare/Define CContextGroup and CContextDefinition |
---|
| 226 | DECLARE_GROUP(CContext); |
---|
| 227 | |
---|
| 228 | ///-------------------------------------------------------------- |
---|
| 229 | |
---|
[335] | 230 | } // namespace xios |
---|
[219] | 231 | |
---|
| 232 | #endif // __XMLIO_CContext__ |
---|