Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

IOManagerIS.cpp

00001 #include "IOManagerIS.h"
00002 #include "IStreamIS.h"
00003 #include "OStreamIS.h"
00004 #include "IONameIS.h"
00005 #include "../Serializable.h"
00006 #include "../LogicErrors.h"
00007 #include "../SctNames.h"
00008 #include "../MultiMessageDebugStream.h"
00009 
00010 #include <is/info.h>
00011 #include <is/infodictionary.h>
00012 #include <is/infoiterator.h>
00013 #include <is/inforeceiver.h>
00014 
00015 namespace Sct {
00016 namespace IS {
00017  
00018 namespace detail {
00019     
00020 class ISAdapter : public ISInfo {
00021 public:
00022     ISAdapter(const string& className, const IOManagerIS& manager) : 
00023     ISInfo(className.c_str()), manager(manager), writeOb(0), className(className) {}
00024     
00025     ISAdapter(const Serializable& writeOb, const IOManagerIS& manager) : 
00026     ISInfo(writeOb.getClassName().c_str()), manager(manager), writeOb(&writeOb) {}
00027     
00028     virtual void refreshGuts(ISistream& inIS) {
00029     IStreamIS in(inIS);
00030     readOb = boost::dynamic_pointer_cast<Serializable>(manager.readImpl(in));
00031     }
00032     
00033     virtual void publishGuts(ISostream& outIS) {
00034       
00035       //Break IS type checking
00036       if (dynamic_cast<ISType*>(&outIS)!=0 ) return; 
00037       if (!writeOb) {
00038     // throw InvariantViolatedError("IOManagerIS::ISAdapter Tried to write a null object", __FILE__, __LINE__);
00039 
00040     static unsigned int numberOfMessages=0;
00041     const unsigned int maxMessages=5;
00042     if (numberOfMessages < maxMessages) {
00043       ++numberOfMessages;
00044       Sct::MultiMessageDebugStream m(true,true,true);
00045       m.severity(MRS_WARNING);
00046       m << "EXPERIMENTAL KLUDGE ... OUGHT TO HAVE THROWN.  DO NOT RELY ON DATA! CGL & DR. [MAX WARNINGS=" << maxMessages<< "]";
00047     };
00048       } else {
00049     OStreamIS out(outIS);
00050     manager.writeImpl(out, *writeOb, true);
00051       };
00052     }
00053     
00054     shared_ptr<Serializable> getOb() {
00055     return readOb;
00056     }
00057     
00058 private:
00059     const IOManagerIS& manager;
00060     const Serializable* writeOb;
00061     shared_ptr<Serializable> readOb;
00062     string className;
00063 };
00064 }   
00065   
00066 using namespace detail;
00067 
00068 IOManagerIS::IOManagerIS() throw() {}
00069 
00070 IOManagerIS& IOManagerIS::instance() throw() {
00071     static IOManagerIS bertha;
00072     return bertha;
00073 }
00074 
00075 void IOManagerIS::write(const Serializable& ob, const IOParams* params) const throw(LogicError, IoError) {   
00076     IONameIS IOName(ob.getUniqueID(), ob.getClassName());
00077     if (params) {
00078     const IOParamsIS* p = dynamic_cast<const IOParamsIS*>(params);
00079     if (p) IOName.setServer(p->serverName);
00080     }
00081     
00082     ISAdapter adapter(ob, *this);
00083     
00084     ISInfoDictionary& id = SctNames::getISDictionary();
00085     ISInfo::Status result = id.insert(IOName.getIOName().c_str(), adapter);
00086     
00087     if (result != ISInfo::Success) {        
00088     throw IsException(result, "Error writing to IS server.  Couldn't write: " + IOName.getIOName(), __FILE__, __LINE__);
00089     }
00090 
00091 }
00092 
00093 shared_ptr<Serializable> IOManagerIS::read(const string& name, const IOParams* params) const throw(LogicError, IoError) {
00094     IONameIS IOName(name);
00095     ISAdapter adapter(IOName.getClassName(), *this);
00096     
00097     ISInfoDictionary& id = SctNames::getISDictionary();
00098     ISInfo::Status result = id.findValue(name.c_str(), adapter);
00099 
00100     if (result != ISInfo::Success) {
00101         throw IsException(result, "Error reading from IS server.  Couldn't read: " + name, __FILE__, __LINE__); 
00102     }
00103 
00104     return adapter.getOb();
00105 }
00106 
00107 shared_ptr<Serializable> IOManagerIS::read(const ISCallbackInfo& info) const throw(LogicError, IoError) {
00108     IONameIS IOName(info.name());
00109     ISAdapter adapter(IOName.getClassName(), *this);
00110     
00111     ISInfo::Status result = info.value(adapter);
00112 
00113     if (result != ISInfo::Success) {
00114         throw IsException(result, string("Error reading from IS server.  Couldn't read: ") + info.name(), __FILE__, __LINE__);  
00115     }
00116 
00117     return adapter.getOb();    
00118 }
00119 
00120 shared_ptr<Serializable> IOManagerIS::read(ISInfoIterator& it) const throw(LogicError, IoError) {
00121     IONameIS IOName(it.name());
00122     ISAdapter adapter(IOName.getClassName(), *this);
00123     
00124     ISInfo::Status result = it.value(adapter);
00125 
00126     if (result != ISInfo::Success) {
00127         throw IsException(result, string("Error reading from IS server.  Couldn't read: ") + it.name(), __FILE__, __LINE__);    
00128     }
00129 
00130     return adapter.getOb();    
00131 }
00132     
00133 }
00134 }

Generated on Thu Dec 22 20:17:03 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5