2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Mateusz Malicki <m.malicki2@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
22 * @author Mateusz Malicki (m.malicki2@samsung.com)
23 * @brief This file contains the public API for Vasum Client
28 #include "client/vasum-client.h"
30 int main(int argc, char** argv)
34 VsmArrayString values = NULL;
37 status = vsm_start_glib_loop(); // start glib loop (if not started any yet)
38 if (VSMCLIENT_SUCCESS != status) {
43 client = vsm_client_create(); // create client handle
50 status = vsm_connect(client); // connect to dbus
51 if (VSMCLIENT_SUCCESS != status) {
57 status = vsm_get_zone_ids(client, &values);
58 if (VSMCLIENT_SUCCESS != status) {
65 for (VsmArrayString iValues = values; *iValues; iValues++) {
66 printf("%s\n", *iValues);
70 vsm_array_string_free(values); // free memory
71 vsm_client_free(client); // destroy client handle
72 vsm_stop_glib_loop(); // stop the glib loop (use only with vsm_start_glib_loop)
78 #ifndef VASUM_CLIENT_H
79 #define VASUM_CLIENT_H
83 #include <netinet/ip.h>
91 * vasum-server's client pointer.
93 typedef void* VsmClient;
96 * NULL-terminated string type.
98 * @sa vsm_array_string_free
100 typedef char* VsmString;
103 * NULL-terminated array of strings type.
105 * @sa vsm_string_free
107 typedef VsmString* VsmArrayString;
110 * Completion status of communication function.
113 VSMCLIENT_CUSTOM_ERROR, /**< User specified error */
114 VSMCLIENT_IO_ERROR, /**< Input/Output error */
115 VSMCLIENT_OPERATION_FAILED, /**< Operation failed */
116 VSMCLIENT_INVALID_ARGUMENT, /**< Invalid argument */
117 VSMCLIENT_OTHER_ERROR, /**< Other error */
118 VSMCLIENT_SUCCESS /**< Success */
124 typedef unsigned int VsmSubscriptionId;
144 * Zone information structure
156 typedef VsmZoneStructure* VsmZone;
159 * Netowrk device type
168 * Network device information structure
173 } VsmNetdevStructure;
176 * Network device information
178 typedef VsmNetdevStructure* VsmNetdev;
192 * Do not call this function if an application creates a glib loop itself.
193 * Otherwise, call it before any other function from this library.
195 * @return status of this function call
197 VsmStatus vsm_start_glib_loop();
202 * Call only if vsm_start_glib_loop() was called.
204 * @return status of this function call
206 VsmStatus vsm_stop_glib_loop();
209 * Create a new vasum-server's client.
211 * @return Created client pointer or NULL on failure.
213 VsmClient vsm_client_create();
216 * Release client resources.
218 * @param[in] client vasum-server's client
220 void vsm_client_free(VsmClient client);
223 * Get status code of last vasum-server communication.
225 * @param[in] client vasum-server's client
226 * @return status of this function call
228 VsmStatus vsm_get_status(VsmClient client);
231 * Get status message of the last vasum-server communication.
233 * @param[in] client vasum-server's client
234 * @return last status message from vasum-server communication
236 const char* vsm_get_status_message(VsmClient client);
239 * Connect client to the vasum-server.
241 * @param[in] client vasum-server's client
242 * @return status of this function call
244 VsmStatus vsm_connect(VsmClient client);
247 * Connect client to the vasum-server via custom address.
249 * @param[in] client vasum-server's client
250 * @param[in] address dbus address
251 * @return status of this function call
253 VsmStatus vsm_connect_custom(VsmClient client, const char* address);
256 * Release VsmArrayString.
258 * @param[in] astring VsmArrayString
260 void vsm_array_string_free(VsmArrayString astring);
265 * @param string VsmString
267 void vsm_string_free(VsmString string);
272 * @param zone VsmZone
274 void vsm_zone_free(VsmZone zone);
279 * @param netdev VsmNetdev
281 void vsm_netdev_free(VsmNetdev netdev);
286 * Functions using org.tizen.vasum.host.manager D-Bus interface.
292 * Zone's D-Bus state change callback function signature.
294 * @param[in] zoneId affected zone id
295 * @param[in] dbusAddress new D-Bus address
296 * @param data custom user's data pointer passed to vsm_add_state_callback() function
298 typedef void (*VsmZoneDbusStateCallback)(const char* zoneId,
299 const char* dbusAddress,
303 * Get dbus address of each zone.
305 * @param[in] client vasum-server's client
306 * @param[out] keys array of zones name
307 * @param[out] values array of zones dbus address
308 * @return status of this function call
309 * @post keys[i] corresponds to values[i]
310 * @remark Use vsm_array_string_free() to free memory occupied by @p keys and @p values.
312 VsmStatus vsm_get_zone_dbuses(VsmClient client, VsmArrayString* keys, VsmArrayString* values);
317 * @param[in] client vasum-server's client
318 * @param[out] array array of zones name
319 * @return status of this function call
320 * @remark Use vsm_array_string_free() to free memory occupied by @p array.
322 VsmStatus vsm_get_zone_ids(VsmClient client, VsmArrayString* array);
325 * Get active (foreground) zone name.
327 * @param[in] client vasum-server's client
328 * @param[out] id active zone name
329 * @return status of this function call
330 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
332 VsmStatus vsm_get_active_zone_id(VsmClient client, VsmString* id);
335 * Get zone name of process with given pid.
337 * @param[in] client vasum-server's client
338 * @param[in] pid process id
339 * @param[out] id active zone name
340 * @return status of this function call
341 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
343 VsmStatus vsm_lookup_zone_by_pid(VsmClient client, int pid, VsmString* id);
346 * Get zone informations of zone with given id.
348 * @param[in] client vasum-server's client
349 * @param[in] id zone name
350 * @param[out] zone zone informations
351 * @return status of this function call
352 * @remark Use @p vsm_zone_free() to free memory occupied by @p zone
354 VsmStatus vsm_lookup_zone_by_id(VsmClient client, const char* id, VsmZone* zone);
357 * Get zone name with given terminal.
359 * @param[in] client vasum-server's client
360 * @param[in] terminal terminal id
361 * @param[out] id zone name with given terminal
362 * @return status of this function call
363 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
365 VsmStatus vsm_lookup_zone_by_terminal_id(VsmClient client, int terminal, VsmString* id);
368 * Set active (foreground) zone.
370 * @param[in] client vasum-server's client
371 * @param[in] id zone name
372 * @return status of this function call
374 VsmStatus vsm_set_active_zone(VsmClient client, const char* id);
377 * Create and add zone
379 * @param[in] client vasum-server's client
380 * @param[in] id zone id
381 * @param[in] tname template name, NULL for default
382 * @return status of this function call
384 VsmStatus vsm_create_zone(VsmClient client, const char* id, const char* tname);
389 * @param[in] client vasum-server's client
390 * @param[in] id zone id
391 * @param[in] force if 0 data will be kept, otherwise data will be lost
392 * @return status of this function call
394 VsmStatus vsm_destroy_zone(VsmClient client, const char* id, int force);
399 * @param[in] client vasum-server's client
400 * @param[in] id zone name
401 * @return status of this function call
403 VsmStatus vsm_shutdown_zone(VsmClient client, const char* id);
408 * @param[in] client vasum-server's client
409 * @param[in] id zone name
410 * @return status of this function call
412 VsmStatus vsm_start_zone(VsmClient client, const char* id);
417 * @param[in] client vasum-server's client
418 * @param[in] id zone name
419 * @return status of this function call
421 VsmStatus vsm_lock_zone(VsmClient client, const char* id);
426 * @param[in] client vasum-server's client
427 * @param[in] id zone name
428 * @return status of this function call
430 VsmStatus vsm_unlock_zone(VsmClient client, const char* id);
433 * Register dbus state change callback function.
435 * @note The callback function will be invoked on a different thread.
437 * @param[in] client vasum-server's client
438 * @param[in] zoneDbusStateCallback callback function
439 * @param[in] data some extra data that will be passed to callback function
440 * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal,
441 * pointer can be NULL.
442 * @return status of this function call
444 VsmStatus vsm_add_state_callback(VsmClient client,
445 VsmZoneDbusStateCallback zoneDbusStateCallback,
447 VsmSubscriptionId* subscriptionId);
450 * Unregister dbus state change callback function.
452 * @param[in] client vasum-server's client
453 * @param[in] subscriptionId subscription identifier returned by vsm_add_state_callback
454 * @return status of this function call
456 VsmStatus vsm_del_state_callback(VsmClient client, VsmSubscriptionId subscriptionId);
459 * Grant access to device
461 * @param[in] client vasum-server's client
462 * @param[in] zone zone name
463 * @param[in] device device path
464 * @param[in] flags access flags
465 * @return status of this function call
467 VsmStatus vsm_grant_device(VsmClient client,
473 * Revoke access to device
475 * @param[in] client vasum-server's client
476 * @param[in] zone zone name
477 * @param[in] device device path
478 * @return status of this function call
480 VsmStatus vsm_revoke_device(VsmClient client, const char* zone, const char* device);
483 * Get array of netdev from given zone
485 * @param[in] client vasum-server's client
486 * @param[in] zone zone name
487 * @param[out] netdevIds array of netdev id
488 * @return status of this function call
489 * @remark Use vsm_array_string_free() to free memory occupied by @p netdevIds.
491 VsmStatus vsm_zone_get_netdevs(VsmClient client, const char* zone, VsmArrayString* netdevIds);
494 * Get ipv4 address for given netdevId
496 * @param[in] client vasum-server's client
497 * @param[in] zone zone name
498 * @param[in] netdevId netdev id
499 * @param[out] addr ipv4 address
500 * @return status of this function call
502 VsmStatus vsm_netdev_get_ipv4_addr(VsmClient client,
504 const char* netdevId,
505 struct in_addr *addr);
508 * Get ipv6 address for given netdevId
510 * @param[in] client vasum-server's client
511 * @param[in] zone zone name
512 * @param[in] netdevId netdev id
513 * @param[out] addr ipv6 address
514 * @return status of this function call
516 VsmStatus vsm_netdev_get_ipv6_addr(VsmClient client,
518 const char* netdevId,
519 struct in6_addr *addr);
522 * Set ipv4 address for given netdevId
524 * @param[in] client vasum-server's client
525 * @param[in] zone zone name
526 * @param[in] netdevId netdev id
527 * @param[in] addr ipv4 address
528 * @param[in] prefix bit-length of the network prefix
529 * @return status of this function call
531 VsmStatus vsm_netdev_set_ipv4_addr(VsmClient client,
533 const char* netdevId,
534 struct in_addr *addr,
538 * Set ipv6 address for given netdevId
540 * @param[in] client vasum-server's client
541 * @param[in] zone zone name
542 * @param[in] netdevId netdev id
543 * @param[in] addr ipv6 address
544 * @param[in] prefix bit-length of the network prefix
545 * @return status of this function call
547 VsmStatus vsm_netdev_set_ipv6_addr(VsmClient client,
549 const char* netdevId,
550 struct in6_addr *addr,
554 * Create netdev in zone
556 * @param[in] client vasum-server's client
557 * @param[in] zone zone name
558 * @param[in] netdevType netdev type
559 * @param[in] target TODO: this is taken form zone-control
560 * @param[in] netdevId network device id
561 * @return status of this function call
563 VsmStatus vsm_create_netdev(VsmClient client,
565 VsmNetdevType netdevType,
567 const char* netdevId);
570 * Remove netdev from zone
572 * @param[in] client vasum-server's client
573 * @param[in] zone zone name
574 * @param[in] netdevId network device id
575 * @return status of this function call
577 VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* netdevId);
580 * Get netdev informations
582 * @param[in] client vasum-server's client
583 * @param[in] zone zone name
584 * @param[in] netdevId network device id
585 * @param[out] netdev netdev informations
586 * @return status of this function call
587 * @remark Use vsm_netdev_free() to free memory occupied by @p netdev.
589 VsmStatus vsm_lookup_netdev_by_name(VsmClient client,
591 const char* netdevId,
595 * Create file, directory or pipe in zone
597 * Declare file, directory or pipe that will be created while zone startup
599 * @param[in] client vasum-server's client
600 * @param[in] type file type
601 * @param[in] zone zone id
602 * @param[in] path path to file
603 * @param[in] flags if O_CREAT bit is set then file will be created in zone,
604 * otherwise file will by copied from host;
605 * it is meaningful only when O_CREAT is set
606 * @param[in] mode mode of file
607 * @return status of this function call
609 VsmStatus vsm_declare_file(VsmClient client,
617 * Create mount point in zone
619 * Declare mount that will be created while zone startup
620 * Parameters are passed to mount system function
622 * @param[in] client vasum-server's client
623 * @param[in] source device path (path in host)
624 * @param[in] zone zone id
625 * @param[in] target mount point (path in zone)
626 * @param[in] type filesystem type
627 * @param[in] flags mount flags as in mount function
628 * @param[in] data additional data as in mount function
629 * @return status of this function call
631 VsmStatus vsm_declare_mount(VsmClient client,
640 * Create link in zone
642 * Declare link that will be created while zone startup
643 * Parameters are passed to link system function
645 * @param[in] client vasum-server's client
646 * @param[in] source path to link source (in host)
647 * @param[in] zone zone id
648 * @param[in] target path to link name (in zone)
649 * @return status of this function call
651 VsmStatus vsm_declare_link(VsmClient client,
657 * Get all declarations
659 * Gets all declarations of resourcies
660 * (@see ::vsm_declare_link, @see ::vsm_declare_mount, @see ::vsm_declare_linki)
662 * @param[in] client vasum-server's client
663 * @param[in] zone zone id
664 * @param[out] declarations array of declarations id
665 * @return status of this function call
667 VsmStatus vsm_list_declarations(VsmClient client,
669 VsmArrayString* declarations);
674 * Removes given declaration by its id (@see ::vsm_list_declarations)
676 * @param[in] client vasum-server's client
677 * @param[in] zone zone id
678 * @param[in] declaration declaration id
679 * @return status of this function call
681 VsmStatus vsm_remove_declaration(VsmClient client,
683 VsmString declaration);
692 * Functions using org.tizen.vasum.zone.manager D-Bus interface.
698 * Notification callback function signature.
700 * @param[in] zone source zone
701 * @param[in] application sending application name
702 * @param[in] message notification message
703 * @param data custom user's data pointer passed to vsm_add_notification_callback()
705 typedef void (*VsmNotificationCallback)(const char* zone,
706 const char* application,
710 * Send message to active zone.
712 * @param[in] client vasum-server's client
713 * @param[in] application application name
714 * @param[in] message message
715 * @return status of this function call
717 VsmStatus vsm_notify_active_zone(VsmClient client, const char* application, const char* message);
720 * Move file between zones.
722 * @param[in] client vasum-server's client
723 * @param[in] destZone destination zone id
724 * @param[in] path path to moved file
725 * @return status of this function call
727 VsmStatus vsm_file_move_request(VsmClient client, const char* destZone, const char* path);
730 * Register notification callback function.
732 * @note The callback function will be invoked on a different thread.
734 * @param[in] client vasum-server's client
735 * @param[in] notificationCallback callback function
736 * @param[in] data some extra data that will be passed to callback function
737 * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal,
738 * pointer can be NULL.
739 * @return status of this function call
741 VsmStatus vsm_add_notification_callback(VsmClient client,
742 VsmNotificationCallback notificationCallback,
744 VsmSubscriptionId* subscriptionId);
747 * Unregister notification callback function.
749 * @param[in] client vasum-server's client
750 * @param[in] subscriptionId subscription identifier returned by vsm_add_notification_callback
751 * @return status of this function call
753 VsmStatus vsm_del_notification_callback(VsmClient client, VsmSubscriptionId subscriptionId);
761 #endif /* VASUM_CLIENT_H */