/*MT* MediaTomb - http://www.mediatomb.cc/ cds_resource.cc - this file is part of MediaTomb. Copyright (C) 2005 Gena Batyan , Sergey 'Jin' Bostandzhyan Copyright (C) 2006-2007 Gena Batyan , Sergey 'Jin' Bostandzhyan , Leonhard Wimmer MediaTomb is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. MediaTomb is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License version 2 along with MediaTomb; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. $Id: cds_resource.cc 1124 2007-02-17 21:49:15Z lww $ */ /// \file cds_resource.cc #ifdef HAVE_CONFIG_H #include "autoconfig.h" #endif #include "tools.h" #include "cds_resource.h" using namespace zmm; CdsResource::CdsResource(int handlerType) : Object() { this->handlerType = handlerType; this->attributes = Ref(new Dictionary()); this->parameters = Ref(new Dictionary()); } CdsResource::CdsResource(int handlerType, Ref attributes, Ref parameters) { this->handlerType = handlerType; this->attributes = attributes; this->parameters = parameters; } void CdsResource::addAttribute(zmm::String name, zmm::String value) { attributes->put(name, value); } void CdsResource::addParameter(zmm::String name, zmm::String value) { parameters->put(name, value); } int CdsResource::getHandlerType() { return handlerType; } Ref CdsResource::getAttributes() { return attributes; } Ref CdsResource::getParameters() { return parameters; } String CdsResource::getAttribute(String name) { return attributes->get(name); } String CdsResource::getParameter(String name) { return parameters->get(name); } bool CdsResource::equals(Ref other) { return ( handlerType == other->handlerType && attributes->equals(other->attributes) && parameters->equals(other->parameters) ); } Ref CdsResource::clone() { return Ref(new CdsResource(handlerType, attributes, parameters)); } String CdsResource::encode() { // encode resources Ref buf(new StringBuffer()); *buf << handlerType; *buf << RESOURCE_PART_SEP; *buf << attributes->encode(); *buf << RESOURCE_PART_SEP; *buf << parameters->encode(); return buf->toString(); } Ref CdsResource::decode(String serial) { Ref > parts = split_string(serial, RESOURCE_PART_SEP); int size = parts->size(); if (size != 2 && size != 3) throw _Exception(_("CdsResource::decode: Could not parse resources")); int handlerType = String(parts->get(0)).toInt(); Ref attr(new Dictionary()); attr->decode(parts->get(1)); Ref par(new Dictionary()); if (size == 3) par->decode(parts->get(2)); Ref resource(new CdsResource(handlerType, attr, par)); return resource; } void CdsResource::optimize() { attributes->optimize(); parameters->optimize(); }