SectorZone: add attribute arc_boundary
[xcsoar.git] / src / FLARM / Glue.cpp
bloba898a06192685c6b6aeb82e05611fcf244c5ed81
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "Glue.hpp"
25 #include "Global.hpp"
26 #include "TrafficDatabases.hpp"
27 #include "FlarmDetails.hpp"
28 #include "FlarmNetReader.hpp"
29 #include "NameFile.hpp"
30 #include "Friends.hpp"
31 #include "Components.hpp"
32 #include "MergeThread.hpp"
33 #include "IO/DataFile.hpp"
34 #include "IO/TextWriter.hpp"
35 #include "Profile/FlarmProfile.hpp"
36 #include "LogFile.hpp"
38 /**
39 * Loads the FLARMnet file
41 static void
42 LoadFLARMnet(FlarmNetDatabase &db)
44 NLineReader *reader = OpenDataTextFileA(_T("data.fln"));
45 if (reader == NULL)
46 return;
48 unsigned num_records = FlarmNetReader::LoadFile(*reader, db);
49 delete reader;
51 if (num_records > 0)
52 LogFormat("%u FLARMnet ids found", num_records);
55 /**
56 * Opens XCSoars own FLARM details file, parses it and
57 * adds its entries as FlarmLookupItems
58 * @see AddSecondaryItem
60 static void
61 LoadSecondary(FlarmNameDatabase &db)
63 LogFormat("OpenFLARMDetails");
65 TLineReader *reader = OpenDataTextFile(_T("xcsoar-flarm.txt"));
66 if (reader != NULL) {
67 LoadFlarmNameFile(*reader, db);
68 delete reader;
72 void
73 LoadFlarmDatabases()
75 if (traffic_databases != nullptr)
76 return;
78 traffic_databases = new TrafficDatabases();
80 /* the MergeThread must be suspended, because it reads the FLARM
81 databases */
82 merge_thread->Suspend();
84 LoadSecondary(traffic_databases->flarm_names);
85 LoadFLARMnet(traffic_databases->flarm_net);
86 Profile::Load(traffic_databases->flarm_colors);
88 merge_thread->Resume();
91 void
92 SaveFlarmColors()
94 if (traffic_databases != nullptr)
95 Profile::Save(traffic_databases->flarm_colors);
98 /**
99 * Saves XCSoars own FLARM details into the
100 * corresponding file (xcsoar-flarm.txt)
102 static void
103 SaveSecondary(FlarmNameDatabase &flarm_names)
105 TextWriter *writer = CreateDataTextFile(_T("xcsoar-flarm.txt"));
106 if (writer == NULL)
107 return;
109 SaveFlarmNameFile(*writer, flarm_names);
110 delete writer;
113 void
114 SaveFlarmNames()
116 if (traffic_databases != nullptr)
117 SaveSecondary(traffic_databases->flarm_names);
120 void
121 DeinitTrafficGlobals()
123 delete traffic_databases;
124 traffic_databases = nullptr;