ReadDirectory.cpp

См. документацию.
00001 /*
00002  * ReadDirectory.cpp
00003  *
00004  *  Created on: 19.04.2011
00005  *      Author: nick
00006  */
00007 
00008 #include "ReadDirectory.h"
00009 #define debug_output
00010 void ReadDirectory::handleTag(TagIQ &tag){
00011    ReadDir rd(tag);//= new ReadDir(tag);
00012    #ifdef debug_output
00013    std::cout<<"Read Dir IQ Handler from:"<<rd.getPath()<<endl;
00014    #endif
00015    if(rd.getType()==TagIQ::Get){
00016            #ifdef debug_output
00017            std::cout<<"OK GET"<<endl;
00018            #endif
00019            //Путь по которому надо получить файлы
00020            //const char* dpath=(sc->getSharedDir()+rd.getPath()).c_str();
00021            string dpath=sc->getSharedDir()+rd.getPath();
00022            #ifdef debug_output
00023            std::cout<<"PATH GET ok"<<dpath<<endl;
00024            #endif
00025            DIR* d=opendir(dpath.c_str());
00026            #ifdef debug_output
00027            std::cout<<"oPENdIR ok"<<endl;
00028            #endif
00029            dirent* de=readdir(d);
00030            //TODO Если тут все хорошо и имя файла получили!, если нет надо сформировать ошибку
00031            #ifdef debug_output
00032            cout<<"READ DIR ok"<<endl;
00033            #endif
00034            ReadDir rdresp(protocol->getCurNodeSend() ,"server",rd.getFrom(),TagIQ::Result,rd.getID());
00035            #ifdef debug_output
00036            cout<<"MK RESP OK"<<endl;
00037            #endif
00038            while(de!=NULL){
00039                #ifdef debug_output
00040                    cout<<"ADD FILENAME"<<endl;
00041                #endif
00042                    rdresp.addFilename(de->d_name);
00043                #ifdef debug_output
00044                    cout<<"ADD FILENAME OK"<<endl;
00045                #endif
00046                    //cout<<"file:"<<de->d_name<<endl;
00047                    de=readdir(d);
00048                #ifdef debug_output
00049                    cout<<"READ DIR ok 2"<<endl;
00050                #endif
00051            }
00052            closedir(d);
00053            #ifdef debug_output
00054            std::cout<<"Read Dir send response:"<<endl;
00055            #endif
00056            protocol->sendNode(rdresp);
00058            #ifdef debug_output
00059            std::cout<<"Read Dir sended response:"<<endl;
00060            #endif
00061            //delete rdresp;
00062          //  cout<<"rdresp deleted"<<endl;
00063    }
00064    //delete rd;
00065    //cout<<"rd deleted"<<endl;
00066 }
00067 
00068 ReadDirectory::ReadDirectory(Protocol &protocol,ServerConfig* sc) {
00069         // TODO Auto-generated constructor stub
00070     #ifdef debug_output
00071         cout<<"=== ReaddDirectory ==="<<endl;
00072     #endif
00073         this->protocol=&protocol;
00074         this->sc=sc;
00075         protocol.addIQHandler(this,ReadDir_xmlns);
00076 }
00077 ReadDirectory::ReadDirectory(){
00078 
00079 }
00080 ReadDirectory::~ReadDirectory() {
00081         // TODO Auto-generated destructor stub
00082     this->protocol->removeIQHandler(this);
00083 }