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

IOManagerIS.cpp

Go to the documentation of this file.
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 
00009 #include <is/isinfo.h>
00010 
00011 namespace Sct {
00012 namespace IS {
00013  
00014 namespace detail {
00015     
00016 class ISAdapter : public ISInfo {
00017 public:
00018     ISAdapter(const string& className, const IOManagerIS& manager) : 
00019     ISInfo(className.c_str()), manager(manager), writeOb(0), className(className) {}
00020     
00021     ISAdapter(const Serializable& writeOb, const IOManagerIS& manager) : 
00022     ISInfo(writeOb.getClassName().c_str()), manager(manager), writeOb(&writeOb) {}
00023     
00024     virtual void refreshGuts(ISistream& inIS) {
00025     IStreamIS in(inIS);
00026     readOb = boost::dynamic_pointer_cast<Serializable>(manager.readImpl(in));
00027     }
00028     
00029     virtual void publishGuts(ISostream& outIS) {
00030     //Break IS type checking
00031     if (dynamic_cast<ISType*>(&outIS)!=0 ) return; 
00032     if (!writeOb) {
00033         throw InvariantViolatedError("IOManagerIS::ISAdapter Tried to write a null object", __FILE__, __LINE__);
00034     }
00035     OStreamIS out(outIS);
00036     manager.writeImpl(out, *writeOb, true);
00037     }
00038     
00039     shared_ptr<Serializable> getOb() {
00040     return readOb;
00041     }
00042     
00043 private:
00044     const IOManagerIS& manager;
00045     const Serializable* writeOb;
00046     shared_ptr<Serializable> readOb;
00047     string className;
00048 };
00049 }   
00050   
00051 using namespace detail;
00052 
00053 IOManagerIS::IOManagerIS() throw() {}
00054 
00055 IOManagerIS& IOManagerIS::instance() throw() {
00056     static IOManagerIS bertha;
00057     return bertha;
00058 }
00059 
00060 void IOManagerIS::write(const Serializable& ob, const IOParams* params) const throw(LogicError, IoError) {   
00061     IONameIS IOName(ob.getUniqueID(), ob.getClassName());
00062     if (params) {
00063     const IOParamsIS* p = dynamic_cast<const IOParamsIS*>(params);
00064     if (p) IOName.setServer(p->serverName);
00065     }
00066     
00067     ISAdapter adapter(ob, *this);
00068     
00069     ISInfoDictionary& id = SctNames::getISDictionary();
00070     ISInfo::Status result = id.insert(IOName.getIOName().c_str(), adapter);
00071     
00072     if (result != ISInfo::Success) {        
00073     throw IsException(result, "Error writing to IS server.  Couldn't write: " + IOName.getIOName(), __FILE__, __LINE__);
00074     }
00075 
00076 }
00077 
00078 shared_ptr<Serializable> IOManagerIS::read(const string& name, const IOParams* params) const throw(LogicError, IoError) {
00079     IONameIS IOName(name);
00080     ISAdapter adapter(IOName.getClassName(), *this);
00081     
00082     ISInfoDictionary& id = SctNames::getISDictionary();
00083     ISInfo::Status result = id.findValue(name.c_str(), adapter);
00084 
00085     if (result != ISInfo::Success) {
00086     throw IsException(result, "Error reading from IS server.  Couldn't read: " + name, __FILE__, __LINE__); 
00087     }
00088 
00089     return adapter.getOb();
00090 }
00091 
00092 shared_ptr<Serializable> IOManagerIS::read(const ISCallbackInfo& info) const throw(LogicError, IoError) {
00093     IONameIS IOName(info.name());
00094     ISAdapter adapter(IOName.getClassName(), *this);
00095     
00096     ISInfo::Status result = info.value(adapter);
00097 
00098     if (result != ISInfo::Success) {
00099         throw IsException(result, string("Error reading from IS server.  Couldn't read: ") + info.name(), __FILE__, __LINE__);  
00100     }
00101 
00102     return adapter.getOb();    
00103 }
00104 
00105 shared_ptr<Serializable> IOManagerIS::read(ISInfoIterator& it) const throw(LogicError, IoError) {
00106     IONameIS IOName(it.name());
00107     ISAdapter adapter(IOName.getClassName(), *this);
00108     
00109     ISInfo::Status result = it.value(adapter);
00110 
00111     if (result != ISInfo::Success) {
00112         throw IsException(result, string("Error reading from IS server.  Couldn't read: ") + it.name(), __FILE__, __LINE__);    
00113     }
00114 
00115     return adapter.getOb();    
00116 }
00117     
00118 }
00119 }

Generated on Mon Dec 15 19:36:04 2003 for SCT DAQ/DCS Software by doxygen1.3-rc3