zsospnfs.cpp

Go to the documentation of this file.
00001 //Grzegorz Wierzowiecki
00002 #include <cstdio>
00003 #include <unistd.h> 
00004 #include <string>
00005 #include <cstring>
00006 #include "ZSO-SPNFS_csv_coding.hpp"
00007 #include "ZSO-SPNFS_helper.hpp"
00008 
00009 #include "zsospnfs.h"
00010 
00011 class encoded{ public:
00012     std::string s;
00013     inline encoded(std::string news){ s = make_csv_string(news); };
00014     inline encoded(long long l){ s = make_csv_string(l); };
00015     inline encoded(const char *news){ s = make_csv_string(news); };
00016     inline encoded(std::string news,int){ s = news; };
00017 };
00018 
00019 inline long long getll(int c){
00020     write(c,"\n--------------------------------------------------\n");//flushing output buffer
00021     return get_integer_from_string(read_csv_string(c));
00022 };
00023 
00024 inline std::string getstr(int c){
00025     write(c,"\n----------------------------------------------------\n");//flushing output buffer
00026     return read_csv_string(c);
00027 };
00028 
00029 inline int snd(int fd, encoded a=encoded("",0), encoded b=encoded("",0), encoded c=encoded("",0), encoded d=encoded("",0), encoded e=encoded("",0) ){
00030     //printf("snd() -> %s\n", (a.s+b.s+c.s+d.s+e.s).c_str());
00031     return write(fd,a.s+b.s+c.s+d.s+e.s 
00032  + "\n--------------------------------------------------\n");//flushing output buffer
00033 };
00034 
00035 int spnfs_connect(int c, const char *user, const char *password){
00036     snd(c,"login",user,password);
00037     int ret = getll(c);
00038     read_csv_string(c); //read also comment
00039     return ret;
00040 };
00041 
00042 int spnfs_disconnect(int c){
00043     snd(c,"bye","quit","exit","ciao"); // ;)
00044     return 0;
00045 };
00046 
00047 int spnfs_new(int c, const char *path){
00048     snd(c,"new",path);
00049     std::string s = getstr(c);
00050     if(s[0]=='O') return 0;
00051     getstr(c); //receive error description
00052     return -1;
00053 };
00054 
00055 int spnfs_open(int c, const char *path){
00056     snd(c,"open",path);
00057     int fid = getll(c);
00058     if(c<0) getstr(c); //receive error desc.
00059     return fid;
00060 };
00061 
00062 int spnfs_read(int c, int fid, void *buf, int len){
00063     snd(c,"read",fid,len);
00064     int retint   =  getll(c);
00065     std::string s = getstr(c);
00066     if(retint>len) retint=len;
00067     if(retint>0) memcpy(buf, s.c_str(), retint);
00068     return retint;
00069 };
00070 
00071 int spnfs_write(int c, int fid, const void *buf, size_t count){
00072     snd(c,"write",fid); write(c,make_csv_string((const char*)buf,count));
00073     count = getll(c);
00074     if(c<0) getstr(c); //receive error desc.
00075     return 0;
00076 };
00077 
00078 long long spnfs_size(int c, const char *path){
00079     snd(c, "size", path);
00080     long long ret = getll(c);
00081     if(ret<0) getstr(c); //receive error desc.
00082     return ret;
00083 };
00084 
00085 int spnfs_seek(int c, int fid, off_t offset, int whence){
00086     snd(c,"seek",fid,offset,whence);
00087     int ret = getll(c);
00088     if(ret<0) getstr(c); //receive erro desc.
00089     return ret;
00090 };
00091 
00092 int spnfs_pos(int c, int fid){
00093     snd(c,"pos",fid);
00094     int ret = getll(c);
00095     if(ret<0) getstr(c); //receive error desc.
00096     return ret;
00097 };
00098 
00099 int spnfs_trunc(int c, int fid){
00100     snd(c,"trunc",fid);
00101     int ret = getll(c);
00102     if(ret!=0) getstr(c); //receive error desc.
00103     return ret;
00104 };
00105 
00106 int spnfs_close(int c, int fid){
00107     snd(c,"close",fid);
00108     std::string s = getstr(c);
00109     if(s[0] == 'O') return 0;
00110     getstr(c); //receive error desc.
00111     return -1;
00112 };
00113 
00114 
00115 
00116 
00117 

Generated on Mon Jan 21 12:09:51 2008 for ZSO - Simple Prototype of Network File System by  doxygen 1.5.4