blob: 98ce9578feb03e829c1134dc933811b9dfda1aa2 [file] [log] [blame]
Yingdi Yu4390ce52013-10-10 17:27:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
11#include "profile-data.h"
Yingdi Yu92e8e482013-10-17 21:13:03 -070012
Yingdi Yufa4ce792014-02-06 18:09:22 -080013#include "logging.h"
Yingdi Yu4390ce52013-10-10 17:27:54 -070014
Yingdi Yu4390ce52013-10-10 17:27:54 -070015using namespace ndn;
Yingdi Yub4be64a2013-10-13 17:24:50 -070016using namespace std;
Yingdi Yu4390ce52013-10-10 17:27:54 -070017
Yingdi Yu92e8e482013-10-17 21:13:03 -070018INIT_LOGGER("ProfileData");
19
Yingdi Yufa4ce792014-02-06 18:09:22 -080020namespace chronos{
21
Yingdi Yu76dd8002013-12-24 11:16:32 +080022ProfileData::ProfileData()
23 : Data()
24{}
25
Yingdi Yu2e3199c2013-11-06 18:42:34 -080026ProfileData::ProfileData(const Profile& profile)
Yingdi Yu4390ce52013-10-10 17:27:54 -070027 : Data()
Yingdi Yu2e3199c2013-11-06 18:42:34 -080028 , m_identity(profile.getIdentityName())
Yingdi Yub4be64a2013-10-13 17:24:50 -070029 , m_profile(profile)
Yingdi Yu4390ce52013-10-10 17:27:54 -070030{
Yingdi Yu2e3199c2013-11-06 18:42:34 -080031 Name dataName = m_identity;
Yingdi Yufa4ce792014-02-06 18:09:22 -080032 dataName.append("PROFILE").appendVersion();
Yingdi Yub4be64a2013-10-13 17:24:50 -070033 setName(dataName);
Yingdi Yu76dd8002013-12-24 11:16:32 +080034
Yingdi Yufa4ce792014-02-06 18:09:22 -080035 OBufferStream os;
36 profile.encode(os);
37 setContent(os.buf());
Yingdi Yu4390ce52013-10-10 17:27:54 -070038}
39
Yingdi Yub4be64a2013-10-13 17:24:50 -070040ProfileData::ProfileData(const Data& data)
Yingdi Yu76dd8002013-12-24 11:16:32 +080041 : Data(data)
Yingdi Yu4390ce52013-10-10 17:27:54 -070042{
Yingdi Yufa4ce792014-02-06 18:09:22 -080043 if(data.getName().get(-2).toEscapedString() == "PROFILE")
Yingdi Yuf8f572d2014-01-13 11:19:47 -080044 throw Error("No PROFILE component in data name!");
Yingdi Yub4be64a2013-10-13 17:24:50 -070045
Yingdi Yufa4ce792014-02-06 18:09:22 -080046 m_identity = data.getName().getPrefix(-2);
Yingdi Yub4be64a2013-10-13 17:24:50 -070047
Yingdi Yufa4ce792014-02-06 18:09:22 -080048 boost::iostreams::stream <boost::iostreams::array_source> is
49 (reinterpret_cast<const char*>(data.getContent().value()), data.getContent().value_size());
50
51 m_profile.decode(is);
Yingdi Yu4390ce52013-10-10 17:27:54 -070052}
Yingdi Yufa4ce792014-02-06 18:09:22 -080053
54}//chronos