value_type* outv = (value_type*)calloc(size + 1, sizeof(value_type));
g_variant_iter_init(&iter, in);
- for (int i = 0; g_variant_iter_loop(&iter, "{ss}", &key, &value); i++) {
+ for (int i = 0; g_variant_iter_loop(&iter, "(ss)", &key, &value); i++) {
outk[i] = strdup(key);
outv[i] = strdup(value);
}
VsmStatus ret = callMethod(HOST_INTERFACE,
api::host::METHOD_GET_ZONE_DBUSES,
NULL,
- "(a{ss})",
+ "(a(ss))",
&out);
if (ret != VSMCLIENT_SUCCESS) {
return ret;
--- /dev/null
+/*
+* Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Contact: Jan Olszak (j.olszak@samsung.com)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License
+*/
+
+/**
+ * @file
+ * @author Jan Olszak (j.olszak@samsung.com)
+ * @brief Interface for result builders
+
+ */
+
+#ifndef COMMON_RESULT_DBUS_METHOD_RESULT_BUILDER_HPP
+#define COMMON_RESULT_DBUS_METHOD_RESULT_BUILDER_HPP
+
+#include "config.hpp"
+
+#include "api/method-result-builder.hpp"
+
+#include "dbus/connection.hpp"
+#include "config/manager.hpp"
+
+#include <memory>
+#include <functional>
+
+namespace vasum {
+namespace api {
+
+template<typename Data>
+class DbusMethodResultBuilder: public MethodResultBuilder {
+public:
+ DbusMethodResultBuilder(const dbus::MethodResultBuilder::Pointer& methodResultBuilderPtr);
+ ~DbusMethodResultBuilder() {}
+
+private:
+ void setImpl(const std::shared_ptr<void>& data) override;
+ void setVoid() override;
+ void setError(const std::string& name, const std::string& message) override;
+
+ dbus::MethodResultBuilder::Pointer mMethodResultBuilderPtr;
+ std::function<GVariant*(std::shared_ptr<void>)> mSerialize;
+};
+
+template<typename Data>
+DbusMethodResultBuilder<Data>::DbusMethodResultBuilder(const dbus::MethodResultBuilder::Pointer& methodResultBuilderPtr)
+ : mMethodResultBuilderPtr(methodResultBuilderPtr)
+{
+ mSerialize = [](const std::shared_ptr<void> data)->GVariant* {
+ return config::saveToGVariant(*std::static_pointer_cast<Data>(data));
+ };
+}
+
+template<typename Data>
+void DbusMethodResultBuilder<Data>::setImpl(const std::shared_ptr<void>& data)
+{
+ GVariant* parameters = mSerialize(data);
+ mMethodResultBuilderPtr->set(parameters);
+}
+
+template<typename Data>
+void DbusMethodResultBuilder<Data>::setVoid()
+{
+ mMethodResultBuilderPtr->setVoid();
+}
+
+template<typename Data>
+void DbusMethodResultBuilder<Data>::setError(const std::string& name, const std::string& message)
+{
+ mMethodResultBuilderPtr->setError(name, message);
+}
+
+} // namespace result
+} // namespace vasum
+
+#endif // COMMON_RESULT_DBUS_METHOD_RESULT_BUILDER_HPP
--- /dev/null
+/*
+* Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Contact: Jan Olszak (j.olszak@samsung.com)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License
+*/
+
+/**
+ * @file
+ * @author Jan Olszak (j.olszak@samsung.com)
+ * @brief Class for sending the result of a method
+ */
+
+#include "api/ipc-method-result-builder.hpp"
+
+namespace vasum {
+namespace api {
+
+IPCMethodResultBuilder::IPCMethodResultBuilder(const ipc::MethodResult::Pointer& methodResultPtr)
+ : mMethodResultPtr(methodResultPtr)
+{
+}
+
+void IPCMethodResultBuilder::setImpl(const std::shared_ptr<void>& data)
+{
+ mMethodResultPtr->set(data);
+}
+
+void IPCMethodResultBuilder::setVoid()
+{
+ mMethodResultPtr->setVoid();
+}
+
+void IPCMethodResultBuilder::setError(const std::string& , const std::string& message)
+{
+ // TODO: Change int codes to string names in IPC MethodResult
+ mMethodResultPtr->setError(1, message);
+}
+
+} // namespace result
+} // namespace vasum
+
+
--- /dev/null
+/*
+* Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Contact: Jan Olszak (j.olszak@samsung.com)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License
+*/
+
+/**
+ * @file
+ * @author Jan Olszak (j.olszak@samsung.com)
+ * @brief Interface for result builders
+
+ */
+
+#ifndef COMMON_RESULT_IPC_METHOD_RESULT_BUILDER_HPP
+#define COMMON_RESULT_IPC_METHOD_RESULT_BUILDER_HPP
+
+#include "config.hpp"
+
+#include "api/method-result-builder.hpp"
+#include "ipc/method-result.hpp"
+
+#include <memory>
+
+namespace vasum {
+namespace api {
+
+class IPCMethodResultBuilder: public MethodResultBuilder {
+public:
+ IPCMethodResultBuilder(const ipc::MethodResult::Pointer& methodResult);
+ ~IPCMethodResultBuilder() {}
+
+private:
+ void setImpl(const std::shared_ptr<void>& data) override;
+ void setVoid() override;
+ void setError(const std::string& name, const std::string& message) override;
+
+ ipc::MethodResult::Pointer mMethodResultPtr;
+};
+
+
+} // namespace result
+} // namespace vasum
+
+#endif // COMMON_RESULT_IPC_METHOD_RESULT_BUILDER_HPP
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jan Olszak (j.olszak@samsung.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+/**
+ * @file
+ * @author Jan Olszak (j.olszak@samsung.com)
+ * @brief Host's internal IPC messages declaration
+ */
+
+
+#ifndef COMMON_API_MESSAGES
+#define COMMON_API_MESSAGES
+
+#include "config/fields.hpp"
+#include <string>
+#include <vector>
+
+namespace vasum {
+namespace api {
+
+struct Void {
+ CONFIG_REGISTER_EMPTY
+};
+
+struct String {
+ std::string value;
+
+ CONFIG_REGISTER
+ (
+ value
+ )
+};
+
+struct StringPair {
+ std::string first;
+ std::string second;
+
+ CONFIG_REGISTER
+ (
+ first,
+ second
+ )
+};
+
+struct VectorOfStrings {
+ std::vector<std::string> values;
+
+ CONFIG_REGISTER
+ (
+ values
+ )
+};
+
+struct VectorOfStringPairs {
+ std::vector<api::StringPair> values;
+
+ CONFIG_REGISTER
+ (
+ values
+ )
+};
+
+typedef api::String ZoneId;
+typedef api::String Declaration;
+typedef api::String FileMoveRequestStatus;
+typedef api::VectorOfStrings ZoneIds;
+typedef api::VectorOfStrings Declarations;
+typedef api::VectorOfStrings NetDevList;
+typedef api::VectorOfStringPairs Dbuses;
+typedef api::VectorOfStringPairs NetDevAttrs;
+
+struct ZoneInfo {
+ std::string id;
+ int vt;
+ std::string state;
+ std::string rootPath;
+
+ CONFIG_REGISTER
+ (
+ id,
+ vt,
+ state,
+ rootPath
+ )
+};
+
+// struct MethodSetActiveZoneConfig {
+// std::string id;
+
+// CONFIG_REGISTER
+// (
+// id
+// )
+// };
+
+// struct MethodGetZoneDbusesConfig {
+// CONFIG_REGISTER_EMPTY
+// };
+
+// struct MethodGetZoneIdListConfig {
+// CONFIG_REGISTER_EMPTY
+// };
+
+
+// struct MethodGetActiveZoneIdConfig {
+// CONFIG_REGISTER_EMPTY
+// };
+
+
+// struct MethodGetZoneInfoConfig {
+// std::string id;
+
+// CONFIG_REGISTER
+// (
+// id
+// )
+// };
+
+// struct MethodSetNetDevAttrsConfig {
+// std::string zone;
+// std::string netdev;
+
+// struct Store {
+// std::string key;
+// std::string value;
+
+// CONFIG_REGISTER
+// (
+// key,
+// value
+// )
+// };
+
+// std::vector<Store> attrs;
+
+// CONFIG_REGISTER
+// (
+// zone,
+// netdev,
+// attrs
+// )
+// };
+
+// struct MethodGetNetDevAttrsConfig {
+// std::string zone;
+// std::string netdev;
+
+// CONFIG_REGISTER
+// (
+// zone,
+// netdev
+// )
+// };
+
+// struct MethodGetNetDevListConfig {
+// std::string zone;
+
+// CONFIG_REGISTER
+// (
+// zone
+// )
+// };
+
+// struct MethodCreateNetDevVethConfig {
+// std::string id;
+// std::string zoneDev;
+// std::string hostDev;
+
+// CONFIG_REGISTER
+// (
+// id,
+// zoneDev,
+// hostDev
+// )
+// };
+
+// struct MethodCreateNetDevMacvlanConfig {
+// std::string id;
+// std::string zoneDev;
+// std::string hostDev;
+
+// CONFIG_REGISTER
+// (
+// id,
+// zoneDev,
+// hostDev
+// )
+// };
+
+// struct MethodCreateNetDevPhysConfig {
+// std::string id;
+// std::string devId;
+
+// CONFIG_REGISTER
+// (
+// id,
+// devId
+// )
+// };
+
+// struct MethodGetDeclareFileConfig {
+// std::string zone;
+// int32_t type;
+// std::string path;
+// int32_t flags;
+// int32_t mode;
+
+// CONFIG_REGISTER
+// (
+// zone,
+// type,
+// path,
+// flags,
+// mode
+// )
+// };
+
+// struct MethodGetDeclareMountConfig {
+// std::string source;
+// std::string zone;
+// std::string target;
+// uint64_t flags;
+// std::string data;
+
+// CONFIG_REGISTER
+// (
+// source,
+// zone,
+// target,
+// flags,
+// data
+// )
+// };
+
+// struct MethodGetDeclareLinkConfig {
+// std::string source;
+// std::string zone;
+// std::string target;
+
+// CONFIG_REGISTER
+// (
+// source,
+// zone,
+// target
+// )
+// };
+
+// struct MethodGetDeclarationConfig {
+// std::string zone;
+// std::string declarationId;
+
+// CONFIG_REGISTER
+// (
+// zone,
+// declarationId
+// )
+// };
+
+// struct MethodRemoveDeclarationConfig {
+// std::string id;
+// std::string declarationId;
+
+// CONFIG_REGISTER
+// (
+// id,
+// declarationId
+// )
+// };
+
+// struct MethodCreateZoneConfig {
+// std::string id;
+// std::string templateName;
+
+// CONFIG_REGISTER
+// (
+// id,
+// templateName
+// )
+// };
+
+// struct MethodDestroyZoneConfig {
+// std::string id;
+
+// CONFIG_REGISTER
+// (
+// id
+// )
+// };
+
+
+// struct MethodShutdownZoneConfig {
+// std::string id;
+
+// CONFIG_REGISTER
+// (
+// id
+// )
+// };
+
+// struct MethodStartZoneConfig {
+// std::string id;
+
+// CONFIG_REGISTER
+// (
+// id
+// )
+// };
+
+// struct MethodLockZoneConfig {
+// std::string id;
+
+// CONFIG_REGISTER
+// (
+// id
+// )
+// };
+
+// struct MethodUnlockZoneConfig {
+// std::string id;
+
+// CONFIG_REGISTER
+// (
+// id
+// )
+// };
+
+// struct MethodGrantDeviceConfig {
+// std::string id;
+// std::string device;
+// uint32_t flags;
+
+// CONFIG_REGISTER
+// (
+// id,
+// device,
+// flags
+// )
+// };
+
+// struct MethodRevokeDeviceConfig {
+// std::string id;
+// std::string device;
+
+// CONFIG_REGISTER
+// (
+// id,
+// device
+// )
+// };
+
+// TODO: Agregate configs if it makes sense. For example: MethodLockZoneConfig and MethodUnlockZoneConfig
+
+
+// Zone:
+// struct MethodNotifyActiveZoneConfig {
+// std::string application;
+// std::string message;
+
+// CONFIG_REGISTER
+// (
+// application,
+// message
+// )
+// };
+
+// struct MethodFileMoveRequest {
+// std::string destination;
+// std::string path;
+
+// CONFIG_REGISTER
+// (
+// destination,
+// path
+// )
+// };
+
+// struct MethodFileMoveRequestResult {
+// std::string result;
+
+// CONFIG_REGISTER
+// (
+// result
+// )
+// };
+
+} // namespace api
+} // namespace vasum
+
+#endif // COMMON_API_MESSAGES
--- /dev/null
+/*
+* Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Contact: Jan Olszak (j.olszak@samsung.com)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License
+*/
+
+/**
+ * @file
+ * @author Jan Olszak (j.olszak@samsung.com)
+ * @brief Interface for result builders
+
+ */
+
+#ifndef COMMON_RESULT_METHOD_RESULT_BUILDER_HPP
+#define COMMON_RESULT_METHOD_RESULT_BUILDER_HPP
+
+#include <memory>
+
+#include "config/is-union.hpp"
+
+namespace vasum {
+namespace api {
+
+/**
+ * An interface used to set a result to a method call.
+ */
+class MethodResultBuilder {
+public:
+ typedef std::shared_ptr<MethodResultBuilder> Pointer;
+
+ virtual ~MethodResultBuilder() {}
+ virtual void setVoid() = 0;
+ virtual void setError(const std::string& name, const std::string& message) = 0;
+
+ template<typename Data>
+ void set(const std::shared_ptr<Data>& data)
+ {
+ static_assert(config::isVisitable<Data>::value, "Use only libConfig's structures");
+ setImpl(data);
+ }
+
+private:
+ virtual void setImpl(const std::shared_ptr<void>& data) =0;
+
+};
+
+} // namespace api
+} // namespace vasum
+
+#endif // COMMON_RESULT_METHOD_RESULT_BUILDER_HPP
#include "host-connection.hpp"
#include "host-dbus-definitions.hpp"
#include "exception.hpp"
+#include "api/dbus-method-result-builder.hpp"
+#include "api/messages.hpp"
#include "logger/logger.hpp"
mDbusConnection->registerObject(api::host::OBJECT_PATH,
api::host::DEFINITION,
std::bind(&HostConnection::onMessageCall,
- this, _1, _2, _3, _4, _5));
+ this, _1, _2, _3, _4, _5));
LOGD("Connected");
}
g_variant_get(parameters, "(&s)", &id);
if (mSetActiveZoneCallback) {
- mSetActiveZoneCallback(id, result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mSetActiveZoneCallback(id, rb);
}
return;
}
if (methodName == api::host::METHOD_GET_ZONE_DBUSES) {
if (mGetZoneDbusesCallback) {
- mGetZoneDbusesCallback(result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Dbuses>>(result);
+ mGetZoneDbusesCallback(rb);
}
return;
}
return;
}
- if (methodName == api::host::METHOD_GET_ZONE_ID_LIST){
- if (mGetZoneIdsCallback){
- mGetZoneIdsCallback(result);
+ if (methodName == api::host::METHOD_GET_ZONE_ID_LIST) {
+ if (mGetZoneIdsCallback) {
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::ZoneIds>>(result);
+ mGetZoneIdsCallback(rb);
}
return;
}
- if (methodName == api::host::METHOD_GET_ACTIVE_ZONE_ID){
- if (mGetActiveZoneIdCallback){
- mGetActiveZoneIdCallback(result);
+ if (methodName == api::host::METHOD_GET_ACTIVE_ZONE_ID) {
+ if (mGetActiveZoneIdCallback) {
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::ZoneId>>(result);
+ mGetActiveZoneIdCallback(rb);
}
return;
}
- if (methodName == api::host::METHOD_GET_ZONE_INFO){
+ if (methodName == api::host::METHOD_GET_ZONE_INFO) {
const gchar* id = NULL;
g_variant_get(parameters, "(&s)", &id);
if (mGetZoneInfoCallback) {
- mGetZoneInfoCallback(id, result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::ZoneInfo>>(result);
+ mGetZoneInfoCallback(id, rb);
}
return;
}
- if (methodName == api::host::METHOD_SET_NETDEV_ATTRS){
+ if (methodName == api::host::METHOD_SET_NETDEV_ATTRS) {
const gchar* zone = NULL;
const gchar* netdev = NULL;
GVariantIter* iter;
}
g_variant_iter_free(iter);
if (mSetNetdevAttrsCallback) {
- mSetNetdevAttrsCallback(zone, netdev, attrs, result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mSetNetdevAttrsCallback(zone, netdev, attrs, rb);
}
return;
}
- if (methodName == api::host::METHOD_GET_NETDEV_ATTRS){
+ if (methodName == api::host::METHOD_GET_NETDEV_ATTRS) {
const gchar* zone = NULL;
const gchar* netdev = NULL;
g_variant_get(parameters, "(&s&s)", &zone, &netdev);
if (mGetNetdevAttrsCallback) {
- mGetNetdevAttrsCallback(zone, netdev, result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::NetDevAttrs>>(result);
+ mGetNetdevAttrsCallback(zone, netdev, rb);
}
return;
}
- if (methodName == api::host::METHOD_GET_NETDEV_LIST){
+ if (methodName == api::host::METHOD_GET_NETDEV_LIST) {
const gchar* zone = NULL;
g_variant_get(parameters, "(&s)", &zone);
if (mGetNetdevListCallback) {
- mGetNetdevListCallback(zone, result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::NetDevList>>(result);
+ mGetNetdevListCallback(zone, rb);
}
return;
}
const gchar* hostDev = NULL;
g_variant_get(parameters, "(&s&s&s)", &id, &zoneDev, &hostDev);
if (mCreateNetdevVethCallback) {
- mCreateNetdevVethCallback(id, zoneDev, hostDev, result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mCreateNetdevVethCallback(id, zoneDev, hostDev, rb);
}
return;
}
guint32 mode;
g_variant_get(parameters, "(&s&s&su)", &id, &zoneDev, &hostDev, &mode);
if (mCreateNetdevMacvlanCallback) {
- mCreateNetdevMacvlanCallback(id, zoneDev, hostDev, mode, result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mCreateNetdevMacvlanCallback(id, zoneDev, hostDev, mode, rb);
}
}
const gchar* devId = NULL;
g_variant_get(parameters, "(&s&s)", &id, &devId);
if (mCreateNetdevPhysCallback) {
- mCreateNetdevPhysCallback(id, devId, result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mCreateNetdevPhysCallback(id, devId, rb);
}
}
g_variant_get(parameters, "(&si&sii)", &zone, &type, &path, &flags, &mode);
if (mDeclareFileCallback) {
- mDeclareFileCallback(zone, type, path, flags, mode, result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Declaration>>(result);
+ mDeclareFileCallback(zone, type, path, flags, mode, rb);
}
return;
}
&data);
if (mDeclareMountCallback) {
- mDeclareMountCallback(source, zone, target, type, flags, data, result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Declaration>>(result);
+ mDeclareMountCallback(source, zone, target, type, flags, data, rb);
}
return;
}
g_variant_get(parameters, "(&s&s&s)", &source, &zone, &target);
if (mDeclareLinkCallback) {
- mDeclareLinkCallback(source, zone, target, result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Declaration>>(result);
+ mDeclareLinkCallback(source, zone, target, rb);
}
return;
}
g_variant_get(parameters, "(&s)", &zone);
if (mGetDeclarationsCallback) {
- mGetDeclarationsCallback(zone, result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Declarations>>(result);
+ mGetDeclarationsCallback(zone, rb);
}
return;
}
g_variant_get(parameters, "(&s&s)", &zone, &declarationId);
if (mRemoveDeclarationCallback) {
- mRemoveDeclarationCallback(zone, declarationId, result);
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mRemoveDeclarationCallback(zone, declarationId, rb);
}
return;
}
const gchar* templateName = NULL;
g_variant_get(parameters, "(&s&s)", &id, &templateName);
- if (mCreateZoneCallback){
- mCreateZoneCallback(id, templateName, result);
+ if (mCreateZoneCallback) {
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mCreateZoneCallback(id, templateName, rb);
}
return;
}
const gchar* id = NULL;
g_variant_get(parameters, "(&s)", &id);
- if (mDestroyZoneCallback){
- mDestroyZoneCallback(id, result);
+ if (mDestroyZoneCallback) {
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mDestroyZoneCallback(id, rb);
}
return;
}
const gchar* id = NULL;
g_variant_get(parameters, "(&s)", &id);
- if (mShutdownZoneCallback){
- mShutdownZoneCallback(id, result);
+ if (mShutdownZoneCallback) {
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mShutdownZoneCallback(id, rb);
}
}
const gchar* id = NULL;
g_variant_get(parameters, "(&s)", &id);
- if (mStartZoneCallback){
- mStartZoneCallback(id, result);
+ if (mStartZoneCallback) {
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mStartZoneCallback(id, rb);
}
}
const gchar* id = NULL;
g_variant_get(parameters, "(&s)", &id);
- if (mLockZoneCallback){
- mLockZoneCallback(id, result);
+ if (mLockZoneCallback) {
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mLockZoneCallback(id, rb);
}
return;
}
const gchar* id = NULL;
g_variant_get(parameters, "(&s)", &id);
- if (mUnlockZoneCallback){
- mUnlockZoneCallback(id, result);
+ if (mUnlockZoneCallback) {
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mUnlockZoneCallback(id, rb);
}
return;
}
uint32_t flags;
g_variant_get(parameters, "(&s&su)", &id, &device, &flags);
- if (mGrantDeviceCallback){
- mGrantDeviceCallback(id, device, flags, result);
+ if (mGrantDeviceCallback) {
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mGrantDeviceCallback(id, device, flags, rb);
}
return;
}
const gchar* device = NULL;
g_variant_get(parameters, "(&s&s)", &id, &device);
- if (mRevokeDeviceCallback){
- mRevokeDeviceCallback(id, device, result);
+ if (mRevokeDeviceCallback) {
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mRevokeDeviceCallback(id, device, rb);
}
return;
}
#define SERVER_HOST_CONNECTION_HPP
#include "dbus/connection.hpp"
+#include "api/method-result-builder.hpp"
#include <mutex>
#include <condition_variable>
GVariant* parameters,
dbus::MethodResultBuilder::Pointer result
)> ProxyCallCallback;
- typedef std::function<void(dbus::MethodResultBuilder::Pointer result
+ typedef std::function<void(api::MethodResultBuilder::Pointer result
)> GetZoneDbusesCallback;
- typedef std::function<void(dbus::MethodResultBuilder::Pointer result
+ typedef std::function<void(api::MethodResultBuilder::Pointer result
)> GetZoneIdsCallback;
- typedef std::function<void(dbus::MethodResultBuilder::Pointer result
+ typedef std::function<void(api::MethodResultBuilder::Pointer result
)> GetActiveZoneIdCallback;
typedef std::function<void(const std::string& id,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> GetZoneInfoCallback;
typedef std::function<void(const std::string& zone,
const std::string& netdev,
const std::vector<std::tuple<std::string, std::string>>& attrs,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> SetNetdevAttrsCallback;
typedef std::function<void(const std::string& zone,
const std::string& netdev,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> GetNetdevAttrsCallback;
typedef std::function<void(const std::string& zone,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> GetNetdevListCallback;
typedef std::function<void(const std::string& zone,
const std::string& netdev,
const std::string& hostDev,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> CreateNetdevVethCallback;
typedef std::function<void(const std::string& id,
const std::string& zoneDev,
const std::string& hostDev,
const uint32_t& mode,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> CreateNetdevMacvlanCallback;
typedef std::function<void(const std::string& id,
const std::string& devId,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> CreateNetdevPhysCallback;
typedef std::function<void(const std::string& zone,
const int32_t& type,
const std::string& path,
const int32_t& flags,
const int32_t& mode,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> DeclareFileCallback;
typedef std::function<void(const std::string& source,
const std::string& zone,
const std::string& type,
const uint64_t& flags,
const std::string& data,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> DeclareMountCallback;
typedef std::function<void(const std::string& source,
const std::string& zone,
const std::string& target,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> DeclareLinkCallback;
typedef std::function<void(const std::string& id,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> GetDeclarationsCallback;
typedef std::function<void(const std::string& id,
const std::string& declarationId,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> RemoveDeclarationCallback;
typedef std::function<void(const std::string& id,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> SetActiveZoneCallback;
typedef std::function<void(const std::string& id,
const std::string& templateName,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> CreateZoneCallback;
typedef std::function<void(const std::string& id,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> DestroyZoneCallback;
typedef std::function<void(const std::string& id,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> ShutdownZoneCallback;
typedef std::function<void(const std::string& id,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> StartZoneCallback;
typedef std::function<void(const std::string& id,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> LockZoneCallback;
typedef std::function<void(const std::string& id,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> UnlockZoneCallback;
typedef std::function<void(const std::string& id,
const std::string& device,
uint32_t flags,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> GrantDeviceCallback;
typedef std::function<void(const std::string& id,
const std::string& device,
- dbus::MethodResultBuilder::Pointer result
+ api::MethodResultBuilder::Pointer result
)> RevokeDeviceCallback;
/**
/**
* Register a callback called to get the active zone id
*/
- void setGetActiveZoneIdCallback(const GetZoneIdsCallback& callback);
+ void setGetActiveZoneIdCallback(const GetActiveZoneIdCallback& callback);
/**
* Register a callback called to get the zone informations
" <arg type='v' name='result' direction='out'/>"
" </method>"
" <method name='" + METHOD_GET_ZONE_DBUSES + "'>"
- " <arg type='a{ss}' name='dbuses' direction='out'/>"
+ " <arg type='a(ss)' name='dbuses' direction='out'/>"
" </method>"
" <method name='" + METHOD_GET_ZONE_ID_LIST + "'>"
" <arg type='as' name='result' direction='out'/>"
// TODO: Switch to real power-manager dbus defs when they will be implemented in power-manager
#include "fake-power-manager-dbus-definitions.hpp"
+#include "api/dbus-method-result-builder.hpp"
+#include "api/messages.hpp"
+
#include "logger/logger.hpp"
mDisplayOffCallback = callback;
}
-void ZoneConnection::setFileMoveRequestCallback(
- const FileMoveRequestCallback& callback)
+void ZoneConnection::setFileMoveCallback(
+ const FileMoveCallback& callback)
{
- mFileMoveRequestCallback = callback;
+ mFileMoveCallback = callback;
}
void ZoneConnection::setProxyCallCallback(const ProxyCallCallback& callback)
const gchar* message = NULL;
g_variant_get(parameters, "(&s&s)", &application, &message);
if (mNotifyActiveZoneCallback) {
- mNotifyActiveZoneCallback(application, message);
- result->setVoid();
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::Void>>(result);
+ mNotifyActiveZoneCallback(application, message, rb);
}
}
const gchar* destination = NULL;
const gchar* path = NULL;
g_variant_get(parameters, "(&s&s)", &destination, &path);
- if (mFileMoveRequestCallback) {
- mFileMoveRequestCallback(destination, path, result);
+ if (mFileMoveCallback) {
+ auto rb = std::make_shared<api::DbusMethodResultBuilder<api::FileMoveRequestStatus>>(result);
+ mFileMoveCallback(destination, path, rb);
}
}
#define SERVER_ZONE_CONNECTION_HPP
#include "dbus/connection.hpp"
+#include "api/method-result-builder.hpp"
#include <mutex>
#include <condition_variable>
-
namespace vasum {
// ------------- API --------------
typedef std::function<void(const std::string& application,
- const std::string& message
+ const std::string& message,
+ api::MethodResultBuilder::Pointer result
)> NotifyActiveZoneCallback;
typedef std::function<void(const std::string& destination,
const std::string& path,
- dbus::MethodResultBuilder::Pointer result
- )> FileMoveRequestCallback;
+ api::MethodResultBuilder::Pointer result
+ )> FileMoveCallback;
typedef std::function<void(const std::string& target,
const std::string& targetBusName,
const std::string& targetMethod,
GVariant* parameters,
dbus::MethodResultBuilder::Pointer result
- )> ProxyCallCallback;
+ )> ProxyCallCallback;
/**
* Register notification request callback
/*
* Register file move request callback
*/
- void setFileMoveRequestCallback(const FileMoveRequestCallback& callback);
+ void setFileMoveCallback(const FileMoveCallback& callback);
/**
* Register proxy call callback
OnNameLostCallback mOnNameLostCallback;
NotifyActiveZoneCallback mNotifyActiveZoneCallback;
DisplayOffCallback mDisplayOffCallback;
- FileMoveRequestCallback mFileMoveRequestCallback;
+ FileMoveCallback mFileMoveCallback;
ProxyCallCallback mProxyCallCallback;
void onNameAcquired();
mConnection->setDisplayOffCallback(mDisplayOffCallback);
}
if (mFileMoveCallback) {
- mConnection->setFileMoveRequestCallback(mFileMoveCallback);
+ mConnection->setFileMoveCallback(mFileMoveCallback);
}
if (mProxyCallCallback) {
mConnection->setProxyCallCallback(mProxyCallCallback);
}
}
-void Zone::setFileMoveRequestCallback(const FileMoveRequestCallback& callback)
+void Zone::setFileMoveCallback(const FileMoveCallback& callback)
{
Lock lock(mReconnectMutex);
mFileMoveCallback = callback;
if (mConnection) {
- mConnection->setFileMoveRequestCallback(callback);
+ mConnection->setFileMoveCallback(callback);
}
}
typedef ZoneConnection::NotifyActiveZoneCallback NotifyActiveZoneCallback;
typedef ZoneConnection::DisplayOffCallback DisplayOffCallback;
- typedef ZoneConnection::FileMoveRequestCallback FileMoveRequestCallback;
+ typedef ZoneConnection::FileMoveCallback FileMoveCallback;
typedef ZoneConnection::ProxyCallCallback ProxyCallCallback;
typedef std::function<void(const std::string& address)> DbusStateChangedCallback;
/**
* Register file move request callback
*/
- void setFileMoveRequestCallback(const FileMoveRequestCallback& callback);
+ void setFileMoveCallback(const FileMoveCallback& callback);
/**
* Register dbus state changed callback
mutable std::recursive_mutex mReconnectMutex;
NotifyActiveZoneCallback mNotifyCallback;
DisplayOffCallback mDisplayOffCallback;
- FileMoveRequestCallback mFileMoveCallback;
+ FileMoveCallback mFileMoveCallback;
ProxyCallCallback mProxyCallCallback;
DbusStateChangedCallback mDbusStateChangedCallback;
std::string mDbusAddress;
#include "utils/fs.hpp"
#include "utils/img.hpp"
#include "utils/environment.hpp"
+#include "api/messages.hpp"
#include <boost/filesystem.hpp>
#include <boost/regex.hpp>
bool regexMatchVector(const std::string& str, const std::vector<boost::regex>& v)
{
- for (const boost::regex& toMatch: v) {
+ for (const boost::regex& toMatch : v) {
if (boost::regex_match(str, toMatch)) {
return true;
}
mHostConnection.setProxyCallCallback(bind(&ZonesManager::handleProxyCall,
this, HOST_ID, _1, _2, _3, _4, _5, _6, _7));
- mHostConnection.setGetZoneDbusesCallback(bind(&ZonesManager::handleGetZoneDbuses,
+ mHostConnection.setGetZoneDbusesCallback(bind(&ZonesManager::handleGetZoneDbusesCall,
this, _1));
mHostConnection.setGetZoneIdsCallback(bind(&ZonesManager::handleGetZoneIdsCall,
this, _1, _2));
mHostConnection.setSetNetdevAttrsCallback(bind(&ZonesManager::handleSetNetdevAttrsCall,
- this, _1, _2, _3, _4));
+ this, _1, _2, _3, _4));
mHostConnection.setGetNetdevAttrsCallback(bind(&ZonesManager::handleGetNetdevAttrsCall,
- this, _1, _2, _3));
+ this, _1, _2, _3));
mHostConnection.setGetNetdevListCallback(bind(&ZonesManager::handleGetNetdevListCall,
- this, _1, _2));
+ this, _1, _2));
mHostConnection.setCreateNetdevVethCallback(bind(&ZonesManager::handleCreateNetdevVethCall,
- this, _1, _2, _3, _4));
+ this, _1, _2, _3, _4));
mHostConnection.setCreateNetdevMacvlanCallback(bind(&ZonesManager::handleCreateNetdevMacvlanCall,
- this, _1, _2, _3, _4, _5));
+ this, _1, _2, _3, _4, _5));
mHostConnection.setCreateNetdevPhysCallback(bind(&ZonesManager::handleCreateNetdevPhysCall,
- this, _1, _2, _3));
+ this, _1, _2, _3));
mHostConnection.setDeclareFileCallback(bind(&ZonesManager::handleDeclareFileCall,
this, _1, _2, _3, _4, _5, _6));
this, _1, _2));
mHostConnection.setRemoveDeclarationCallback(bind(&ZonesManager::handleRemoveDeclarationCall,
- this, _1, _2, _3));
+ this, _1, _2, _3));
mHostConnection.setSetActiveZoneCallback(bind(&ZonesManager::handleSetActiveZoneCall,
this, _1, _2));
if (mConfig.inputConfig.enabled) {
LOGI("Registering input monitor [" << mConfig.inputConfig.device.c_str() << "]");
mSwitchingSequenceMonitor.reset(
- new InputMonitor(mConfig.inputConfig,
- std::bind(&ZonesManager::switchingSequenceMonitorNotify,
- this)));
+ new InputMonitor(mConfig.inputConfig,
+ std::bind(&ZonesManager::switchingSequenceMonitorNotify,
+ this)));
}
mConfig.runMountPointPrefix));
using namespace std::placeholders;
- zone->setNotifyActiveZoneCallback(bind(&ZonesManager::notifyActiveZoneHandler,
- this, zoneId, _1, _2));
+ zone->setNotifyActiveZoneCallback(bind(&ZonesManager::handleNotifyActiveZoneCall,
+ this, zoneId, _1, _2, _3));
- zone->setDisplayOffCallback(bind(&ZonesManager::displayOffHandler,
+ zone->setDisplayOffCallback(bind(&ZonesManager::handleDisplayOffCall,
this, zoneId));
- zone->setFileMoveRequestCallback(bind(&ZonesManager::handleZoneMoveFileRequest,
+ zone->setFileMoveCallback(bind(&ZonesManager::handleFileMoveCall,
this, zoneId, _1, _2, _3));
zone->setProxyCallCallback(bind(&ZonesManager::handleProxyCall,
}
}
-void ZonesManager::notifyActiveZoneHandler(const std::string& caller,
- const std::string& application,
- const std::string& message)
+void ZonesManager::handleNotifyActiveZoneCall(const std::string& caller,
+ const std::string& application,
+ const std::string& message,
+ api::MethodResultBuilder::Pointer result)
{
- LOGI("notifyActiveZoneHandler(" << caller << ", " << application << ", " << message
+ LOGI("handleNotifyActiveZoneCall(" << caller << ", " << application << ", " << message
<< ") called");
Lock lock(mMutex);
if (iter != mZones.end() && caller != get(iter).getId()) {
get(iter).sendNotification(caller, application, message);
}
- } catch(const VasumException&) {
+ result->setVoid();
+ } catch (const VasumException&) {
LOGE("Notification from " << caller << " hasn't been sent");
+ result->setError(api::ERROR_INTERNAL, "Notification hasn't been sent");
}
}
-void ZonesManager::displayOffHandler(const std::string& /*caller*/)
+void ZonesManager::handleDisplayOffCall(const std::string& /*caller*/)
{
// get config of currently set zone and switch if switchToDefaultAfterTimeout is true
Lock lock(mMutex);
}
}
-void ZonesManager::handleZoneMoveFileRequest(const std::string& srcZoneId,
- const std::string& dstZoneId,
- const std::string& path,
- dbus::MethodResultBuilder::Pointer result)
+void ZonesManager::handleFileMoveCall(const std::string& srcZoneId,
+ const std::string& dstZoneId,
+ const std::string& path,
+ api::MethodResultBuilder::Pointer result)
{
// TODO: this implementation is only a placeholder.
// There are too many unanswered questions and security concerns:
}
Zone& srcZone = get(srcIter);
+ auto status = std::make_shared<api::FileMoveRequestStatus>();
+
auto dstIter = findZone(dstZoneId);
if (dstIter == mZones.end()) {
LOGE("Destination zone '" << dstZoneId << "' not found");
- result->set(g_variant_new("(s)", api::zone::FILE_MOVE_DESTINATION_NOT_FOUND.c_str()));
+ status->value = api::zone::FILE_MOVE_DESTINATION_NOT_FOUND;
+ result->set(status);
return;
}
Zone& dstContanier = get(dstIter);
if (srcZoneId == dstZoneId) {
LOGE("Cannot send a file to yourself");
- result->set(g_variant_new("(s)", api::zone::FILE_MOVE_WRONG_DESTINATION.c_str()));
+ status->value = api::zone::FILE_MOVE_WRONG_DESTINATION;
+ result->set(status);
return;
}
if (!regexMatchVector(path, srcZone.getPermittedToSend())) {
LOGE("Source zone has no permissions to send the file: " << path);
- result->set(g_variant_new("(s)", api::zone::FILE_MOVE_NO_PERMISSIONS_SEND.c_str()));
+ status->value = api::zone::FILE_MOVE_NO_PERMISSIONS_SEND;
+ result->set(status);
return;
}
if (!regexMatchVector(path, dstContanier.getPermittedToRecv())) {
LOGE("Destination zone has no permissions to receive the file: " << path);
- result->set(g_variant_new("(s)", api::zone::FILE_MOVE_NO_PERMISSIONS_RECEIVE.c_str()));
+ status->value = api::zone::FILE_MOVE_NO_PERMISSIONS_RECEIVE;
+ result->set(status);
return;
}
if (!utils::moveFile(srcPath, dstPath)) {
LOGE("Failed to move the file: " << path);
- result->set(g_variant_new("(s)", api::zone::FILE_MOVE_FAILED.c_str()));
+ status->value = api::zone::FILE_MOVE_FAILED;
+ result->set(status);
} else {
- result->set(g_variant_new("(s)", api::zone::FILE_MOVE_SUCCEEDED.c_str()));
+ status->value = api::zone::FILE_MOVE_SUCCEEDED;
+ result->set(status);
try {
dstContanier.sendNotification(srcZoneId, path, api::zone::FILE_MOVE_SUCCEEDED);
} catch (ServerException&) {
targetInterface,
targetMethod)) {
LOGW("Forbidden proxy call; " << caller << " -> " << target << "; " << targetBusName
- << "; " << targetObjectPath << "; " << targetInterface << "; " << targetMethod);
+ << "; " << targetObjectPath << "; " << targetInterface << "; " << targetMethod);
result->setError(api::ERROR_FORBIDDEN, "Proxy call forbidden");
return;
}
LOGI("Proxy call; " << caller << " -> " << target << "; " << targetBusName
- << "; " << targetObjectPath << "; " << targetInterface << "; " << targetMethod);
+ << "; " << targetObjectPath << "; " << targetInterface << "; " << targetMethod);
- auto asyncResultCallback = [result](dbus::AsyncMethodCallResult& asyncMethodCallResult) {
+ auto asyncResultCallback = [result](dbus::AsyncMethodCallResult & asyncMethodCallResult) {
try {
GVariant* targetResult = asyncMethodCallResult.get();
result->set(g_variant_new("(v)", targetResult));
Zone& targetZone = get(targetIter);
targetZone.proxyCallAsync(targetBusName,
- targetObjectPath,
- targetInterface,
- targetMethod,
- parameters,
- asyncResultCallback);
+ targetObjectPath,
+ targetInterface,
+ targetMethod,
+ parameters,
+ asyncResultCallback);
}
-void ZonesManager::handleGetZoneDbuses(dbus::MethodResultBuilder::Pointer result)
+void ZonesManager::handleGetZoneDbusesCall(api::MethodResultBuilder::Pointer result)
{
Lock lock(mMutex);
- std::vector<GVariant*> entries;
+ auto dbuses = std::make_shared<api::Dbuses>();
for (auto& zone : mZones) {
- GVariant* zoneId = g_variant_new_string(zone->getId().c_str());
- GVariant* dbusAddress = g_variant_new_string(zone->getDbusAddress().c_str());
- GVariant* entry = g_variant_new_dict_entry(zoneId, dbusAddress);
- entries.push_back(entry);
+ dbuses->values.push_back({zone->getId(), zone->getDbusAddress()});
}
- GVariant* dict = g_variant_new_array(G_VARIANT_TYPE("{ss}"), entries.data(), entries.size());
- result->set(g_variant_new("(@a{ss})", dict));
+ result->set(dbuses);
}
void ZonesManager::handleDbusStateChanged(const std::string& zoneId,
mHostConnection.signalZoneDbusState(zoneId, dbusAddress);
}
-void ZonesManager::handleGetZoneIdsCall(dbus::MethodResultBuilder::Pointer result)
+void ZonesManager::handleGetZoneIdsCall(api::MethodResultBuilder::Pointer result)
{
Lock lock(mMutex);
- std::vector<GVariant*> zoneIds;
- for(auto& zone: mZones){
- zoneIds.push_back(g_variant_new_string(zone->getId().c_str()));
+ auto zoneIds = std::make_shared<api::ZoneIds>();
+ for (const auto& zone : mZones) {
+ zoneIds->values.push_back(zone->getId());
}
- GVariant* array = g_variant_new_array(G_VARIANT_TYPE("s"),
- zoneIds.data(),
- zoneIds.size());
- result->set(g_variant_new("(@as)", array));
+ result->set(zoneIds);
}
-void ZonesManager::handleGetActiveZoneIdCall(dbus::MethodResultBuilder::Pointer result)
+void ZonesManager::handleGetActiveZoneIdCall(api::MethodResultBuilder::Pointer result)
{
LOGI("GetActiveZoneId call");
-
- std::string id = getRunningForegroundZoneId();
- result->set(g_variant_new("(s)", id.c_str()));
+ auto zoneId = std::make_shared<api::ZoneId>();
+ zoneId->value = getRunningForegroundZoneId();
+ result->set(zoneId);
}
void ZonesManager::handleGetZoneInfoCall(const std::string& id,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("GetZoneInfo call");
result->setError(api::ERROR_INVALID_ID, "No such zone id");
return;
}
+
Zone& zone = get(iter);
- const char* state;
+ auto zoneInfo = std::make_shared<api::ZoneInfo>();
if (zone.isRunning()) {
- state = "RUNNING";
+ zoneInfo->state = "RUNNING";
} else if (zone.isStopped()) {
- state = "STOPPED";
+ zoneInfo->state = "STOPPED";
} else if (zone.isPaused()) {
- state = "FROZEN";
+ zoneInfo->state = "FROZEN";
} else {
LOGE("Unrecognized state of zone id=" << id);
result->setError(api::ERROR_INTERNAL, "Unrecognized state of zone");
return;
}
- result->set(g_variant_new("((siss))",
- id.c_str(),
- zone.getVT(),
- state,
- zone.getRootPath().c_str()));
+ result->set(zoneInfo);
}
void ZonesManager::handleSetNetdevAttrsCall(const std::string& zone,
const std::string& netdev,
- const std::vector<
- std::tuple<std::string, std::string>>& attrs,
- dbus::MethodResultBuilder::Pointer result)
+ const std::vector<std::tuple<std::string, std::string>>& attrs,
+ api::MethodResultBuilder::Pointer result)
{
LOGI("SetNetdevAttrs call");
try {
Lock lock(mMutex);
-
getZone(zone).setNetdevAttrs(netdev, attrs);
result->setVoid();
} catch (const InvalidZoneIdException&) {
void ZonesManager::handleGetNetdevAttrsCall(const std::string& zone,
const std::string& netdev,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("GetNetdevAttrs call");
try {
Lock lock(mMutex);
-
+ auto netDevAttrs = std::make_shared<api::NetDevAttrs>();
const auto attrs = getZone(zone).getNetdevAttrs(netdev);
- GVariantBuilder builder;
- g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
- for (const auto entry : attrs) {
- g_variant_builder_add(&builder,
- "(ss)",
- std::get<0>(entry).c_str(),
- std::get<1>(entry).c_str());
+ for (size_t i = 0; i < attrs.size(); ++i) {
+ netDevAttrs->values.push_back({std::get<0>(attrs[i]), std::get<1>(attrs[i])});
}
- result->set(g_variant_builder_end(&builder));
+ result->set(netDevAttrs);
} catch (const InvalidZoneIdException&) {
LOGE("No zone with id=" << zone);
result->setError(api::ERROR_INVALID_ID, "No such zone id");
}
void ZonesManager::handleGetNetdevListCall(const std::string& zone,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("GetNetdevList call");
try {
Lock lock(mMutex);
- std::vector<GVariant*> netdevs;
- for(auto& netdev: getZone(zone).getNetdevList()){
- netdevs.push_back(g_variant_new_string(netdev.c_str()));
- }
- GVariant* array = g_variant_new_array(G_VARIANT_TYPE("s"),
- netdevs.data(),
- netdevs.size());
- result->set(g_variant_new("(@as)", array));
+ auto netDevList = std::make_shared<api::NetDevList>();
+ netDevList->values = getZone(zone).getNetdevList();
+ result->set(netDevList);
} catch (const InvalidZoneIdException&) {
LOGE("No zone with id=" << zone);
result->setError(api::ERROR_INVALID_ID, "No such zone id");
void ZonesManager::handleCreateNetdevVethCall(const std::string& zone,
const std::string& zoneDev,
const std::string& hostDev,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("CreateNetdevVeth call");
try {
const std::string& zoneDev,
const std::string& hostDev,
const uint32_t& mode,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("CreateNetdevMacvlan call");
try {
void ZonesManager::handleCreateNetdevPhysCall(const std::string& zone,
const std::string& devId,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("CreateNetdevPhys call");
try {
const std::string& path,
const int32_t& flags,
const int32_t& mode,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("DeclareFile call");
try {
Lock lock(mMutex);
-
- const std::string id = getZone(zone).declareFile(type, path, flags, mode);
- result->set(g_variant_new("(s)", id.c_str()));
+ auto declaration = std::make_shared<api::Declaration>();
+ declaration->value = getZone(zone).declareFile(type, path, flags, mode);
+ result->set(declaration);
} catch (const InvalidZoneIdException&) {
LOGE("No zone with id=" << zone);
result->setError(api::ERROR_INVALID_ID, "No such zone id");
const std::string& type,
const uint64_t& flags,
const std::string& data,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("DeclareMount call");
try {
Lock lock(mMutex);
-
- const std::string id = getZone(zone).declareMount(source, target, type, flags, data);
- result->set(g_variant_new("(s)", id.c_str()));
+ auto declaration = std::make_shared<api::Declaration>();
+ declaration->value = getZone(zone).declareMount(source, target, type, flags, data);
+ result->set(declaration);
} catch (const InvalidZoneIdException&) {
LOGE("No zone with id=" << zone);
result->setError(api::ERROR_INVALID_ID, "No such zone id");
void ZonesManager::handleDeclareLinkCall(const std::string& source,
const std::string& zone,
const std::string& target,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("DeclareLink call");
try {
Lock lock(mMutex);
-
- const std::string id = getZone(zone).declareLink(source, target);
- result->set(g_variant_new("(s)", id.c_str()));
+ auto declaration = std::make_shared<api::Declaration>();
+ declaration->value = getZone(zone).declareLink(source, target);
+ result->set(declaration);
} catch (const InvalidZoneIdException&) {
LOGE("No zone with id=" << zone);
result->setError(api::ERROR_INVALID_ID, "No such zone id");
}
void ZonesManager::handleGetDeclarationsCall(const std::string& zone,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("GetDeclarations call Id=" << zone);
try {
Lock lock(mMutex);
-
- std::vector<std::string> declarations = getZone(zone).getDeclarations();
-
- std::vector<GVariant*> out;
- for (auto declaration : declarations) {
- out.push_back(g_variant_new_string(declaration.c_str()));
- }
-
- GVariant* array = g_variant_new_array(G_VARIANT_TYPE("s"),
- out.data(),
- out.size());
- result->set(g_variant_new("(@as)", array));
+ auto declarations = std::make_shared<api::Declarations>();
+ declarations->values = getZone(zone).getDeclarations();
+ result->set(declarations);
} catch (const InvalidZoneIdException&) {
LOGE("No zone with id=" << zone);
result->setError(api::ERROR_INVALID_ID, "No such zone id");
LOGE(ex.what());
result->setError(api::ERROR_INTERNAL, ex.what());
}
-
}
void ZonesManager::handleRemoveDeclarationCall(const std::string& zone,
const std::string& declarationId,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("RemoveDeclaration call Id=" << zone);
try {
}
void ZonesManager::handleSetActiveZoneCall(const std::string& id,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("SetActiveZone call; Id=" << id );
Lock lock(mMutex);
auto iter = findZone(id);
- if (iter == mZones.end()){
+ if (iter == mZones.end()) {
LOGE("No zone with id=" << id );
result->setError(api::ERROR_INVALID_ID, "No such zone id");
return;
}
- if (!get(iter).isRunning()){
+ if (!get(iter).isRunning()) {
LOGE("Could not activate stopped or paused zone");
result->setError(api::host::ERROR_ZONE_NOT_RUNNING,
"Could not activate stopped or paused zone");
}
}
- auto removeAllWrapper = [](const std::string& path) -> bool {
+ auto removeAllWrapper = [](const std::string & path) -> bool {
try {
LOGD("Removing copied data");
fs::remove_all(fs::path(path));
- } catch(const std::exception& e) {
+ } catch (const std::exception& e) {
LOGW("Failed to remove data: " << boost::diagnostic_information(e));
}
return true;
void ZonesManager::handleCreateZoneCall(const std::string& id,
const std::string& templateName,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
try {
createZone(id, templateName);
}
void ZonesManager::handleDestroyZoneCall(const std::string& id,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
auto destroyer = [id, result, this] {
try {
}
void ZonesManager::handleShutdownZoneCall(const std::string& id,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("ShutdownZone call; Id=" << id );
}
void ZonesManager::handleStartZoneCall(const std::string& id,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("StartZone call; Id=" << id );
}
void ZonesManager::handleLockZoneCall(const std::string& id,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("LockZone call; Id=" << id );
}
void ZonesManager::handleUnlockZoneCall(const std::string& id,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("UnlockZone call; Id=" << id );
void ZonesManager::handleGrantDeviceCall(const std::string& id,
const std::string& device,
uint32_t flags,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("GrantDevice call; id=" << id << "; dev=" << device);
void ZonesManager::handleRevokeDeviceCall(const std::string& id,
const std::string& device,
- dbus::MethodResultBuilder::Pointer result)
+ api::MethodResultBuilder::Pointer result)
{
LOGI("RevokeDevice call; id=" << id << "; dev=" << device);
#include "input-monitor.hpp"
#include "proxy-call-policy.hpp"
#include "utils/worker.hpp"
+#include "api/method-result-builder.hpp"
#include <string>
#include <memory>
int getVTForNewZone();
void insertZone(const std::string& zoneId, const std::string& templatePath);
- void notifyActiveZoneHandler(const std::string& caller,
- const std::string& appliaction,
- const std::string& message);
- void displayOffHandler(const std::string& caller);
- void handleZoneMoveFileRequest(const std::string& srcZoneId,
- const std::string& dstZoneId,
- const std::string& path,
- dbus::MethodResultBuilder::Pointer result);
+ void handleNotifyActiveZoneCall(const std::string& caller,
+ const std::string& appliaction,
+ const std::string& message,
+ api::MethodResultBuilder::Pointer result);
+ void handleDisplayOffCall(const std::string& caller);
+ void handleFileMoveCall(const std::string& srcZoneId,
+ const std::string& dstZoneId,
+ const std::string& path,
+ api::MethodResultBuilder::Pointer result);
void handleProxyCall(const std::string& caller,
const std::string& target,
const std::string& targetBusName,
const std::string& targetMethod,
GVariant* parameters,
dbus::MethodResultBuilder::Pointer result);
- void handleGetZoneDbuses(dbus::MethodResultBuilder::Pointer result);
+ void handleGetZoneDbusesCall(api::MethodResultBuilder::Pointer result);
void handleDbusStateChanged(const std::string& zoneId, const std::string& dbusAddress);
- void handleGetZoneIdsCall(dbus::MethodResultBuilder::Pointer result);
- void handleGetActiveZoneIdCall(dbus::MethodResultBuilder::Pointer result);
- void handleGetZoneInfoCall(const std::string& id, dbus::MethodResultBuilder::Pointer result);
+ void handleGetZoneIdsCall(api::MethodResultBuilder::Pointer result);
+ void handleGetActiveZoneIdCall(api::MethodResultBuilder::Pointer result);
+ void handleGetZoneInfoCall(const std::string& id, api::MethodResultBuilder::Pointer result);
void handleSetNetdevAttrsCall(const std::string& zone,
const std::string& netdev,
const std::vector<std::tuple<std::string, std::string>>& attrs,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleGetNetdevAttrsCall(const std::string& zone,
const std::string& netdev,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleGetNetdevListCall(const std::string& zone,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleCreateNetdevVethCall(const std::string& zone,
const std::string& zoneDev,
const std::string& hostDev,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleCreateNetdevMacvlanCall(const std::string& zone,
const std::string& zoneDev,
const std::string& hostDev,
const uint32_t& mode,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleCreateNetdevPhysCall(const std::string& zone,
const std::string& devId,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleDeclareFileCall(const std::string& zone,
const int32_t& type,
const std::string& path,
const int32_t& flags,
const int32_t& mode,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleDeclareMountCall(const std::string& source,
const std::string& zone,
const std::string& target,
const std::string& type,
const uint64_t& flags,
const std::string& data,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleDeclareLinkCall(const std::string& source,
const std::string& zone,
const std::string& target,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleGetDeclarationsCall(const std::string& zone,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleRemoveDeclarationCall(const std::string& zone,
const std::string& declarationId,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleSetActiveZoneCall(const std::string& id,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleCreateZoneCall(const std::string& id,
const std::string& templateName,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleDestroyZoneCall(const std::string& id,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleShutdownZoneCall(const std::string& id,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleStartZoneCall(const std::string& id,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleLockZoneCall(const std::string& id,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleUnlockZoneCall(const std::string& id,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleGrantDeviceCall(const std::string& id,
const std::string& device,
uint32_t flags,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
void handleRevokeDeviceCall(const std::string& id,
const std::string& device,
- dbus::MethodResultBuilder::Pointer result);
+ api::MethodResultBuilder::Pointer result);
};
#include "utils/fs.hpp"
#include "utils/scoped-dir.hpp"
+#include "api/method-result-builder.hpp"
+
using namespace vasum;
using namespace vasum::utils;
Latch notifyCalled;
ZoneConnection connection(acquireAddress(), nullptr);
- auto callback = [&](const std::string& application, const std::string& message) {
+ auto callback = [&](const std::string& application, const std::string& message, api::MethodResultBuilder::Pointer result) {
if (application == "testapp" && message == "testmessage") {
notifyCalled.set();
}
+ result->setVoid();
};
connection.setNotifyActiveZoneCallback(callback);
const std::string& objectPath,
const std::string& interface,
const std::string& signalName,
- GVariant* parameters) {
+ GVariant* parameters) {
if (objectPath == api::zone::OBJECT_PATH &&
- interface == api::zone::INTERFACE &&
- signalName == api::zone::SIGNAL_NOTIFICATION &&
- g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) {
+ interface == api::zone::INTERFACE &&
+ signalName == api::zone::SIGNAL_NOTIFICATION &&
+ g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) {
const gchar* zone = NULL;
const gchar* application = NULL;
const gchar* message = NULL;
g_variant_get(parameters, "(&s&s&s)", &zone, &application, &message);
if (zone == std::string("testzone") &&
- application == std::string("testapp") &&
- message == std::string("testmessage")) {
+ application == std::string("testapp") &&
+ message == std::string("testmessage")) {
signalEmitted.set();
}
}
api::host::INTERFACE,
api::host::METHOD_GET_ZONE_DBUSES,
NULL,
- "(a{ss})");
+ "(a(ss))");
GVariant* array = NULL;
g_variant_get(result.get(), "(*)", &array);
dbus::GVariantPtr autounref(array, g_variant_unref);
for (size_t n = 0; n < count; ++n) {
const char* zoneId = NULL;
const char* dbusAddress = NULL;
- g_variant_get_child(array, n, "{&s&s}", &zoneId, &dbusAddress);
+ g_variant_get_child(array, n, "(&s&s)", &zoneId, &dbusAddress);
dbuses.insert(Dbuses::value_type(zoneId, dbusAddress));
}
return dbuses;