void CityLamp::SendOfflineCmdToPCClient(u_short lampid) { char buf[7]; buf[0] = 0x5A; buf[1] = 0x06; char* pid = (char*)&lampid; buf[2] = pid[0]; buf[3] = pid[1]; buf[4] = 0xFF; buf[5] = 0x00; buf[6] = 0x00; AddCheckSum(buf, sizeof(buf)); SendDataToPCClient(buf, sizeof(buf)); }
void CityLamp::SendOnlineCmdToPCClient() { char buf[7]; MutexGuard guard(LampID2LampMutexSocketMapMutex); map<u_short, LPLampMutexSockStruct>::iterator map_it = LampID2LampMutexSockMap.begin(); while (map_it != LampID2LampMutexSockMap.end()) { u_short lampid = map_it->first; buf[0] = 0x5A; buf[1] = 0x06; char* pid = (char*)&lampid; buf[2] = pid[0]; buf[3] = pid[1]; buf[4] = 0xFE; buf[5] = 0x00; buf[6] = 0x00; AddCheckSum(buf, sizeof(buf)); SendDataToPCClient(buf, sizeof(buf)); ++map_it; } }
std::string WorkSpace::Respond(const std::string& query) { const char* cquery = query.c_str(); std::cmatch match; try { if ( std::regex_match( cquery, match, std::regex("\\s*") ) ) { return query; } else if ( std::regex_match( cquery, match, std::regex("\\s*check\\s+file\\s+(.+)\\s*") ) ) { if (access(std::string(match[1]).c_str(), F_OK ) == -1) { throw FIException(142142, "File with name " + std::string(match[1]) + " does not exits."); } if (CheckFile(match[1])) { return "File hasn't changed."; } else { return "File has changed."; } } else if ( std::regex_match( cquery, match, std::regex("\\s*add\\s+file\\s+(.+)\\s*") ) ) { if (access(std::string(match[1]).c_str(), F_OK ) == -1) { throw FIException(171142, "File with name " +std::string(match[1]) + " does not exits."); } pthread_mutex_lock(&m); AddFileToInotify(std::string(match[1])); // inotify_add_watch(inotify, std::string(match[1]).c_str(), IN_ALL_EVENTS); AddCheckSum(match[1]); pthread_mutex_unlock(&m); } else if ( std::regex_match( cquery, match, std::regex("\\s*delete\\s+file\\s+(.+)\\s*") ) ) { pthread_mutex_lock(&m); int wd = ind_by_files_table.Select(std::string(match[1])); logger << wd; ind_by_files_table.Delete(std::string(match[1])); files_by_ind_table.Delete(wd); checksum_table.Delete(std::string(match[1])); inotify_rm_watch(inotify, wd); pthread_mutex_unlock(&m); } else if ( std::regex_match( cquery, match, std::regex("\\s*update\\s+file\\s+(.+)\\s*") ) ) { if (access(std::string(match[1]).c_str(), F_OK ) == -1) { throw FIException(171142, "File with name " + std::string(match[1]) + " does not exits."); } AddCheckSum(match[1]); return "Ok"; } else if ( std::regex_match( cquery, match, std::regex("\\s*add\\s+files\\s+(.+)\\s*") ) ) { ExecuteHandler ex(" find / | grep -E \'" + std::string(match[1]) + "\'"); std::string file_name; std::string files; while (ex >> file_name) { files += file_name + " : " + Respond("add file " + file_name) + "\n"; } return files; } else if ( std::regex_match( cquery, match, std::regex("\\s*help\\s*") ) ) { return std::string("Queries:\n") +"\tadd file <filename>\n" + "\tdelete file <filename>\n" + "\tcheck file <filname>\n" + "\tupdate file <filename>\n" + "\tadd files <regexp>"; } else { return "Incorrent query."; } } catch (std::exception& e) {