blob: 4efc285d6e0dbb995ccfa3d37ffa70d7a7da7318 [file] [log] [blame]
shockjianga5ae48c2014-07-27 23:21:41 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
4 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "zone-mgr.hpp"
21
shockjianga5ae48c2014-07-27 23:21:41 -070022namespace ndn {
23namespace ndns {
24
shockjiang99ad3892014-08-03 14:56:13 -070025ZoneMgr::ZoneMgr(Zone& zone)
26 : m_zone(zone)
shockjianga5ae48c2014-07-27 23:21:41 -070027{
28 this->lookupId();
29}
30
shockjiang99ad3892014-08-03 14:56:13 -070031void ZoneMgr::lookupId(const Name& name)
shockjianga5ae48c2014-07-27 23:21:41 -070032{
33 this->open();
shockjiang99ad3892014-08-03 14:56:13 -070034 std::string sql = "SELECT id FROM zones WHERE name=\'" + name.toUri() + "\'";
shockjianga5ae48c2014-07-27 23:21:41 -070035 //sql = "SELECT * FROM ZONES";
shockjiang99ad3892014-08-03 14:56:13 -070036 std::cout << "sql=" << sql << std::endl;
shockjianga5ae48c2014-07-27 23:21:41 -070037 //std::cout<<"*this="<<this<<" m_zone.id="<<m_zone.getId()<<" zoneId="<<&m_zone<<std::endl;
38 this->execute(sql, static_callback_setId, this);
39 //std::cout<<"*this="<<this<<" m_zone.id="<<m_zone.getId()<<" zoneId="<<&m_zone<<std::endl;
40 this->close();
41
42}
shockjiang99ad3892014-08-03 14:56:13 -070043int ZoneMgr::callback_setId(int argc, char **argv, char **azColName)
shockjianga5ae48c2014-07-27 23:21:41 -070044{
45 //Zone zone = this->getZone();
46 this->addResultNum();
47
48 Zone zone = this->m_zone;
49
shockjiang99ad3892014-08-03 14:56:13 -070050 if (argc < 1) {
51 this->setErr("No Zone with Name " + zone.getAuthorizedName().toUri());
shockjianga5ae48c2014-07-27 23:21:41 -070052 return -1;
53 }
54 //std::cout<<"id="<<(uint32_t)std::atoi(argv[0])<<" "<<std::endl;
55 int t1 = std::atoi(argv[0]);
56
shockjianga5ae48c2014-07-27 23:21:41 -070057 m_zone.setId(t1);
58
59 return 0;
60}
shockjiang99ad3892014-08-03 14:56:13 -070061void ZoneMgr::lookupId()
shockjianga5ae48c2014-07-27 23:21:41 -070062{
63 lookupId(this->m_zone.getAuthorizedName());
64}
65
shockjiang99ad3892014-08-03 14:56:13 -070066} //namepsace ndns
67} //namespace ndn
shockjianga5ae48c2014-07-27 23:21:41 -070068