/[projects]/smsdaemon/plugins/TogPlugin.cpp
ViewVC logotype

Contents of /smsdaemon/plugins/TogPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (show annotations) (download)
Sun Dec 7 20:58:41 2008 UTC (15 years, 5 months ago) by torben
File size: 2226 byte(s)
Refactoring / rename:
        IGsmModem -> ISmsTransceiver
        GsmModem -> ModemTransceiver
        DebugGsmModem -> DebugTransceiver

Move DebugTransceiver to its own files.


1 #include "TogPlugin.h"
2 #include "ISmsTransceiver.h"
3 #include "Sms.h"
4
5 #include "TrainInfo.h"
6 #include "util.h"
7
8 #include <iostream>
9 #include <sstream>
10
11 #include "common.h"
12
13 using namespace std;
14
15
16 TogPlugin::TogPlugin()
17 : Plugin("tog", "Henter tog info fra bane.dk")
18 {
19 _stationInfo["ar"] = StationInfo("AR","�rhus");
20 _stationInfo["la"] = StationInfo("LG","Lang�");
21 _stationInfo["ul"] = StationInfo("UP","Ulstrup");
22 _stationInfo["bj"] = StationInfo("BJ","Bjerringbro");
23 _stationInfo["vi"] = StationInfo("VG","Viborg");
24 _stationInfo["ho"] = StationInfo("H�","H�jslev");
25 _stationInfo["sk"] = StationInfo("SK","Skive");
26 }
27
28 string TogPlugin::GetRealStationCode(string code, string &stationName)
29 {
30 map<string, StationInfo>::iterator it = _stationInfo.find(code);
31
32 if (it != _stationInfo.end())
33 {
34 stationName = (*it).second.name;
35 return (*it).second.code;
36 }
37
38 return "";
39 }
40
41 string TogPlugin::CreateStationList()
42 {
43 ostringstream os;
44
45 os << "code - station\n";
46
47 map<string, StationInfo>::iterator it;
48
49 for (it = _stationInfo.begin(); it != _stationInfo.end(); ++it)
50 {
51 os << (*it).first << " - " << (*it).second.name << "\n";
52 }
53
54 return os.str();
55 }
56
57 void TogPlugin::Execute(ISmsTransceiver& modem, SMS& sms)
58 {
59 string data = sms.ExtractParameters();
60
61 data = Util::str_gsm2latin(data);;
62 data = Util::str_tolower(data);
63
64
65 if (data == "")
66 {
67 modem.SendSms(sms.GetSender(), "Usage: tog <stationskode>\ntog list - liste over stationer", false);
68 return;
69 }
70
71 if (data == "list")
72 {
73 modem.SendSms(sms.GetSender(), CreateStationList(), true);
74 return;
75 }
76
77 string stationName;
78 string code = GetRealStationCode(data, stationName);
79
80 if (code == "")
81 {
82 modem.SendSms(sms.GetSender(), "Unknown station", false);
83 return;
84 }
85
86 vector<TrainInfo> infos;
87 try
88 {
89 infos = GetTrainInfo( code , "" );
90 }
91 catch(std::exception& e)
92 {
93 modem.SendSms(sms.GetSender(), e.what(), false );
94 return;
95 }
96
97 ostringstream os;
98 os << stationName << ":\n";
99
100 for (unsigned int i=0; i< infos.size(); ++i)
101 {
102 TrainInfo& train = infos[i];
103 os << train.time << " ";
104 os << train.destination << " ";
105 os << train.status << " ";
106 os << train.note << "\n";
107 }
108
109 modem.SendSms(sms.GetSender(), os.str(), true);
110
111
112
113 }

  ViewVC Help
Powered by ViewVC 1.1.20