Files
BPI-M2C/source_sync_rls_25c/source/unisoc/perflink/libudbus/Property.cpp
T

169 lines
4.4 KiB
C++
Raw Normal View History

2026-09-22 09:38:26 +08:00
/*
* SPDX-License-Identifier: LicenseRef-Unisoc-General-1.0
* Copyright 2016-2023 Unisoc (Shanghai) Technologies Co., Ltd
* Licensed under the Unisoc General Software License, version 1.0 (the License);
* you may not use this file except in compliance with the License. You may obtain a copy of the License at
* https://www.unisoc.com/en_us/license/UNISOC_GENERAL_LICENSE_V1.0-EN_US
* Software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OF ANY KIND, either express or implied.
* See the Unisoc General Software License, version 1.0 for more details.
*/
#include <Debug.h>
#include <Property.h>
#include <Introspection.h>
using namespace UDBus;
static const char *gPropertiesName = "smartlink.netcon.UDBus.Properties";
UDbusPropertiesAdaptor::UDbusPropertiesAdaptor()
: UDbusInterfaceAdaptor(gPropertiesName)
{
REGISTER_METHOD(UDbusPropertiesAdaptor, Set, Set);
REGISTER_METHOD(UDbusPropertiesAdaptor, Get, Get);
REGISTER_METHOD(UDbusPropertiesAdaptor, GetAll, GetAll);
}
Message UDbusPropertiesAdaptor::GetAll(const CallMessage &call)
{
UDbusPropertyDict *properties;
std::string propertyName;
UDbusVariant value;
std::string ifaceName;
MessageIter ri = call.Reader();
ri >> ifaceName;
UDbusInterfaceAdaptor *iface = (UDbusInterfaceAdaptor *) FindInterface(ifaceName);
if (!iface)
throw ErrorFailed("requested interface not found");
properties = iface->GetAllProperties();
ReturnMessage reply(call);
MessageIter wi = reply.Writer();
wi << *properties;
delete properties;
return reply;
}
Message UDbusPropertiesAdaptor::Set(const CallMessage &call)
{
string propertyName;
UDbusVariant value;
string ifaceName;
MessageIter ri = call.Reader();
ri >> ifaceName >> propertyName >> value;
UDbusInterfaceAdaptor *iface = (UDbusInterfaceAdaptor *) FindInterface(ifaceName);
if (nullptr == iface)
throw ErrorFailed("requested interface not found");
OnSetProperty(*iface, propertyName, value);
iface->SetProperty(propertyName, value);
ReturnMessage reply(call);
return reply;
}
Message UDbusPropertiesAdaptor::Get(const CallMessage &call)
{
std::string ifaceName;
std::string propertyName;
MessageIter ri = call.Reader();
ri >> ifaceName >> propertyName;
DEBUG("requesting property %s on interface %s", propertyName.c_str(), ifaceName.c_str());
UDbusInterfaceAdaptor *iface = (UDbusInterfaceAdaptor *) FindInterface(ifaceName);
if (nullptr == iface)
throw ErrorFailed("requested interface not found");
UDbusVariant *variant = iface->GetProperty(propertyName);
if (nullptr == variant)
throw ErrorFailed("requested property not found");
if (variant->Signature().empty())
throw ErrorFailed("requested property has not been initialized");
OnGetProperty(*iface, propertyName, *variant);
ReturnMessage reply(call);
MessageIter wi = reply.Writer();
wi << *variant;
return reply;
}
const UDbusIntrospectIface *UDbusPropertiesAdaptor::Introspect() const
{
static UDbusIntrospectArg getAllArgs[] = {
{ "ifaceName", "s", true },
{ "properties", "a{sv}", false },
{ 0, 0, 0 }
};
static UDbusIntrospectArg setArgs[] = {
{ "ifaceName", "s", true },
{ "propertyName", "s", true },
{ "value", "v", true },
{ 0, 0, 0 }
};
static UDbusIntrospectArg getArgs[] = {
{ "ifaceName", "s", true },
{ "propertyName", "s", true },
{ "value", "v", false },
{ 0, 0, 0 }
};
static UDbusIntrospectMethod propertiesmSignals[] = {
{ 0, 0 }
};
static UDbusIntrospectProp propertiesmProperties[] = {
{ 0, 0, 0, 0 }
};
static UDbusIntrospectMethod propertiesmMethods[] = {
{ "Set", setArgs },
{ "GetAll", getAllArgs },
{ "Get", getArgs },
{ 0, 0 }
};
static UDbusIntrospectIface propertiesIface = {
gPropertiesName,
propertiesmMethods,
propertiesmSignals,
propertiesmProperties
};
return &propertiesIface;
}
UDbusPropertiesProxy::UDbusPropertiesProxy()
: InterfaceProxy(gPropertiesName)
{
}
UDbusVariant UDbusPropertiesProxy::Get(const std::string &iface, const std::string &property)
{
//todo
UDbusVariant v;
return v;
}
void UDbusPropertiesProxy::Set(const std::string &iface, const std::string &property, const UDbusVariant &value)
{
//todo
}