1 // ----------------------------------------------------------------------------
2 // synop.h  --  SYNOP decoding
3 //
4 // Copyright (C) 2012
5 //		Remi Chateauneu, F4ECW
6 //
7 // This file is part of fldigi.
8 //
9 // Fldigi is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // Fldigi is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with fldigi.  If not, see <http://www.gnu.org/licenses/>.
21 // ----------------------------------------------------------------------------
22 
23 #ifndef _SYNOP_H
24 #define _SYNOP_H
25 
26 // This tells how Synop data are serialized.
27 class synop_callback {
28 public:
~synop_callback()29 	virtual ~synop_callback() {} ;
30 
31 	// These methods could as well be pure virtual.
interleaved(void)32 	virtual bool interleaved(void) const { return true; }
33 	virtual void print( const char * str, size_t nb, bool ) const  = 0;
34 	virtual bool log_adif(void) const = 0;
35 	virtual bool log_kml(void) const = 0 ;
36 };
37 
38 
39 // Implementation hidden in synop.cxx
40 class synop {
41 	// When set, the output does not contain Synop sentences but only
42 	// the name of the regular expression which matched. It helps
43 	// for debugging because the output is independent of the locale.
44 	static bool m_test_mode ;
45 public:
46 
47 	static const synop_callback * ptr_callback ;
48 
49 	template< class Callback >
setup()50 	static void setup()
51 	{
52 		static const Callback cstCall = Callback();
53 		ptr_callback = &cstCall ;
54 	};
55 
56 	static synop * instance();
57 
58 	static void regex_usage(void);
59 
~synop()60 	virtual ~synop() {};
61 
62 	// It is used as a global object, the constructor does not do anything.
63 	virtual void init() = 0;
64 
65 	virtual void cleanup() = 0;
66 
67 	/// We should have a tempo as well.
68 	virtual void add(char c) = 0;
69 
70 	// When Synop decoding is disabled.
71 	virtual void flush(bool finish_decoding) = 0;
72 
73 	virtual bool enabled(void) const = 0;
74 
GetTestMode(void)75 	static bool GetTestMode(void) { return m_test_mode ; };
SetTestMode(bool test_mode)76 	static void SetTestMode(bool test_mode) { m_test_mode = test_mode ; };
77 };
78 
79 // gathers the various data files used for Synop decoding.
80 struct SynopDB {
81 	// Loads the files from s given directory.
82 	static bool Init( const std::string & data_dir );
83 
84 	// For testing purpose.
85 	static const std::string & IndicatorToName( int wmo_indicator );
86 	static const std::string IndicatorToCoordinates( int wmo_indicator );
87 
88 	// To Test the reading of our weather stations data files.
89 	static const std::string & BuoyToName( const char * buoy_id );
90 	static const std::string & ShipToName( const char * ship_id );
91 	static const std::string & JCommToName( const char * ship_id );
92 };
93 
94 // ----------------------------------------------------------------------------
95 
96 #endif // _SYNOP_H
97