device/hcnetdisk.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
device/include/netdisk.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
device/include/netdisk_factory.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
device/netdisk_factory.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
device/test.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
service/Makefile | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
service/netdisk_service | 补丁 | 查看 | 原始文档 | blame | 历史 | |
service/netdisk_service.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
service/request_handler.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
service/test | 补丁 | 查看 | 原始文档 | blame | 历史 | |
service/test.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
device/hcnetdisk.c
@@ -71,8 +71,8 @@ port = loginInfo.port; startChannel = struDeviceInfo.struDeviceV30.byStartDChan; maxChannels = struDeviceInfo.struDeviceV30.byIPChanNum + struDeviceInfo.struDeviceV30.byHighDChanNum * 256; deviceInfo.startChannel = struDeviceInfo.struDeviceV30.byStartDChan; deviceInfo.maxChannels = struDeviceInfo.struDeviceV30.byIPChanNum + struDeviceInfo.struDeviceV30.byHighDChanNum * 256; return 0; } device/include/netdisk.h
@@ -34,12 +34,17 @@ class Netdisk { private: std::string loginDataFile; struct DeviceInfo { int startChannel; //起始通道号 int maxChannels; //最大通道数 }; protected: int startChannel; //起始通道号 int maxChannels; //最大通道数 DeviceInfo deviceInfo; std::string deviceType; //设备类型 std::string loginUUID; std::string username; //用户名 @@ -67,9 +72,7 @@ virtual int downloadByTime(Netdisk_DownloadRequest &request, std::vector<std::string> *files) = 0; int getStartChannel() {return startChannel;} int getMaxChannels() {return maxChannels;} DeviceInfo getDeviceInfo() {return deviceInfo;} }; device/include/netdisk_factory.h
New file @@ -0,0 +1,9 @@ #ifndef __NETDISK_FACTORY_H__ #define __NETDISK_FACTORY_H__ #include "netdisk.h" class NetdiskFacotory { public: static Netdisk *create(std::string deviceType); }; #endif device/netdisk_factory.c
New file @@ -0,0 +1,12 @@ #include "netdisk_factory.h" Netdisk *NetdiskFacotory::create(std::string deviceType) { if(deviceType == "HC") { // std::cout << "new HCNetdisk" << std::endl; return new HCNetdisk(); } else { err_msg(0, "无法识别的设备类型: %s", deviceType.c_str()); return NULL; } } device/test.c
@@ -18,7 +18,7 @@ loginInfo.password = "a1234567"; netdisk->login(loginInfo); std::cout << "起始通道:" << netdisk->getStartChannel() << ", 最大通道号:" << netdisk->getMaxChannels() << std::endl; //std::cout << "起始通道:" << netdisk->getStartChannel() << ", 最大通道号:" << netdisk->getMaxChannels() << std::endl; //下载 service/Makefile
@@ -18,7 +18,7 @@ test_properties: properties_config.c netdisk_service: $(ROOT)/device/hcnetdisk.c login_store.c request_handler.c properties_config.c netdisk_service: $(ROOT)/device/hcnetdisk.c $(ROOT)/device/netdisk_factory.c login_store.c request_handler.c properties_config.c test: $(ROOT)/device/hcnetdisk.c service/netdisk_serviceBinary files differ
service/netdisk_service.c
@@ -4,14 +4,13 @@ #include "login_store.h" #include "request_handler.h" #include "properties_config.h" #include "netdisk_factory.h" #include <jsoncpp/json/json.h> #include <nng/nng.h> #include <nng/protocol/reqrep0/rep.h> #include <nng/protocol/reqrep0/req.h> using namespace std; static int work(Netdisk_DownloadRequest drequest); static int connectAndSend(const char *url, char * str); @@ -23,7 +22,7 @@ PropertiesConfig config("../data/config.txt"); SafeQueue<Netdisk_DownloadRequest> task_queue(10); SafeQueue<Netdisk_DownloadRequest> task_queue(100); std::map<std::string, Netdisk *> userDeviceMap; @@ -78,14 +77,12 @@ Netdisk_LoginInfo loginInfo = loginStore.getLoginInfo(drequest.loginUUID); if (netdisk == NULL) { if(loginInfo.deviceType == "HC") { // std::cout << "new HCNetdisk" << std::endl; netdisk = new HCNetdisk(); netdisk = NetdiskFacotory::create(loginInfo.deviceType); if(netdisk != NULL) { userDeviceMap.insert({loginInfo.loginUUID, netdisk}); } else { err_msg(0, "无法识别的设备类型: %s", loginInfo.deviceType.c_str()); } } @@ -162,14 +159,7 @@ } else { std::cerr << "Don't support " << method << std::endl; } // if (method == "login") { // handleLogin(sock, request); // } else if (method == "downloadByTime") { // handleDownloadByTimeAsync(sock, request); // } else { // std::cerr << "Don't support " << method << std::endl; // } // Unrecognized command, so toss the buffer. nng_free(buf, sz); } } service/request_handler.c
@@ -1,4 +1,5 @@ #include "request_handler.h" #include "netdisk_factory.h" extern SafeQueue<Netdisk_DownloadRequest> task_queue; @@ -34,10 +35,10 @@ if( userDeviceIter != userDeviceMap.end() ) { netdisk = userDeviceIter->second; } if (netdisk == NULL) { if(loginInfo.deviceType == "HC") { // std::cout << "new HCNetdisk" << std::endl; netdisk = new HCNetdisk(); netdisk = NetdiskFacotory::create(loginInfo.deviceType); if(netdisk != NULL) { userDeviceMap.insert({loginInfo.loginUUID, netdisk}); } else { err_msg(0, "无法识别的设备类型: %s", loginInfo.deviceType.c_str()); @@ -47,7 +48,7 @@ code = netdisk->login(loginInfo); if (code == 0) { loginStore.saveLoginInfo(loginInfo); std::cout << "起始通道:" << netdisk->getStartChannel() << ", 最大通道号:" << netdisk->getMaxChannels() << std::endl; std::cout << "起始通道:" << netdisk->getDeviceInfo().startChannel << ", 最大通道号:" << netdisk->getDeviceInfo().maxChannels << std::endl; } @@ -150,13 +151,11 @@ Netdisk_LoginInfo loginInfo = loginStore.getLoginInfo(drequest.loginUUID); if (netdisk == NULL) { if(loginInfo.deviceType == "HC") { // std::cout << "new HCNetdisk" << std::endl; netdisk = new HCNetdisk(); netdisk = NetdiskFacotory::create(loginInfo.deviceType); if(netdisk != NULL) { userDeviceMap.insert({loginInfo.loginUUID, netdisk}); } else { err_msg(0, "无法识别的设备类型: %s", loginInfo.deviceType.c_str()); } } service/testBinary files differ
service/test.c
@@ -19,7 +19,7 @@ loginInfo.password = "a1234567"; netdisk->login(loginInfo); std::cout << "起始通道:" << netdisk->getStartChannel() << ", 最大通道号:" << netdisk->getMaxChannels() << std::endl; //std::cout << "起始通道:" << netdisk->getStartChannel() << ", 最大通道号:" << netdisk->getMaxChannels() << std::endl; //下载