| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| /* |
| * Copyright (c) 2013, Regents of the University of California |
| * Yingdi Yu |
| * |
| * BSD license, See the LICENSE file for more information |
| * |
| * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| */ |
| |
| #include "profile-data.h" |
| #include <boost/date_time/posix_time/posix_time.hpp> |
| #include "exception.h" |
| #include "logging.h" |
| |
| |
| using namespace ndn; |
| using namespace std; |
| using namespace boost::posix_time; |
| |
| INIT_LOGGER("ProfileData"); |
| |
| ProfileData::ProfileData() |
| : Data() |
| {} |
| |
| ProfileData::ProfileData(const Profile& profile) |
| : Data() |
| , m_identity(profile.getIdentityName()) |
| , m_profile(profile) |
| { |
| Name dataName = m_identity; |
| |
| time_duration now = microsec_clock::universal_time () - ptime(boost::gregorian::date (1970, boost::gregorian::Jan, 1)); |
| uint64_t version = (now.total_seconds () << 12) | (0xFFF & (now.fractional_seconds () / 244)); |
| dataName.append("PROFILE").appendVersion(version); |
| setName(dataName); |
| |
| string content; |
| profile.encode(&content); |
| setContent((const uint8_t *)&content[0], content.size()); |
| |
| getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0); |
| |
| } |
| |
| ProfileData::ProfileData(const ProfileData& profileData) |
| : Data(profileData) |
| , m_identity(profileData.m_identity) |
| , m_profile(profileData.m_profile) |
| {} |
| |
| ProfileData::ProfileData(const Data& data) |
| : Data(data) |
| { |
| const Name& dataName = data.getName(); |
| Name::Component appFlag(Name::fromEscapedString("PROFILE")); |
| |
| int profileIndex = -1; |
| for(int i = 0; i < dataName.size(); i++) |
| { |
| if(0 == dataName.get(i).compare(appFlag)) |
| { |
| profileIndex = i; |
| break; |
| } |
| } |
| |
| if(profileIndex < 0) |
| throw LnException("No PROFILE component in data name!"); |
| |
| m_identity = dataName.getPrefix(profileIndex); |
| |
| string encoded((const char*)data.getContent().buf(), data.getContent().size()); |
| m_profile = *Profile::decode(encoded); |
| } |