| /******************************************************************************* | |
| * Copyright (c) 2010 Nokia and others. | |
| * All rights reserved. This program and the accompanying materials | |
| * are made available under the terms of the Eclipse Public License v1.0 | |
| * which accompanies this distribution, and is available at | |
| * http://www.eclipse.org/legal/epl-v10.html | |
| * | |
| * Contributors: | |
| * Nokia - Initial API and implementation | |
| *******************************************************************************/ | |
| #include "TCFContext.h" | |
| #include "ContextManager.h" | |
| #include "AgentUtils.h" | |
| #undef remove | |
| /* | |
| * Create a new context. | |
| */ | |
| Context::Context(const ContextID& parentID, const ContextID& internalID) { | |
| this->internalID = internalID; | |
| this->parentID = parentID; | |
| Initialize(); | |
| // Don't add the context to any context cache here as there are different | |
| // caches for different purposes. | |
| // See ContextManager for more. | |
| } | |
| Context::Context(const ContextID& parentID, const ContextID& internalID, Properties& props) { | |
| this->internalID = internalID; | |
| this->parentID = parentID; | |
| this->properties = props; | |
| Initialize(); | |
| } | |
| Context::~Context() { | |
| properties.clear(); | |
| // delete remaining children. | |
| // | |
| // This makes a copy. | |
| std::list<Context *> remainingKids = GetChildren(); | |
| for (std::list<Context *>::iterator iter = remainingKids.begin(); | |
| iter != remainingKids.end(); iter++) { | |
| Context* kid = *iter; | |
| delete ContextManager::findContext(kid->GetID()); | |
| } | |
| // Remove this context from global cache. | |
| ContextManager::removeContext(GetID()); | |
| } | |
| void Context::Initialize() | |
| { | |
| SetProperty(PROP_ID, PropertyValue(internalID)); | |
| SetProperty(PROP_PARENT_ID, PropertyValue(parentID)); | |
| } | |
| ContextID Context::GetID() const { | |
| return internalID; | |
| } | |
| ContextID Context::GetParentID() const { | |
| return parentID; | |
| } | |
| Properties& Context::GetProperties() { | |
| return properties; | |
| } | |
| void Context::AddChild(Context* child) { | |
| children_.push_back(child); | |
| } | |
| void Context::RemoveChild(Context* child) { | |
| children_.remove(child); | |
| } | |
| std::list<Context*>& Context::GetChildren() { | |
| return children_; | |
| } | |
| PropertyValue& Context::GetProperty(const std::string& key) { | |
| return properties[key]; | |
| } | |
| void Context::SetProperty(const std::string& key, const PropertyValue& value) { | |
| properties[key] = value; | |
| } |