/* Coded by Loïc Jeannin - loic@conectiva.com.br - tahorg - gcu(c) 5/2002 this piece of *sigh* code is freely distribuable under the terms of the GPL. Conectiva Corporation (c) */ // vim: tabstop=2 shiftwidth=2 expandtab /* objects definitions */ #include "drbd_main.h" using namespace std; class net { int SyncRate; int SkipSync; int TlSize; int Timeout; int ConnectInt; int PingInt; public: net() { SyncRate=250; SkipSync=0; TlSize=5000; Timeout=10; ConnectInt=10; PingInt=10; } int getSyncRate() {return(SyncRate);} int getSkipSync() {return(SkipSync);} int getTlSize() {return(TlSize);} int getTimeout() {return(Timeout);} int getConnectInt() {return(ConnectInt);} int getPingInt() {return(PingInt);} void setSyncRate(int tmp) {SyncRate=tmp;} void setSkipSync(int tmp) {SkipSync=tmp;} void setTlSize(int tmp) {TlSize=tmp;} void setTimeout(int tmp) {Timeout=tmp;} void setConnectInt(int tmp) {ConnectInt=tmp;} void setPingInt(int tmp) {PingInt=tmp;} void print() { ofstream f(SAVE_FILE,ios::app); f << "\tnet {" << endl; f << "\t\tsync-rate=" << SyncRate << endl; if(SkipSync) f << "\t\tskip-sync" << endl; f << "\t\ttimeout="<< Timeout << endl; f << "\t\ttl-size=" << TlSize << endl; f << "\t\tconnect-int=" << ConnectInt << endl; f << "\t\tping-int=" << PingInt << endl; f << "\t}" << endl << endl; f.close(); } }; /**----------**/ class disk { private: int DoPanic; long int Size; public: disk(){ DoPanic=0; Size=0; } int getDoPanic(){return(DoPanic);} long int getSize(){return(Size);} void setSize(long int s){Size=s;} void setDoPanic(int d){ DoPanic=d; } void print() { ofstream f(SAVE_FILE,ios::app); f << "\tdisk {" << endl; if (DoPanic) f << "\t\tdo-panic" << endl; f << "\t\tdisk-size=" << Size << endl; f << "\t}\n" << endl; f.close(); } }; /**----------**/ class on_block { private: char *Name; char *Device; char *Disk; char *Address; int Port; public: const char * getName(){return(Name);} const char * getDevice(){return(Device);} const char * getDisk(){return(Disk);} const char * getAddress(){return(Address);} int getPort(){return(Port);} /** constructor **/ on_block() { Name=Device=Disk=Address=NULL; Port=7788; } on_block(char *n) { setName(n); Device=Disk=Address=NULL; Port=0; } /** data manipulation **/ void setName(const char *name){ if(!Name) free(Name); Name=(char *)malloc((strlen(name)+1)*sizeof(char)); strcpy(Name,name); } void setDevice(const char *device){ if(!Device) free(Device); Device=(char *)malloc((strlen(device)+1)*sizeof(char)); strcpy(Device,device); } void setDisk(const char *disk){ if(!Disk) free(Disk); Disk=(char *)malloc((strlen(disk)+1)*sizeof(char)); strcpy(Disk,disk); } void setAddress(const char *address){ if(!Address) free(Address); Address=(char *)malloc((strlen(address)+1)*sizeof(char)); strcpy(Address,address); } void setPort(int port){ Port=port; } /** writing in the file **/ void print() { ofstream f(SAVE_FILE,ios::app); f << "\ton " << Name << " {\n"; f << "\t\tdevice=" << Device << "\n"; f << "\t\tdisk=" << Disk << "\n"; f << "\t\taddress=" << Address << "\n"; f << "\t\tport=" << Port << "\n"; f << "\t}\n\n"; f.close(); } }; /**----------**/ class resource { private: char *Name; char *Fsckcmd; char Protocol; int Inittimeout; public: resource *next; on_block o_block_1; on_block o_block_2; disk o_disk; net o_net; int n_block; resource() { Protocol='A'; Inittimeout=0; next=NULL; Fsckcmd=Name=NULL; n_block=0; } resource(const char * n) { Protocol='A'; Inittimeout=0; next=NULL; Fsckcmd=Name=NULL; n_block=0; setName(n); } const char * getName(){return(Name);} const char * getFsckcmd(){return(Fsckcmd);} char getProtocol(){return(Protocol);} int getInittimeout(){return(Inittimeout);} void setName(const char *name){ if(!Name) free(Name); Name=(char *)malloc((strlen(name)+1)*sizeof(char)); strcpy(Name,name); } void setFsckcmd(const char *fsckcmd){ if(!Fsckcmd) free(Fsckcmd); Fsckcmd=(char *)malloc((strlen(fsckcmd)+1)*sizeof(char)); strcpy(Fsckcmd,fsckcmd); } void setProtocol(char protocol){ Protocol=protocol; } void setInittimeout(int inittimeout){ Inittimeout=inittimeout; } void print() { ofstream f(SAVE_FILE,ios::app); f << "resource " << Name << " {" << endl; f << "\tprotocol=" << Protocol << endl; f << "\tfsckcmd=" << Fsckcmd << endl ; if (Inittimeout) f << "\tinittimeout=" << Inittimeout << endl; f << endl; o_disk.print(); o_net.print(); o_block_1.print(); o_block_2.print(); f << "}" << endl; f.close(); } };