tape_ODBC/ODBCConnHandle.cpp

00001 /*  ODBCConnHandle.cpp
00002  *
00003  *  author: Matt Hauer, matthew.hauer@pnl.gov, 6/4/07 - ***
00004  */
00005 
00006 #include "ODBCConnHandle.h"
00007 
00008 ODBCConnHandle::ODBCConnHandle(){
00009     Reset();
00010 }
00011 
00012 ODBCConnHandle::ODBCConnHandle(Connection *inconn, char *hostname){
00013     Reset();
00014     conn=inconn;
00015     strncpy(servername, hostname, 128);
00016 }
00017 
00018 ODBCConnHandle::~ODBCConnHandle(){
00019     Disconnect();   //  clears list
00020     delete conn;
00021 }
00022 
00023 void ODBCConnHandle::Reset(){
00024     tapect=0;
00025     conn=0;
00026     if(!tapelist.empty()){
00027         printf("WARNING:\tODBCConnHandle::Reset: we're reseting a non-empty handle?\n");
00028     }
00029     tapelist.clear();
00030     memset(servername, 0, 128);
00031 }
00032 
00033 int ODBCConnHandle::CheckName(char *hostname){
00034     return strcmp(servername, hostname);
00035 }
00036 
00037 void ODBCConnHandle::DisconnectTape(ODBCTapeStream *ts){
00038     if(tapelist.empty()) return;    //  nothing to remove
00039     tapelist.remove(ts);
00040     int tapelistsize=(int)(tapelist.size());
00041     if(tapelistsize > tapect)
00042         printf("WARNING:\tODBCConnHandle::DisconnectTape: we disconnected a tape and ended up with more tapes than we started with?\n");
00043     tapect=tapelistsize;            //  shouldn't assume single instence removed
00044 }
00045 
00046 void ODBCConnHandle::Disconnect(){  //  as in, everything
00047     while(!tapelist.empty()){
00048         tapelist.front()->HardClose();
00049         tapelist.pop_front();
00050     }
00051 }
00052 
00053 int ODBCConnHandle::RegisterStream(ODBCTapeStream *ts){
00054     tapelist.push_back(ts);
00055     ++tapect;
00056     return 1;   //  success
00057 }
00058 
00059 //  end of ODBCConnHandle.cpp

GridLAB-DTM Version 1.0
An open-source project initiated by the US Department of Energy