libdballe 5.10
|
00001 /* 00002 * Copyright (C) 2005--2011 ARPA-SIM <urpsim@smr.arpa.emr.it> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License. 00007 * 00008 * This program is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 * GNU General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU General Public License 00014 * along with this program; if not, write to the Free Software 00015 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00016 * 00017 * Author: Enrico Zini <enrico@enricozini.com> 00018 */ 00019 00020 #ifndef PROCESSOR_H 00021 #define PROCESSOR_H 00022 00023 #include <dballe/core/rawmsg.h> 00024 #include <dballe/msg/codec.h> 00025 #include <popt.h> 00026 00027 namespace wreport { 00028 struct Bulletin; 00029 } 00030 00031 namespace dballe { 00032 struct Rawmsg; 00033 struct Msgs; 00034 struct Matcher; 00035 00036 namespace cmdline { 00037 00038 struct Item 00039 { 00040 unsigned idx; 00041 Rawmsg* rmsg; 00042 wreport::Bulletin* bulletin; 00043 Msgs* msgs; 00044 00045 Item(); 00046 ~Item(); 00047 00049 void decode(msg::Importer& imp, bool print_errors=false); 00050 00052 void set_msgs(Msgs* new_msgs); 00053 }; 00054 00055 struct Action 00056 { 00057 virtual ~Action() {} 00058 virtual void operator()(const Item& item) = 0; 00059 }; 00060 00061 struct Filter 00062 { 00063 msg::Exporter::Options export_opts; 00064 int category; 00065 int subcategory; 00066 int checkdigit; 00067 int unparsable; 00068 int parsable; 00069 const char* index; 00070 Matcher* matcher; 00071 00072 Filter(); 00073 ~Filter(); 00074 00076 void matcher_from_args(poptContext optCon); 00077 00078 bool match_index(int idx) const; 00079 bool match_common(const Rawmsg& rmsg, const Msgs* msgs) const; 00080 bool match_msgs(const Msgs& msgs) const; 00081 bool match_bufrex(const Rawmsg& rmsg, const wreport::Bulletin* rm, const Msgs* msgs) const; 00082 bool match_bufr(const Rawmsg& rmsg, const wreport::Bulletin* rm, const Msgs* msgs) const; 00083 bool match_crex(const Rawmsg& rmsg, const wreport::Bulletin* rm, const Msgs* msgs) const; 00084 bool match_aof(const Rawmsg& rmsg, const Msgs* msgs) const; 00085 bool match_item(const Item& item) const; 00086 }; 00087 00088 class Reader 00089 { 00090 protected: 00091 void read_csv(poptContext optCon, Action& action); 00092 void read_file(poptContext optCon, Action& action); 00093 00094 public: 00095 const char* input_type; 00096 msg::Importer::Options import_opts; 00097 Filter filter; 00098 00099 Reader(); 00100 00101 void read(poptContext optCon, Action& action); 00102 }; 00103 00104 #if 0 00105 void process_all(poptContext optCon, 00106 Encoding type, 00107 struct Filter* grepdata, 00108 Action& action); 00109 #endif 00110 00111 #if 0 00112 void process_csv(poptContext optCon, 00113 struct Filter* grepdata, 00114 Action& action); 00115 #endif 00116 00117 } // namespace cmdline 00118 } // namespace dballe 00119 00120 #endif