diff --git a/program/Build/RaspberryCloud.sdf b/program/Build/RaspberryCloud.sdf index fc689ef9c000ed498bd0eccd96149902c6b599d0..afc9ac1a73860b5b3cfcceaa5c0292f89122ba9a 100644 Binary files a/program/Build/RaspberryCloud.sdf and b/program/Build/RaspberryCloud.sdf differ diff --git a/program/Build/RaspberryCloud.v12.suo b/program/Build/RaspberryCloud.v12.suo index 96f8b4f1153a378a17093a8ad958187a533169a2..728a0587f480dde5fe1cd0f376e0f45aa5b18244 100644 Binary files a/program/Build/RaspberryCloud.v12.suo and b/program/Build/RaspberryCloud.v12.suo differ diff --git a/program/Build/RaspberryCloud/RaspberryCloud.vcxproj b/program/Build/RaspberryCloud/RaspberryCloud.vcxproj index cdcaf8ea04be812327e1dbe219a391e6d4813211..fb9203755cb3b12cdf36ff2c27cbeb4e97f8f066 100644 --- a/program/Build/RaspberryCloud/RaspberryCloud.vcxproj +++ b/program/Build/RaspberryCloud/RaspberryCloud.vcxproj @@ -89,7 +89,6 @@ <ItemGroup> <ClCompile Include="..\..\Source\app\Application.cpp" /> <ClCompile Include="..\..\Source\app\UI.cpp" /> - <ClCompile Include="..\..\Source\cache\BasicCache.cpp" /> <ClCompile Include="..\..\Source\cache\FIFOCache.cpp" /> <ClCompile Include="..\..\Source\cache\LFUCache.cpp" /> <ClCompile Include="..\..\Source\cache\LRUCache.cpp" /> @@ -123,7 +122,6 @@ <ItemGroup> <ClInclude Include="..\..\Source\app\Application.h" /> <ClInclude Include="..\..\Source\app\UI.h" /> - <ClInclude Include="..\..\Source\cache\BasicCache.h" /> <ClInclude Include="..\..\Source\cache\Cache.h" /> <ClInclude Include="..\..\Source\cache\CacheFile.h" /> <ClInclude Include="..\..\Source\cache\FIFOCache.h" /> diff --git a/program/Build/RaspberryCloud/RaspberryCloud.vcxproj.filters b/program/Build/RaspberryCloud/RaspberryCloud.vcxproj.filters index c5fe3838bc9c9303a9218b94e89444897835c2bb..8deec8fefe4d177adabf27bd2c8d384a1b3f662f 100644 --- a/program/Build/RaspberryCloud/RaspberryCloud.vcxproj.filters +++ b/program/Build/RaspberryCloud/RaspberryCloud.vcxproj.filters @@ -156,9 +156,6 @@ <ClCompile Include="..\..\Source\cache\FIFOCache.cpp"> <Filter>Source Files\cache</Filter> </ClCompile> - <ClCompile Include="..\..\Source\cache\BasicCache.cpp"> - <Filter>Source Files\cache</Filter> - </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\Source\app\UI.h"> @@ -269,9 +266,6 @@ <ClInclude Include="..\..\Source\cache\Cache.h"> <Filter>Header Files\cache</Filter> </ClInclude> - <ClInclude Include="..\..\Source\cache\BasicCache.h"> - <Filter>Header Files\cache</Filter> - </ClInclude> <ClInclude Include="..\..\Source\cache\CacheFile.h"> <Filter>Header Files\cache</Filter> </ClInclude> diff --git a/program/Source/app/Application.cpp b/program/Source/app/Application.cpp index 1e93aae58cad4606ef8a941a0af2476a0dcb44dc..77aac8cef947a66b8837a360693a497a26b02983 100644 --- a/program/Source/app/Application.cpp +++ b/program/Source/app/Application.cpp @@ -1,4 +1,5 @@ #include <string.h> +#include <ctime> #include "../logger/Logger.h" #include "Application.h" #include "../cloud/LocalCloudAdapter.h" @@ -32,7 +33,7 @@ const string Application::SERVER = "server"; * Requests commands from the user and sends them to the UI */ -int main(int argc, char **argv) { +int main2(int argc, char **argv){ LOG_ENTER_EXIT; Application application; @@ -62,10 +63,10 @@ int main(int argc, char **argv) { } } - application.cfs.getEncoder()->setFolders(dataFolder,fragFolder); - application.cfs.getDecoder()->setFolders(dataFolder,fragFolder); + application.cfs.getEncoder()->setFolders(dataFolder, fragFolder); + application.cfs.getDecoder()->setFolders(dataFolder, fragFolder); application.cfs.setFolders(fragFolder); - + bool waitAnswer = true; Cache *cacheToSetup; while (waitAnswer){ @@ -76,24 +77,24 @@ int main(int argc, char **argv) { int cacheSize = 3; switch (answer){ - case 1: - cacheToSetup = new NoCache(); - waitAnswer = false; - break; - case 2: - cacheToSetup = new FIFOCache(cacheSize); - waitAnswer = false; - break; - case 3: - cacheToSetup = new LRUCache(cacheSize); - waitAnswer = false; - break; - case 4: - cacheToSetup = new LFUCache(cacheSize); - waitAnswer = false; - break; - default: - break; + case 1: + cacheToSetup = new NoCache(); + waitAnswer = false; + break; + case 2: + cacheToSetup = new FIFOCache(cacheSize); + waitAnswer = false; + break; + case 3: + cacheToSetup = new LRUCache(cacheSize); + waitAnswer = false; + break; + case 4: + cacheToSetup = new LFUCache(cacheSize); + waitAnswer = false; + break; + default: + break; } } @@ -132,7 +133,7 @@ int main(int argc, char **argv) { cout << "Welcome to the amazing RaspberryCloud application" << endl; cout << "=================================================" << endl << endl; cout << "Setting up system" << endl; - + while (true){ cout << "Please set home network behaviour (pi/client)" << endl; string answer = ""; @@ -145,7 +146,7 @@ int main(int argc, char **argv) { application.ui.setComputeOnPi(false); break; } - } + } cout << "To list avaliable orders enter \"help\"." << endl; @@ -186,14 +187,15 @@ int main(int argc, char **argv) { ReturnableFile returned = application.ui.getFile(fileDesc); if (returned.isValid()) { cout << "Successfully downloaded: " << returned.getLocalFileId() << endl; - } else { + } + else { cout << "ERROR with getting: " << returned.getLocalFileId() << endl << returned.getErrorMessage() << endl; - } + } } else if (command == "getFileList"){ list<FileDescriptor*>* fileTree = application.ui.getFileTree(); cout << "fileTree has " << fileTree->size() << " file(s)." << endl; - for(FileDescriptor* fileD : *fileTree) + for (FileDescriptor* fileD : *fileTree) { cout << fileD->getFileID() << endl; for (Fragment f : fileD->getFragments()){ @@ -235,6 +237,105 @@ int main(int argc, char **argv) { cout << "Invalid command." << endl; } } + + return 0; +} + +void addFile(Application& application, string localid, string destid) { + cout << application.ui.addFile(localid, destid) << endl; +} + +void getFile(Application& application, string fileid) { + FileDescriptor fileDesc = FileDescriptor(fileid); + ReturnableFile returned = application.ui.getFile(fileDesc); + if (returned.isValid()) { + cout << "Successfully downloaded: " << returned.getLocalFileId() << endl; + } + else { + cout << "ERROR with getting: " << returned.getLocalFileId() << endl << returned.getErrorMessage() << endl; + } +} + +void getFileList(Application& application) { + list<FileDescriptor*>* fileTree = application.ui.getFileTree(); + cout << "fileTree has " << fileTree->size() << " file(s)." << endl; + for (FileDescriptor* fileD : *fileTree) + { + cout << fileD->getFileID() << endl; + for (Fragment f : fileD->getFragments()){ + cout << f.getCloudFileID() << endl; + cout << f.getCloudId() << endl; + } + } +} + +void deleteFile(Application& application, string fileid) { + FileDescriptor fileDesc = FileDescriptor(fileid); + cout << application.ui.deleteFile(fileDesc) << endl; +} + +int test1(){ + Application application; + + application.cm.addCloud(make_shared<LocalCloudAdapter>()); + application.cm.addCloud(make_shared<DropboxAdapter>()); + application.cm.addCloud(make_shared<FTPAdapter>()); + + string dataFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\data\\"; + string fragFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\temp\\"; + string cloudFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\cloud\\"; + string cacheFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\cache\\"; + + application.cfs.getEncoder()->setFolders(dataFolder, fragFolder); + application.cfs.getDecoder()->setFolders(dataFolder, fragFolder); + application.cfs.setFolders(fragFolder); + + Cache *cacheToSetup; + + int cacheSize = 3; + //cacheToSetup = new NoCache(); + cacheToSetup = new FIFOCache(cacheSize); + //cacheToSetup = new LRUCache(cacheSize); + //cacheToSetup = new LFUCache(cacheSize); + + application.cfs.setCache(cacheToSetup); + application.cfs.getCache()->setFolders(cacheFolder, dataFolder); + application.cfs.getCache()->readCache(); + + application.hnc.setDataFolder(dataFolder); + + for (auto ca : application.cm.getCloudList()){ + ca->setFolders(cloudFolder, fragFolder); + } + + application.ui.setComputeOnPi(false); + + double elapsed_secs = 0; + clock_t begin = clock(); + + + addFile(application, "1.html", "1h"); + addFile(application, "2.html", "2h"); + addFile(application, "3.html", "3h"); + + deleteFile(application, "1.html"); + deleteFile(application, "2.html"); + deleteFile(application, "3.html"); + + application.cfs.getCache()->clearCache(); + + clock_t end = clock(); + elapsed_secs += double(end - begin); + cout.precision(15); + cout << "Spent time:" << elapsed_secs << endl; + + + int i; + cin >> i; return 0; } + +int main(int argc, char **argv) { + return test1(); +} \ No newline at end of file diff --git a/program/Source/cache/Cache.h b/program/Source/cache/Cache.h index a02c9c9a4d27e4653978ebf24ec3b6cdfd0a7983..d71a818505c6389a2eb50971ffc4f8f35d616165 100644 --- a/program/Source/cache/Cache.h +++ b/program/Source/cache/Cache.h @@ -40,6 +40,16 @@ public: virtual bool addFile(std::string localFileID) = 0; virtual void readCache() = 0; + + void clearCache() { + for (int i = 0; i < maxSize; i++) { + if (files[i].getFileId() != "") { + string spath = cacheFolder + files[i].getFileId(); + const char* path = spath.c_str(); + int res = remove(path); + } + } + } }; #endif //_CACHE_H \ No newline at end of file