void operator ()(parse_state &state, int argc, char **argv) { state.prog = argv[0]; --argc, ++argv; if(argc == 0) { throw helper{ state.prog }; } std::vector<std::string> args; std::copy(argv, argv + argc, std::back_inserter(args)); auto const end(args.end()); for(auto i(args.begin()); i != end; ++i) { bool read{}; read |= param_help(state, i, end); if(!read) { read |= param_version(state, i, end); } if(!read) { read |= param_verbosity(state, i, end); } if(!read) { read |= param_output(state, i, end); } if(!read) { read |= param_input(state, i, end); } if(!read) { throw invalid_cmdline(state.prog, "unknown argument: " + *i); } } if(state.input_file.empty()) { throw helper{ state.prog }; } if(state.verbose) { std::cout << "input: " << state.input_file << std::endl; } }
Json::Value load_params(const string jsonfile) { //Caricamento parametri utente (da parameters.json) Json::Reader reader; // Oggetto per il parsing: trasforma file.json ---> json::value Json::Value loaded_params; std::ifstream param_input(jsonfile, std::ifstream::binary); //Nuovo oggetto stream in ingresso (associato al file "filename.json") if ( !reader.parse( param_input, loaded_params, true ) ) { // report to the user the failure and their locations in the document. std::cout << "Errore di lettura dal file di configurazione:\n" << reader.getFormattedErrorMessages(); loaded_params.clear(); } else { //Visualizza i parametri appena caricati (e verifica che gli interi non siano nulli o minori di 0!) cout<<"Parametri caricati"<<endl; cout<<"-- ID data --"<<endl; cout<<"MY_VID: 0x"<<hex<< check_not_zero( loaded_params["device"].get("MY_VID",0).asInt() ) <<endl; cout<<"MY_PID: 0x"<<hex<< check_not_zero( loaded_params["device"].get("MY_PID",0).asInt() ) <<endl; cout<<"MY_MAC: "<<loaded_params["device"].get("MY_MAC",0).asString()<<endl; cout<<"Outdoor Temp Local feed id: "<<dec<< check_not_zero( loaded_params["sensors"]["temp"]["ext"].get("lfid",0).asInt() ) <<endl; cout<<"Outdoor Humid Local feed id: "<< check_not_zero( loaded_params["sensors"]["humid"]["ext"].get("lfid",0).asInt() ) <<endl; cout<<"Outdoor Dust Local feed id: "<< check_not_zero( loaded_params["sensors"]["dust"]["ext"].get("lfid",0).asInt() ) <<endl; cout<<"Indoor Temp Local feed id: "<< check_not_zero( loaded_params["sensors"]["temp"]["int"].get("lfid",0).asInt() ) <<endl; cout<<"Indoor Humid Local feed id: "<< check_not_zero( loaded_params["sensors"]["humid"]["int"].get("lfid",0).asInt() ) <<endl; cout<<"-- Precision data --"<<endl; cout<<"Temperature sample rate (sec): "<< check_not_zero( loaded_params["sensors"]["temp"].get("REFRESH_RATE",0).asInt() ) <<endl; cout<<"Humidity sample rate (sec): "<< check_not_zero( loaded_params["sensors"]["humid"].get("REFRESH_RATE",0).asInt() ) <<endl; cout<<"Dust sample rate (sec): "<< check_not_zero( loaded_params["sensors"]["dust"].get("REFRESH_RATE",0).asInt() ) <<endl; cout<<"Server report interval (min): "<< check_not_zero( loaded_params["report"].get("INTERVAL",0).asInt() ) <<endl; cout<<"\tEach sensor will work on num.samples = ("<< loaded_params["report"].get("INTERVAL",0).asInt() <<"*60s)/sample_rate"<<endl; cout<<"Acceptable report validity (%): "<< check_not_zero( loaded_params["report"].get("VALIDITY_PERCENTAGE_THRESHOLD",0).asInt() ) <<"%"<<endl; if(zero_found) { cout<<"WARNING: Some values from configuration are not valid (0 or less). Params cleared!"<<endl; loaded_params.clear(); } zero_found=false; //reset check_not_zero() flag } return loaded_params; //will be empty if loading has failed }
/* * This a QueryPlan Processing function. It is a framework right now. Different * query type can be added. */ void PelotonService::QueryPlan(::google::protobuf::RpcController* controller, const QueryPlanExecRequest* request, QueryPlanExecResponse* response, ::google::protobuf::Closure* done) { // TODO: controller should be set, we probably use it in the future if (controller->Failed()) { std::string error = controller->ErrorText(); LOG_TRACE("PelotonService with controller failed:%s ", error.c_str()); } // If request is not null, this is a rpc call, server should handle the // reqeust if (request != NULL) { LOG_TRACE("Received a queryplan"); if (!request->has_plan_type()) { LOG_ERROR("Queryplan recived desen't have type"); return; } // construct parameter list //int param_num = request->param_num(); std::string param_list = request->param_list(); ReferenceSerializeInput param_input(param_list.c_str(), param_list.size()); std::vector<type::Value> params; //for (int it = 0; it < param_num; it++) { // // TODO: Make sure why varlen_pool is used as parameter // std::shared_ptr<type::VarlenPool> pool(new type::VarlenPool(BACKEND_TYPE_MM)); // Value value_item; // value_item.DeserializeFromAllocateForStorage(param_input, pool.get()); // params.push_back(value_item); //} // construct TupleDesc // std::unique_ptr<tupleDesc> tuple_desc = // ParseTupleDescMsg(request->tuple_dec()); PlanNodeType plan_type = static_cast<PlanNodeType>(request->plan_type()); // TODO: We can add more plan type in this switch to process switch (plan_type) { case PLAN_NODE_TYPE_INVALID: { LOG_ERROR("Queryplan recived desen't have type"); break; } case PLAN_NODE_TYPE_SEQSCAN: { LOG_TRACE("SEQSCAN revieved"); std::string plan = request->plan(); ReferenceSerializeInput input(plan.c_str(), plan.size()); std::shared_ptr<peloton::planner::SeqScanPlan> ss_plan = std::make_shared<peloton::planner::SeqScanPlan>(); ss_plan->DeserializeFrom(input); std::vector<std::unique_ptr<executor::LogicalTile>> logical_tile_list; int tuple_count = peloton::bridge::PlanExecutor::ExecutePlan( ss_plan.get(), params, logical_tile_list); // Return result if (tuple_count < 0) { // ExecutePlan fails LOG_ERROR("ExecutePlan fails"); return; } // Set the basic metadata response->set_tuple_count(tuple_count); response->set_tile_count(logical_tile_list.size()); // Loop the logical_tile_list to set the response std::vector<std::unique_ptr<executor::LogicalTile>>::iterator it; for (it = logical_tile_list.begin(); it != logical_tile_list.end(); it++) { // First materialize logicalTile to physical tile std::unique_ptr<storage::Tile> tile = (*it)->Materialize(); // Then serialize physical tile CopySerializeOutput output_tiles; tile->SerializeTo(output_tiles, tile->GetActiveTupleCount()); // Finally set the response, which be automatically sent back response->add_result(output_tiles.Data(), output_tiles.Size()); // Debug LOG_TRACE("Tile content is: %s", tile->GetInfo().c_str()); } break; } default: { LOG_ERROR("Queryplan recived :: Unsupported TYPE: %u ", plan_type); break; } } // If callback exist, run it if (done) { done->Run(); } } // Here is for the client callback for response else { // Process the response LOG_TRACE("proecess the Query response"); PL_ASSERT(response); UNUSED_ATTRIBUTE int tile_count = response->tile_count(); UNUSED_ATTRIBUTE int result_size = response->result_size(); PL_ASSERT(result_size == tile_count); for (int idx = 0; idx < result_size; idx++) { // Get the tile bytes std::string tile_bytes = response->result(idx); ReferenceSerializeInput tile_input(tile_bytes.c_str(), tile_bytes.size()); // Create a tile or tuple that depends on our protocol. // Tuple is prefered, since it voids copying from tile again // But we should prepare schema before creating tuple/tile. // Can we get the schema from local catalog? // storage::Tile tile; storage::Tuple tuple; // TODO: Make sure why varlen_pool is used as parameter // std::shared_ptr<VarlenPool> var_pool(new VarlenPool(BACKEND_TYPE_MM)); // Tile deserialization. // tile.DeserializeTuplesFrom(tile_input, var_pool); // We should remove tile header or no header when serialize, then use // tuple deserialize tuple.DeserializeWithHeaderFrom(tile_input); // Debug // LOG_TRACE("Recv a tile: %s", tile.GetInfo().c_str()); } } }