Yingdi Yu | 4390ce5 | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 1 | /* -*- 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 Yu | 92e8e48 | 2013-10-17 21:13:03 -0700 | [diff] [blame] | 12 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 13 | #include "logging.h" |
Yingdi Yu | 4390ce5 | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 14 | |
Yingdi Yu | 4390ce5 | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 15 | using namespace ndn; |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 16 | using namespace std; |
Yingdi Yu | 4390ce5 | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 17 | |
Yingdi Yu | 92e8e48 | 2013-10-17 21:13:03 -0700 | [diff] [blame] | 18 | INIT_LOGGER("ProfileData"); |
19 | |||||
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 20 | namespace chronos{ |
21 | |||||
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 22 | ProfileData::ProfileData() |
23 | : Data() | ||||
24 | {} | ||||
25 | |||||
Yingdi Yu | 2e3199c | 2013-11-06 18:42:34 -0800 | [diff] [blame] | 26 | ProfileData::ProfileData(const Profile& profile) |
Yingdi Yu | 4390ce5 | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 27 | : Data() |
Yingdi Yu | 2e3199c | 2013-11-06 18:42:34 -0800 | [diff] [blame] | 28 | , m_identity(profile.getIdentityName()) |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 29 | , m_profile(profile) |
Yingdi Yu | 4390ce5 | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 30 | { |
Yingdi Yu | 2e3199c | 2013-11-06 18:42:34 -0800 | [diff] [blame] | 31 | Name dataName = m_identity; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 32 | dataName.append("PROFILE").appendVersion(); |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 33 | setName(dataName); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 34 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 35 | OBufferStream os; |
36 | profile.encode(os); | ||||
37 | setContent(os.buf()); | ||||
Yingdi Yu | 4390ce5 | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 38 | } |
39 | |||||
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 40 | ProfileData::ProfileData(const Data& data) |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 41 | : Data(data) |
Yingdi Yu | 4390ce5 | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 42 | { |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 43 | if(data.getName().get(-2).toEscapedString() == "PROFILE") |
Yingdi Yu | f8f572d | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 44 | throw Error("No PROFILE component in data name!"); |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 45 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 46 | m_identity = data.getName().getPrefix(-2); |
Yingdi Yu | b4be64a | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 47 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 48 | 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 Yu | 4390ce5 | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 52 | } |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 53 | |
54 | }//chronos |