From b9b79d9eb38bd08bd4a42228172c954e07aa10b0 Mon Sep 17 00:00:00 2001
From: srsdanny <seres.dani@gmail.com>
Date: Tue, 8 Dec 2015 17:25:26 +0100
Subject: [PATCH] Minor changes to networking

---
 program/Build/RaspberryCloud/RaspberryCloud.vcxproj  |  2 --
 .../RaspberryCloud/RaspberryCloud.vcxproj.filters    |  6 ------
 program/Source/app/Application.cpp                   |  8 ++++++--
 program/Source/networking/FileServerConnection.cpp   |  4 ++--
 .../Source/networking/HomeNetworkCommunications.cpp  | 12 ++++++++----
 program/Source/networking/NetworkHelperMethods.h     |  9 +++++----
 6 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/program/Build/RaspberryCloud/RaspberryCloud.vcxproj b/program/Build/RaspberryCloud/RaspberryCloud.vcxproj
index cdcaf8ea..fb920375 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 c5fe3838..8deec8fe 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 1e93aae5..cadc08e0 100644
--- a/program/Source/app/Application.cpp
+++ b/program/Source/app/Application.cpp
@@ -60,6 +60,10 @@ int main(int argc, char **argv) {
 		{
 			cloudFolder.assign(argv[i] + 2);
 		}
+		else if (strncmp(argv[i], "-C", 2) == 0)
+		{
+			cacheFolder.assign(argv[i] + 2);
+		}
 	}
 
 	application.cfs.getEncoder()->setFolders(dataFolder,fragFolder);
@@ -161,7 +165,7 @@ int main(int argc, char **argv) {
 			cout << "To get the avaliable files   enter \"getFileList\"." << endl;
 			cout << "To delete a file             enter \"deleteFile\"." << endl;
 			cout << "To authorize a cloud adapter enter \"authCA\"." << endl;
-			cout << "To start or stop the server  enter \"serverCfg\"." << endl;
+			cout << "To start or stop the server  enter \"server\"." << endl;
 		}
 		else if (command == "addFile"){
 			cout << "Adding file. Please enter local file id" << endl;
@@ -216,7 +220,7 @@ int main(int argc, char **argv) {
 			cin >> cloudAdapterId;
 			application.ui.authCloudAdapter(cloudAdapterId);
 		}
-		else if (command == "serverCfg")
+		else if (command == "server")
 		{
 			string startOrStop;
 			cout << "Start or stop server?" << endl;
diff --git a/program/Source/networking/FileServerConnection.cpp b/program/Source/networking/FileServerConnection.cpp
index 08233bff..82a38329 100644
--- a/program/Source/networking/FileServerConnection.cpp
+++ b/program/Source/networking/FileServerConnection.cpp
@@ -18,7 +18,7 @@ void FileServerConnection::run()
 	char buffer[100000];
 	string fileName;
 
-	int msgType;
+	char msgType;
 	int fileNameSize;
 	long long fileSize;
 
@@ -51,7 +51,7 @@ void FileServerConnection::run()
 
 		// Send file
 		fileSize = getFileSize(file);
-		socket().sendBytes(&OK_ANS, sizeof(OK_ANS));
+		socket().sendBytes(&FILE_ANS, sizeof(FILE_ANS));
 		socket().sendBytes(&fileSize, sizeof(fileSize));
 		while (file)
 		{
diff --git a/program/Source/networking/HomeNetworkCommunications.cpp b/program/Source/networking/HomeNetworkCommunications.cpp
index 7762b441..fc9f4891 100644
--- a/program/Source/networking/HomeNetworkCommunications.cpp
+++ b/program/Source/networking/HomeNetworkCommunications.cpp
@@ -32,10 +32,14 @@ bool HomeNetworkCommunications::addFileRemote(string fileID)
 	LOG_ENTER_EXIT;
 
 	refresh();
-	if (!piAvaliable) 
+	if (!piAvaliable)
+	{
+		cout << "Server not available" << endl;
 		return false;
+	}
+		
 	
-	int msgType;
+	char msgType;
 	int fileNameSize = fileID.size();
 
 	// Open file, check if exists
@@ -87,7 +91,7 @@ ReturnableFile HomeNetworkCommunications::getFileRemote(string fileID)
 		return result;
 	}
 	
-	int msgType;
+	char msgType;
 	int fileNameSize = fileID.size();
 	long long fileSize;
 
@@ -102,7 +106,7 @@ ReturnableFile HomeNetworkCommunications::getFileRemote(string fileID)
 
 	// Get server answer
 	socket.receiveBytes(&msgType, sizeof(msgType));
-	if (msgType != OK_ANS)
+	if (msgType != FILE_ANS)
 	{
 		result.setErrorMessage("Serverside error");
 		return result;
diff --git a/program/Source/networking/NetworkHelperMethods.h b/program/Source/networking/NetworkHelperMethods.h
index 4ff11d99..42b886a6 100644
--- a/program/Source/networking/NetworkHelperMethods.h
+++ b/program/Source/networking/NetworkHelperMethods.h
@@ -7,10 +7,11 @@
 
 const int UDP_PORT = 42420;
 const int TCP_PORT = 42421;
-const int GET_CMD = 100;
-const int PUT_CMD = 101;
-const int OK_ANS = 200;
-const int ERR_ANS = 201;
+const char GET_CMD = 100;
+const char PUT_CMD = 101;
+const char FILE_ANS = 200;
+const char OK_ANS = 201;
+const char ERR_ANS = 202;
 
 inline long long getFileSize(std::ifstream& file)
 {
-- 
GitLab