tobicore  7.0.0
 All Classes Functions Variables Typedefs Enumerator Friends Groups Pages
TCLanguage.cpp
1 /*
2  Copyright (C) 2009-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
3  Michele Tavella <michele.tavella@epfl.ch>
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef TCLANGUAGE_CPP
20 #define TCLANGUAGE_CPP
21 
22 #include "TCLanguage.hpp"
23 #include "TCTypes.hpp"
24 #include <stdio.h>
25 #include <sstream>
26 #include <string.h>
27 
28 std::string TCLanguage::Status(const int component, const int status,
29  const int fidx) {
30  std::ostringstream stream;
31  stream << "<" << TCSTATUS_ROOTNODE << " " <<
32  TCSTATUS_VERSIONNODE << "=\"" << TCSTATUS_VERSION << "\" " <<
33  TCSTATUS_COMPONENTNODE << "=\"" << component << "\" " <<
34  TCSTATUS_STATUSNODE << "=\"" << status << "\" " <<
35  TCSTATUS_FRAMENODE << "=\"" << fidx << "\"" << "/>";
36  return stream.str();
37 }
38 
39 bool TCLanguage::CheckVersion(const std::string& message) {
40  char version[32];
41  sscanf(message.c_str(), "<%*s version=\"%[^'\"']\" %*s/>", version);
42  return(strcmp(version, TCSTATUS_VERSION) == 0);
43 }
44 
45 bool TCLanguage::IsStatus(const std::string& message, int* component,
46  int* status, int* fidx) {
47 
48  int ret = sscanf(message.c_str(),
49  "<tcstatus %*s component=\"%d\" status=\"%d\" frame=\"%d\"/>",
50  component, status, fidx);
51  return(ret == 3);
52 }
53 
54 #endif