VsmFileType type,
const char *path,
int32_t flags,
- mode_t mode) noexcept
+ mode_t mode,
+ VsmString* id) noexcept
{
assert(path);
+ GVariant* out = NULL;
GVariant* args_in = g_variant_new("(sisii)", zone, type, path, flags, mode);
- return callMethod(ZONE_INTERFACE,
- api::host::METHOD_DECLARE_FILE,
- args_in);
+ VsmStatus ret = callMethod(HOST_INTERFACE,
+ api::host::METHOD_DECLARE_FILE,
+ args_in,
+ "(s)",
+ &out);
+ if (ret != VSMCLIENT_SUCCESS) {
+ return ret;
+ }
+ GVariant* unpacked;
+ if (id != NULL) {
+ g_variant_get(out, "(*)", &unpacked);
+ toBasic(unpacked, id);
+ g_variant_unref(unpacked);
+ }
+ g_variant_unref(out);
+ return ret;
}
VsmStatus Client::vsm_declare_mount(const char *source,
const char *target,
const char *type,
uint64_t flags,
- const char *data) noexcept
+ const char *data,
+ VsmString* id) noexcept
{
assert(source);
assert(target);
data = "";
}
+ GVariant* out = NULL;
GVariant* args_in = g_variant_new("(ssssts)", source, zone, target, type, flags, data);
- return callMethod(ZONE_INTERFACE,
- api::host::METHOD_DECLARE_MOUNT,
- args_in);
+ VsmStatus ret = callMethod(HOST_INTERFACE,
+ api::host::METHOD_DECLARE_MOUNT,
+ args_in,
+ "(s)",
+ &out);
+ if (ret != VSMCLIENT_SUCCESS) {
+ return ret;
+ }
+ GVariant* unpacked;
+ if (id != NULL) {
+ g_variant_get(out, "(*)", &unpacked);
+ toBasic(unpacked, id);
+ g_variant_unref(unpacked);
+ }
+ g_variant_unref(out);
+ return ret;
}
VsmStatus Client::vsm_declare_link(const char *source,
const char* zone,
- const char *target) noexcept
+ const char *target,
+ VsmString* id) noexcept
{
assert(source);
assert(target);
+ GVariant* out = NULL;
GVariant* args_in = g_variant_new("(sss)", source, zone, target);
- return callMethod(ZONE_INTERFACE,
- api::host::METHOD_DECLARE_LINK,
+ VsmStatus ret = callMethod(HOST_INTERFACE,
+ api::host::METHOD_DECLARE_LINK,
+ args_in,
+ "(s)",
+ &out);
+ if (ret != VSMCLIENT_SUCCESS) {
+ return ret;
+ }
+ GVariant* unpacked;
+ if (id != NULL) {
+ g_variant_get(out, "(*)", &unpacked);
+ toBasic(unpacked, id);
+ g_variant_unref(unpacked);
+ }
+ g_variant_unref(out);
+ return ret;
+}
+
+VsmStatus Client::vsm_list_declarations(const char* zone, VsmArrayString* declarations)
+{
+ assert(declarations);
+
+ GVariant* out = NULL;
+ GVariant* args_in = g_variant_new("(s)", zone);
+ VsmStatus ret = callMethod(HOST_INTERFACE,
+ api::host::METHOD_GET_DECLARATIONS,
+ args_in,
+ "(as)",
+ &out);
+ if (ret != VSMCLIENT_SUCCESS) {
+ return ret;
+ }
+ GVariant* unpacked;
+ g_variant_get(out, "(*)", &unpacked);
+ toArray(unpacked, declarations);
+ g_variant_unref(unpacked);
+ g_variant_unref(out);
+ return ret;
+}
+
+VsmStatus Client::vsm_remove_declaration(const char* zone, VsmString declaration)
+{
+ assert(declaration);
+
+ GVariant* args_in = g_variant_new("(ss)", zone, declaration);
+ return callMethod(HOST_INTERFACE,
+ api::host::METHOD_REMOVE_DECLARATION,
args_in);
}
VsmFileType type,
const char* path,
int32_t flags,
- mode_t mode) noexcept;
+ mode_t mode,
+ VsmString* id) noexcept;
/**
* @see ::vsm_declare_mount
const char* target,
const char* type,
uint64_t flags,
- const char* data) noexcept;
+ const char* data,
+ VsmString* id) noexcept;
/**
* @see ::vsm_declare_link
*/
VsmStatus vsm_declare_link(const char* source,
const char* zone,
- const char* target) noexcept;
+ const char* target,
+ VsmString* id) noexcept;
+
+ /**
+ * @see ::vsm_list_declarations
+ */
+ VsmStatus vsm_list_declarations(const char* zone, VsmArrayString* declarations);
+
+ /**
+ * @see ::vsm_remove_declaration
+ */
+ VsmStatus vsm_remove_declaration(const char* zone, VsmString declaration);
/**
* @see ::vsm_notify_active_zone
int32_t flags,
mode_t mode)
{
- return getClient(client).vsm_declare_file(zone, type, path, flags, mode);
+ return getClient(client).vsm_declare_file(zone, type, path, flags, mode, NULL);
}
uint64_t flags,
const char* data)
{
- return getClient(client).vsm_declare_mount(source, zone, target, type, flags, data);
+ return getClient(client).vsm_declare_mount(source, zone, target, type, flags, data, NULL);
}
API VsmStatus vsm_declare_link(VsmClient client,
const char* zone,
const char* target)
{
- return getClient(client).vsm_declare_link(source, zone, target);
+ return getClient(client).vsm_declare_link(source, zone, target, NULL);
}
+API VsmStatus vsm_list_declarations(VsmClient client,
+ const char* zone,
+ VsmArrayString* declarations)
+{
+ return getClient(client).vsm_list_declarations(zone, declarations);
+}
+
+API VsmStatus vsm_remove_declaration(VsmClient client,
+ const char* zone,
+ VsmString declaration)
+{
+ return getClient(client).vsm_remove_declaration(zone, declaration);
+}
API VsmStatus vsm_notify_active_zone(VsmClient client,
const char* application,
const char* zone,
const char *target);
+/**
+ * Get all declarations
+ *
+ * Gets all declarations of resourcies
+ * (@see ::vsm_declare_link, @see ::vsm_declare_mount, @see ::vsm_declare_linki)
+ *
+ * @param[in] client vasum-server's client
+ * @param[in] zone zone id
+ * @param[out] declarations array of declarations id
+ * @return status of this function call
+ */
+VsmStatus vsm_list_declarations(VsmClient client,
+ const char* zone,
+ VsmArrayString* declarations);
+
+/**
+ * Remove declaration
+ *
+ * Removes given declaration by its id (@see ::vsm_list_declarations)
+ *
+ * @param[in] client vasum-server's client
+ * @param[in] zone zone id
+ * @param[in] declaration declaration id
+ * @return status of this function call
+ */
+VsmStatus vsm_remove_declaration(VsmClient client,
+ const char* zone,
+ VsmString declaration);
+
/** @} Host API */
mDeclareLinkCallback = callback;
}
+void HostConnection::setGetDeclarationsCallback(const GetDeclarationsCallback& callback)
+{
+ mGetDeclarationsCallback = callback;
+}
+
+void HostConnection::setRemoveDeclarationCallback(const RemoveDeclarationCallback& callback)
+{
+ mRemoveDeclarationCallback = callback;
+}
+
void HostConnection::setSetActiveZoneCallback(const SetActiveZoneCallback& callback)
{
mSetActiveZoneCallback = callback;
return;
}
+ if (methodName == api::host::METHOD_GET_DECLARATIONS) {
+ const gchar* zone;
+ g_variant_get(parameters, "(&s)", &zone);
+
+ if (mGetDeclarationsCallback) {
+ mGetDeclarationsCallback(zone, result);
+ }
+ return;
+ }
+
+ if (methodName == api::host::METHOD_REMOVE_DECLARATION) {
+ const gchar* zone;
+ const gchar* declarationId;
+ g_variant_get(parameters, "(&s&s)", &zone, &declarationId);
+
+ if (mRemoveDeclarationCallback) {
+ mRemoveDeclarationCallback(zone, declarationId, result);
+ }
+ return;
+ }
+
if (methodName == api::host::METHOD_CREATE_ZONE) {
const gchar* id = NULL;
g_variant_get(parameters, "(&s)", &id);
)> DeclareLinkCallback;
typedef std::function<void(const std::string& id,
dbus::MethodResultBuilder::Pointer result
+ )> GetDeclarationsCallback;
+ typedef std::function<void(const std::string& id,
+ const std::string& declarationId,
+ dbus::MethodResultBuilder::Pointer result
+ )> RemoveDeclarationCallback;
+ typedef std::function<void(const std::string& id,
+ dbus::MethodResultBuilder::Pointer result
)> SetActiveZoneCallback;
typedef std::function<void(const std::string& id,
dbus::MethodResultBuilder::Pointer result
void setDeclareLinkCallback(const DeclareLinkCallback& callback);
/**
+ * Register a callback called to list declarations
+ */
+ void setGetDeclarationsCallback(const GetDeclarationsCallback& callback);
+
+ /**
+ * Register a callback called to remove declarartion
+ */
+ void setRemoveDeclarationCallback(const RemoveDeclarationCallback& callback);
+
+ /**
* Register a callback called to set the active zone
*/
void setSetActiveZoneCallback(const SetActiveZoneCallback& callback);
DeclareFileCallback mDeclareFileCallback;
DeclareMountCallback mDeclareMountCallback;
DeclareLinkCallback mDeclareLinkCallback;
+ GetDeclarationsCallback mGetDeclarationsCallback;
+ RemoveDeclarationCallback mRemoveDeclarationCallback;
SetActiveZoneCallback mSetActiveZoneCallback;
CreateZoneCallback mCreateZoneCallback;
DestroyZoneCallback mDestroyZoneCallback;
const std::string METHOD_DECLARE_FILE = "DeclareFile";
const std::string METHOD_DECLARE_MOUNT = "DeclareMount";
const std::string METHOD_DECLARE_LINK = "DeclareLink";
+const std::string METHOD_GET_DECLARATIONS = "GetDeclarations";
+const std::string METHOD_REMOVE_DECLARATION = "RemoveDeclaration";
const std::string METHOD_SET_ACTIVE_ZONE = "SetActiveZone";
const std::string METHOD_CREATE_ZONE = "CreateZone";
const std::string METHOD_DESTROY_ZONE = "DestroyZone";
" <arg type='s' name='path' direction='in'/>"
" <arg type='i' name='flags' direction='in'/>"
" <arg type='i' name='mode' direction='in'/>"
+ " <arg type='s' name='id' direction='out'/>"
" </method>"
" <method name='" + METHOD_DECLARE_MOUNT + "'>"
" <arg type='s' name='source' direction='in'/>"
" <arg type='s' name='type' direction='in'/>"
" <arg type='t' name='flags' direction='in'/>"
" <arg type='s' name='data' direction='in'/>"
+ " <arg type='s' name='id' direction='out'/>"
" </method>"
" <method name='" + METHOD_DECLARE_LINK + "'>"
" <arg type='s' name='source' direction='in'/>"
" <arg type='s' name='zone' direction='in'/>"
" <arg type='s' name='target' direction='in'/>"
+ " <arg type='s' name='id' direction='out'/>"
+ " </method>"
+ " <method name='" + METHOD_GET_DECLARATIONS + "'>"
+ " <arg type='s' name='zone' direction='in'/>"
+ " <arg type='as' name='list' direction='out'/>"
+ " </method>"
+ " <method name='" + METHOD_REMOVE_DECLARATION + "'>"
+ " <arg type='s' name='zone' direction='in'/>"
+ " <arg type='s' name='declaration' direction='in'/>"
" </method>"
" <method name='" + METHOD_SET_ACTIVE_ZONE + "'>"
" <arg type='s' name='id' direction='in'/>"
return mProvision->declareLink(source, target);
}
+std::vector<std::string> Zone::getDeclarations() const
+{
+ return mProvision->list();
+}
+
+void Zone::removeDeclaration(const std::string& declarationId)
+{
+ mProvision->remove(declarationId);
+}
+
} // namespace vasum
std::string declareLink(const std::string& source,
const std::string& target);
- /**
+ /**
+ * Gets all declarations
+ */
+ std::vector<std::string> getDeclarations() const;
+
+ /**
+ * Remove declaration
+ */
+ void removeDeclaration(const std::string& declarationId);
+
+ /**
* Get zone root path
*/
std::string getRootPath() const;
mHostConnection.setDeclareLinkCallback(bind(&ZonesManager::handleDeclareLinkCall,
this, _1, _2, _3, _4));
+ mHostConnection.setGetDeclarationsCallback(bind(&ZonesManager::handleGetDeclarationsCall,
+ this, _1, _2));
+
+ mHostConnection.setRemoveDeclarationCallback(bind(&ZonesManager::handleRemoveDeclarationCall,
+ this, _1, _2, _3));
+
mHostConnection.setSetActiveZoneCallback(bind(&ZonesManager::handleSetActiveZoneCall,
this, _1, _2));
entries.push_back(entry);
}
GVariant* dict = g_variant_new_array(G_VARIANT_TYPE("{ss}"), entries.data(), entries.size());
- result->set(g_variant_new("(*)", dict));
+ result->set(g_variant_new("(@a{ss})", dict));
}
void ZonesManager::handleDbusStateChanged(const std::string& zoneId,
GVariant* array = g_variant_new_array(G_VARIANT_TYPE("s"),
zoneIds.data(),
zoneIds.size());
- result->set(g_variant_new("(*)", array));
+ result->set(g_variant_new("(@as)", array));
}
void ZonesManager::handleGetActiveZoneIdCall(dbus::MethodResultBuilder::Pointer result)
try {
Lock lock(mMutex);
- at(mZones, zone).declareFile(type, path, flags, mode);
- result->setVoid();
+ const std::string id = at(mZones, zone).declareFile(type, path, flags, mode);
+ result->set(g_variant_new("(s)", id.c_str()));
} catch (const std::out_of_range&) {
LOGE("No zone with id=" << zone);
result->setError(api::ERROR_INVALID_ID, "No such zone id");
try {
Lock lock(mMutex);
- at(mZones, zone).declareMount(source, target, type, flags, data);
- result->setVoid();
+ const std::string id = at(mZones, zone).declareMount(source, target, type, flags, data);
+ result->set(g_variant_new("(s)", id.c_str()));
} catch (const std::out_of_range&) {
LOGE("No zone with id=" << zone);
result->setError(api::ERROR_INVALID_ID, "No such zone id");
try {
Lock lock(mMutex);
- at(mZones, zone).declareLink(source, target);
- result->setVoid();
+ const std::string id = at(mZones, zone).declareLink(source, target);
+ result->set(g_variant_new("(s)", id.c_str()));
} catch (const std::out_of_range&) {
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)
+{
+ LOGI("GetDeclarations call Id=" << zone);
+ try {
+ Lock lock(mMutex);
+
+ std::vector<std::string> declarations = at(mZones, 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));
+ } catch (const std::out_of_range&) {
+ LOGE("No zone with id=" << zone);
+ result->setError(api::ERROR_INVALID_ID, "No such zone id");
+ } catch (const VasumException& ex) {
+ 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)
+{
+ LOGI("RemoveDeclaration call Id=" << zone);
+ try {
+ Lock lock(mMutex);
+
+ at(mZones, zone).removeDeclaration(declarationId);
+
+ result->setVoid();
+ } catch (const std::out_of_range&) {
+ LOGE("No zone with id=" << zone);
+ result->setError(api::ERROR_INVALID_ID, "No such zone id");
+ } catch (const VasumException& ex) {
+ LOGE(ex.what());
+ result->setError(api::ERROR_INTERNAL, ex.what());
+ }
+}
+
void ZonesManager::handleSetActiveZoneCall(const std::string& id,
dbus::MethodResultBuilder::Pointer result)
{
const std::string& zone,
const std::string& target,
dbus::MethodResultBuilder::Pointer result);
+ void handleGetDeclarationsCall(const std::string& zone,
+ dbus::MethodResultBuilder::Pointer result);
+ void handleRemoveDeclarationCall(const std::string& zone,
+ const std::string& declarationId,
+ dbus::MethodResultBuilder::Pointer result);
void handleSetActiveZoneCall(const std::string& id,
dbus::MethodResultBuilder::Pointer result);
void handleCreateZoneCall(const std::string& id,
vsm_client_free(client);
}
+BOOST_AUTO_TEST_CASE(ProvisionTest)
+{
+ VsmClient client = vsm_client_create();
+ BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, vsm_connect(client));
+ const std::string zone = cm.getRunningForegroundZoneId();
+ VsmArrayString declarations;
+ BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, vsm_list_declarations(client, zone.c_str(), &declarations));
+ BOOST_REQUIRE(declarations != NULL && declarations[0] == NULL);
+ vsm_array_string_free(declarations);
+ BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, vsm_declare_link(client, "/tmp/fake", zone.c_str(), "/tmp/fake/"));
+ BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, vsm_list_declarations(client, zone.c_str(), &declarations));
+ BOOST_REQUIRE(declarations != NULL && declarations[0] != NULL && declarations[1] == NULL);
+ BOOST_CHECK_EQUAL(VSMCLIENT_SUCCESS, vsm_remove_declaration(client, zone.c_str(), declarations[0]));
+ vsm_array_string_free(declarations);
+ BOOST_CHECK_EQUAL(VSMCLIENT_SUCCESS, vsm_list_declarations(client, zone.c_str(), &declarations));
+ BOOST_CHECK(declarations != NULL && declarations[0] == NULL);
+ vsm_array_string_free(declarations);
+ vsm_client_free(client);
+}
+
BOOST_AUTO_TEST_SUITE_END()