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 client = vsm_client_create(); // create client handle
44 status = vsm_connect(client); // connect to dbus
45 if (VSMCLIENT_SUCCESS != status) {
51 status = vsm_get_zone_ids(client, &values);
52 if (VSMCLIENT_SUCCESS != status) {
59 for (VsmArrayString iValues = values; *iValues; iValues++) {
60 printf("%s\n", *iValues);
64 vsm_array_string_free(values); // free memory
65 vsm_client_free(client); // destroy client handle
71 #ifndef VASUM_CLIENT_H
72 #define VASUM_CLIENT_H
76 #include <netinet/ip.h>
77 #include <linux/if_link.h>
85 * vasum-server's client pointer.
87 typedef void* VsmClient;
90 * NULL-terminated string type.
92 * @sa vsm_array_string_free
94 typedef char* VsmString;
97 * NULL-terminated array of strings type.
101 typedef VsmString* VsmArrayString;
104 * Completion status of communication function.
107 VSMCLIENT_CUSTOM_ERROR, /**< User specified error */
108 VSMCLIENT_IO_ERROR, /**< Input/Output error */
109 VSMCLIENT_OPERATION_FAILED, /**< Operation failed */
110 VSMCLIENT_INVALID_ARGUMENT, /**< Invalid argument */
111 VSMCLIENT_OTHER_ERROR, /**< Other error */
112 VSMCLIENT_SUCCESS /**< Success */
118 typedef unsigned int VsmSubscriptionId;
138 * Zone information structure
150 typedef VsmZoneStructure* VsmZone;
153 * Netowrk device type
162 * Network device information structure
167 } VsmNetdevStructure;
170 * Network device information
172 typedef VsmNetdevStructure* VsmNetdev;
183 #ifndef __VASUM_WRAPPER_SOURCE__
186 * Create a new vasum-server's client.
188 * @return Created client pointer or NULL on failure.
190 VsmClient vsm_client_create();
193 * Release client resources.
195 * @param[in] client vasum-server's client
197 void vsm_client_free(VsmClient client);
200 * Get status code of last vasum-server communication.
202 * @param[in] client vasum-server's client
203 * @return status of this function call
205 VsmStatus vsm_get_status(VsmClient client);
208 * Get status message of the last vasum-server communication.
210 * @param[in] client vasum-server's client
211 * @return last status message from vasum-server communication
213 const char* vsm_get_status_message(VsmClient client);
216 * Connect client to the vasum-server.
218 * @param[in] client vasum-server's client
219 * @return status of this function call
221 VsmStatus vsm_connect(VsmClient client);
224 * Connect client to the vasum-server via custom address.
226 * @param[in] client vasum-server's client
227 * @param[in] address dbus address
228 * @return status of this function call
230 VsmStatus vsm_connect_custom(VsmClient client, const char* address);
233 * Release VsmArrayString.
235 * @param[in] astring VsmArrayString
237 void vsm_array_string_free(VsmArrayString astring);
242 * @param string VsmString
244 void vsm_string_free(VsmString string);
249 * @param zone VsmZone
251 void vsm_zone_free(VsmZone zone);
256 * @param netdev VsmNetdev
258 void vsm_netdev_free(VsmNetdev netdev);
263 * Functions using org.tizen.vasum.host.manager D-Bus interface.
269 * Zone's D-Bus state change callback function signature.
271 * @param[in] zoneId affected zone id
272 * @param[in] address new D-Bus address
273 * @param data custom user's data pointer passed to vsm_add_state_callback() function
275 typedef void (*VsmZoneDbusStateCallback)(const char* zoneId,
280 * Get dbus address of each zone.
282 * @param[in] client vasum-server's client
283 * @param[out] keys array of zones name
284 * @param[out] values array of zones dbus address
285 * @return status of this function call
286 * @post keys[i] corresponds to values[i]
287 * @remark Use vsm_array_string_free() to free memory occupied by @p keys and @p values.
289 VsmStatus vsm_get_zone_dbuses(VsmClient client, VsmArrayString* keys, VsmArrayString* values);
294 * @param[in] client vasum-server's client
295 * @param[out] array array of zones name
296 * @return status of this function call
297 * @remark Use vsm_array_string_free() to free memory occupied by @p array.
299 VsmStatus vsm_get_zone_ids(VsmClient client, VsmArrayString* array);
302 * Get active (foreground) zone name.
304 * @param[in] client vasum-server's client
305 * @param[out] id active zone name
306 * @return status of this function call
307 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
309 VsmStatus vsm_get_active_zone_id(VsmClient client, VsmString* id);
312 * Get zone rootfs path.
314 * @param[in] client vasum-server's client
315 * @param[in] id zone name
316 * @param[out] rootpath zone rootfs path
317 * @return status of this function call
318 * @remark Use @p vsm_string_free() to free memory occupied by @p rootpath.
320 VsmStatus vsm_get_zone_rootpath(VsmClient client, const char* id, VsmString* rootpath);
323 * Get zone name of process with given pid.
325 * @param[in] client vasum-server's client
326 * @param[in] pid process id
327 * @param[out] id active zone name
328 * @return status of this function call
329 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
331 VsmStatus vsm_lookup_zone_by_pid(VsmClient client, int pid, VsmString* id);
334 * Get zone informations of zone with given id.
336 * @param[in] client vasum-server's client
337 * @param[in] id zone name
338 * @param[out] zone zone informations
339 * @return status of this function call
340 * @remark Use @p vsm_zone_free() to free memory occupied by @p zone
342 VsmStatus vsm_lookup_zone_by_id(VsmClient client, const char* id, VsmZone* zone);
345 * Get zone name with given terminal.
347 * @param[in] client vasum-server's client
348 * @param[in] terminal terminal id
349 * @param[out] id zone name with given terminal
350 * @return status of this function call
351 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
353 VsmStatus vsm_lookup_zone_by_terminal_id(VsmClient client, int terminal, VsmString* id);
356 * Set active (foreground) zone.
358 * @param[in] client vasum-server's client
359 * @param[in] id zone name
360 * @return status of this function call
362 VsmStatus vsm_set_active_zone(VsmClient client, const char* id);
365 * Create and add zone
367 * @param[in] client vasum-server's client
368 * @param[in] id zone id
369 * @param[in] tname template name, NULL is equivalent to "default"
370 * @return status of this function call
372 VsmStatus vsm_create_zone(VsmClient client, const char* id, const char* tname);
377 * @param[in] client vasum-server's client
378 * @param[in] id zone id
379 * @param[in] force if 0 data will be kept, otherwise data will be lost
380 * @return status of this function call
382 VsmStatus vsm_destroy_zone(VsmClient client, const char* id, int force);
387 * @param[in] client vasum-server's client
388 * @param[in] id zone name
389 * @return status of this function call
391 VsmStatus vsm_shutdown_zone(VsmClient client, const char* id);
396 * @param[in] client vasum-server's client
397 * @param[in] id zone name
398 * @return status of this function call
400 VsmStatus vsm_start_zone(VsmClient client, const char* id);
405 * @param[in] client vasum-server's client
406 * @param[in] id zone name
407 * @return status of this function call
409 VsmStatus vsm_lock_zone(VsmClient client, const char* id);
414 * @param[in] client vasum-server's client
415 * @param[in] id zone name
416 * @return status of this function call
418 VsmStatus vsm_unlock_zone(VsmClient client, const char* id);
421 * Register dbus state change callback function.
423 * @note The callback function will be invoked on a different thread.
425 * @param[in] client vasum-server's client
426 * @param[in] zoneDbusStateCallback callback function
427 * @param[in] data some extra data that will be passed to callback function
428 * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal,
429 * pointer can be NULL.
430 * @return status of this function call
432 VsmStatus vsm_add_state_callback(VsmClient client,
433 VsmZoneDbusStateCallback zoneDbusStateCallback,
435 VsmSubscriptionId* subscriptionId);
438 * Unregister dbus state change callback function.
440 * @param[in] client vasum-server's client
441 * @param[in] subscriptionId subscription identifier returned by vsm_add_state_callback
442 * @return status of this function call
444 VsmStatus vsm_del_state_callback(VsmClient client, VsmSubscriptionId subscriptionId);
447 * Grant access to device
449 * @param[in] client vasum-server's client
450 * @param[in] zone zone name
451 * @param[in] device device path
452 * @param[in] flags access flags
453 * @return status of this function call
455 VsmStatus vsm_grant_device(VsmClient client,
461 * Revoke access to device
463 * @param[in] client vasum-server's client
464 * @param[in] zone zone name
465 * @param[in] device device path
466 * @return status of this function call
468 VsmStatus vsm_revoke_device(VsmClient client, const char* zone, const char* device);
471 * Get array of netdev from given zone
473 * @param[in] client vasum-server's client
474 * @param[in] zone zone name
475 * @param[out] netdevIds array of netdev id
476 * @return status of this function call
477 * @remark Use vsm_array_string_free() to free memory occupied by @p netdevIds.
479 VsmStatus vsm_zone_get_netdevs(VsmClient client, const char* zone, VsmArrayString* netdevIds);
482 * Get ipv4 address for given netdevId
484 * @param[in] client vasum-server's client
485 * @param[in] zone zone name
486 * @param[in] netdevId netdev id
487 * @param[out] addr ipv4 address
488 * @return status of this function call
490 VsmStatus vsm_netdev_get_ipv4_addr(VsmClient client,
492 const char* netdevId,
493 struct in_addr *addr);
496 * Get ipv6 address for given netdevId
498 * @param[in] client vasum-server's client
499 * @param[in] zone zone name
500 * @param[in] netdevId netdev id
501 * @param[out] addr ipv6 address
502 * @return status of this function call
504 VsmStatus vsm_netdev_get_ipv6_addr(VsmClient client,
506 const char* netdevId,
507 struct in6_addr *addr);
510 * Set ipv4 address for given netdevId
512 * @param[in] client vasum-server's client
513 * @param[in] zone zone name
514 * @param[in] netdevId netdev id
515 * @param[in] addr ipv4 address
516 * @param[in] prefix bit-length of the network prefix
517 * @return status of this function call
519 VsmStatus vsm_netdev_set_ipv4_addr(VsmClient client,
521 const char* netdevId,
522 struct in_addr *addr,
526 * Set ipv6 address for given netdevId
528 * @param[in] client vasum-server's client
529 * @param[in] zone zone name
530 * @param[in] netdevId netdev id
531 * @param[in] addr ipv6 address
532 * @param[in] prefix bit-length of the network prefix
533 * @return status of this function call
535 VsmStatus vsm_netdev_set_ipv6_addr(VsmClient client,
537 const char* netdevId,
538 struct in6_addr *addr,
542 * Remove ipv4 address from netdev
544 * @param[in] client vasum-server's client
545 * @param[in] zone zone name
546 * @param[in] netdevId network device id
547 * @param[in] addr ipv4 address
548 * @param[in] prefix bit-length of the network prefix
549 * @return status of this function call
551 VsmStatus vsm_netdev_del_ipv4_addr(VsmClient client,
553 const char* netdevId,
554 struct in_addr* addr,
558 * Remove ipv6 address from netdev
560 * @param[in] client vasum-server's client
561 * @param[in] zone zone name
562 * @param[in] netdevId network device id
563 * @param[in] addr ipv6 address
564 * @param[in] prefix bit-length of the network prefix
565 * @return status of this function call
567 VsmStatus vsm_netdev_del_ipv6_addr(VsmClient client,
569 const char* netdevId,
570 struct in6_addr* addr,
574 * Turn up a network device in the zone
576 * @param[in] client vasum-server's client
577 * @param[in] zone zone name
578 * @param[in] netdevId netdev id
579 * @return status of this function call
581 VsmStatus vsm_netdev_up(VsmClient client,
583 const char* netdevId);
586 * Turn down a network device in the zone
588 * @param[in] client vasum-server's client
589 * @param[in] zone zone name
590 * @param[in] netdevId netdev id
591 * @return status of this function call
593 VsmStatus vsm_netdev_down(VsmClient client,
595 const char* netdevId);
599 * Create veth netdev in zone
601 * @param[in] client vasum-server's client
602 * @param[in] zone zone name
603 * @param[in] zoneDev in host network device id
604 * @param[in] hostDev in zone network device id
605 * @return status of this function call
607 VsmStatus vsm_create_netdev_veth(VsmClient client,
610 const char* hostDev);
612 * Create macvlab in zone
614 * @param[in] client vasum-server's client
615 * @param[in] zone zone name
616 * @param[in] zoneDev in host network device id
617 * @param[in] hostDev in zone network device id
618 * @return status of this function call
620 VsmStatus vsm_create_netdev_macvlan(VsmClient client,
624 enum macvlan_mode mode);
626 * Create/move phys netdev in/to zone
628 * @param[in] client vasum-server's client
629 * @param[in] zone zone name
630 * @param[in] devId network device id
631 * @return status of this function call
633 VsmStatus vsm_create_netdev_phys(VsmClient client, const char* zone, const char* devId);
636 * Get netdev informations
638 * @param[in] client vasum-server's client
639 * @param[in] zone zone name
640 * @param[in] netdevId network device id
641 * @param[out] netdev netdev informations
642 * @return status of this function call
643 * @remark Use vsm_netdev_free() to free memory occupied by @p netdev.
645 VsmStatus vsm_lookup_netdev_by_name(VsmClient client,
647 const char* netdevId,
651 * Remove netdev from zone
653 * @param[in] client vasum-server's client
654 * @param[in] zone zone name
655 * @param[in] devId network device id
656 * @return status of this function call
658 VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* devId);
661 * Create file, directory or pipe in zone
663 * Declare file, directory or pipe that will be created while zone startup
665 * @param[in] client vasum-server's client
666 * @param[in] type file type
667 * @param[in] zone zone id
668 * @param[in] path path to file
669 * @param[in] flags if O_CREAT bit is set then file will be created in zone,
670 * otherwise file will by copied from host;
671 * it is meaningful only when O_CREAT is set
672 * @param[in] mode mode of file
673 * @return status of this function call
675 VsmStatus vsm_declare_file(VsmClient client,
683 * Create mount point in zone
685 * Declare mount that will be created while zone startup
686 * Parameters are passed to mount system function
688 * @param[in] client vasum-server's client
689 * @param[in] source device path (path in host)
690 * @param[in] zone zone id
691 * @param[in] target mount point (path in zone)
692 * @param[in] type filesystem type
693 * @param[in] flags mount flags as in mount function
694 * @param[in] data additional data as in mount function
695 * @return status of this function call
697 VsmStatus vsm_declare_mount(VsmClient client,
706 * Create link in zone
708 * Declare link that will be created while zone startup
709 * Parameters are passed to link system function
711 * @param[in] client vasum-server's client
712 * @param[in] source path to link source (in host)
713 * @param[in] zone zone id
714 * @param[in] target path to link name (in zone)
715 * @return status of this function call
717 VsmStatus vsm_declare_link(VsmClient client,
723 * Get all declarations
725 * Gets all declarations of resourcies
726 * (@see ::vsm_declare_link, @see ::vsm_declare_mount, @see ::vsm_declare_linki)
728 * @param[in] client vasum-server's client
729 * @param[in] zone zone id
730 * @param[out] declarations array of declarations id
731 * @return status of this function call
733 VsmStatus vsm_list_declarations(VsmClient client,
735 VsmArrayString* declarations);
740 * Removes given declaration by its id (@see ::vsm_list_declarations)
742 * @param[in] client vasum-server's client
743 * @param[in] zone zone id
744 * @param[in] declaration declaration id
745 * @return status of this function call
747 VsmStatus vsm_remove_declaration(VsmClient client,
749 VsmString declaration);
758 * Functions using org.tizen.vasum.zone.manager D-Bus interface.
764 * Notification callback function signature.
766 * @param[in] zone source zone
767 * @param[in] application sending application name
768 * @param[in] message notification message
769 * @param data custom user's data pointer passed to vsm_add_notification_callback()
771 typedef void (*VsmNotificationCallback)(const char* zone,
772 const char* application,
776 * Send message to active zone.
778 * @param[in] client vasum-server's client
779 * @param[in] application application name
780 * @param[in] message message
781 * @return status of this function call
783 VsmStatus vsm_notify_active_zone(VsmClient client, const char* application, const char* message);
786 * Move file between zones.
788 * @param[in] client vasum-server's client
789 * @param[in] destZone destination zone id
790 * @param[in] path path to moved file
791 * @return status of this function call
793 VsmStatus vsm_file_move_request(VsmClient client, const char* destZone, const char* path);
796 * Register notification callback function.
798 * @note The callback function will be invoked on a different thread.
800 * @param[in] client vasum-server's client
801 * @param[in] notificationCallback callback function
802 * @param[in] data some extra data that will be passed to callback function
803 * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal,
804 * pointer can be NULL.
805 * @return status of this function call
807 VsmStatus vsm_add_notification_callback(VsmClient client,
808 VsmNotificationCallback notificationCallback,
810 VsmSubscriptionId* subscriptionId);
813 * Unregister notification callback function.
815 * @param[in] client vasum-server's client
816 * @param[in] subscriptionId subscription identifier returned by vsm_add_notification_callback
817 * @return status of this function call
819 VsmStatus vsm_del_notification_callback(VsmClient client, VsmSubscriptionId subscriptionId);
821 #endif /* __VASUM_WRAPPER_SOURCE__ */
829 #endif /* VASUM_CLIENT_H */