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;
184 * Event dispacher types.
186 * @par Example usage:
192 #include <sys/epoll.h>
193 #include <vasum-client.h>
195 volatile static sig_atomic_t running;
196 static int LOOP_INTERVAL = 1000; // ms
198 void* main_loop(void* client)
201 VsmStatus status = vsm_get_poll_fd(client, &fd);
202 assert(VSMCLIENT_SUCCESS == status);
205 struct epoll_event event;
206 int num = epoll_wait(fd, &event, 1, LOOP_INTERVAL);
208 status = vsm_enter_eventloop(client, 0 , 0);
209 assert(VSMCLIENT_SUCCESS == status);
215 int main(int argc, char** argv)
222 client = vsm_client_create();
225 status = vsm_set_dispatcher_type(client, VSMDISPATCHER_EXTERNAL);
226 assert(VSMCLIENT_SUCCESS == status);
228 status = vsm_connect(client);
229 assert(VSMCLIENT_SUCCESS == status);
233 ret = pthread_create(&loop, NULL, main_loop, client);
236 // make vsm_* calls on client
239 status = vsm_disconnect(client);
240 assert(VSMCLIENT_SUCCESS == status);
244 ret = pthread_join(loop, NULL);
247 vsm_client_free(client); // destroy client handle
253 VSMDISPATCHER_EXTERNAL, /**< User must handle dispatching messages */
254 VSMDISPATCHER_INTERNAL /**< Library will take care of dispatching messages */
257 #ifndef __VASUM_WRAPPER_SOURCE__
260 * Get file descriptor associated with event dispatcher of zone client
262 * The function vsm_get_poll_fd() returns the file descriptor associated with the event dispatcher of vsm client.
263 * The file descriptor can be bound to another I/O multiplexing facilities like epoll, select, and poll.
265 * @param[in] client vsm client
266 * @param[out] fd epoll file descriptor
267 * @return status of this function call
269 VsmStatus vsm_get_poll_fd(VsmClient client, int* fd);
272 * Wait for an I/O event on a vsm client
274 * vsm_enter_eventloop() waits for event on the vsm client
276 * The call waits for a maximum time of timout milliseconds. Specifying a timeout of -1 makes vsm_enter_eventloop() wait indefinitely,
277 * while specifying a timeout equal to zero makes vsm_enter_eventloop() to return immediately even if no events are available.
279 * @param[in] client vasum-server's client
280 * @param[in] flags Reserved
281 * @param[in] timeout Timeout time (milisecond), -1 is infinite
282 * @return status of this function call
284 VsmStatus vsm_enter_eventloop(VsmClient client, int flags, int timeout);
287 * Set dispatching method
289 * @param[in] client vasum-server's client
290 * @param[in] dispacher dispatching method
291 * @return status of this function call
293 VsmStatus vsm_set_dispatcher_type(VsmClient client, VsmDispacherType dispacher);
296 * Get dispatching method
298 * @param[in] client vasum-server's client
299 * @param[out] dispacher dispatching method
300 * @return status of this function call
302 VsmStatus vsm_get_dispatcher_type(VsmClient client, VsmDispacherType* dispacher);
305 * Create a new vasum-server's client.
307 * @return Created client pointer or NULL on failure.
309 VsmClient vsm_client_create();
312 * Release client resources.
314 * @param[in] client vasum-server's client
316 void vsm_client_free(VsmClient client);
319 * Get status code of last vasum-server communication.
321 * @param[in] client vasum-server's client
322 * @return status of this function call
324 VsmStatus vsm_get_status(VsmClient client);
327 * Get status message of the last vasum-server communication.
329 * @param[in] client vasum-server's client
330 * @return last status message from vasum-server communication
332 const char* vsm_get_status_message(VsmClient client);
335 * Connect client to the vasum-server.
337 * @param[in] client vasum-server's client
338 * @return status of this function call
340 VsmStatus vsm_connect(VsmClient client);
343 * Connect client to the vasum-server via custom address.
345 * @param[in] client vasum-server's client
346 * @param[in] address dbus address
347 * @return status of this function call
349 VsmStatus vsm_connect_custom(VsmClient client, const char* address);
352 * Disconnect client from vasum-server.
354 * @param[in] client vasum-server's client
355 * @return status of this function call
357 VsmStatus vsm_disconnect(VsmClient client);
360 * Release VsmArrayString.
362 * @param[in] astring VsmArrayString
364 void vsm_array_string_free(VsmArrayString astring);
369 * @param string VsmString
371 void vsm_string_free(VsmString string);
376 * @param zone VsmZone
378 void vsm_zone_free(VsmZone zone);
383 * @param netdev VsmNetdev
385 void vsm_netdev_free(VsmNetdev netdev);
390 * Functions using org.tizen.vasum.host.manager D-Bus interface.
396 * Zone's D-Bus state change callback function signature.
398 * @param[in] zoneId affected zone id
399 * @param[in] address new D-Bus address
400 * @param data custom user's data pointer passed to vsm_add_state_callback() function
402 typedef void (*VsmZoneDbusStateCallback)(const char* zoneId,
407 * Get dbus address of each zone.
409 * @param[in] client vasum-server's client
410 * @param[out] keys array of zones name
411 * @param[out] values array of zones dbus address
412 * @return status of this function call
413 * @post keys[i] corresponds to values[i]
414 * @remark Use vsm_array_string_free() to free memory occupied by @p keys and @p values.
416 VsmStatus vsm_get_zone_dbuses(VsmClient client, VsmArrayString* keys, VsmArrayString* values);
421 * @param[in] client vasum-server's client
422 * @param[out] array array of zones name
423 * @return status of this function call
424 * @remark Use vsm_array_string_free() to free memory occupied by @p array.
426 VsmStatus vsm_get_zone_ids(VsmClient client, VsmArrayString* array);
429 * Get active (foreground) zone name.
431 * @param[in] client vasum-server's client
432 * @param[out] id active zone name
433 * @return status of this function call
434 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
436 VsmStatus vsm_get_active_zone_id(VsmClient client, VsmString* id);
439 * Get zone rootfs path.
441 * @param[in] client vasum-server's client
442 * @param[in] id zone name
443 * @param[out] rootpath zone rootfs path
444 * @return status of this function call
445 * @remark Use @p vsm_string_free() to free memory occupied by @p rootpath.
447 VsmStatus vsm_get_zone_rootpath(VsmClient client, const char* id, VsmString* rootpath);
450 * Get zone name of process with given pid.
452 * @param[in] client vasum-server's client
453 * @param[in] pid process id
454 * @param[out] id active zone name
455 * @return status of this function call
456 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
458 VsmStatus vsm_lookup_zone_by_pid(VsmClient client, int pid, VsmString* id);
461 * Get zone informations of zone with given id.
463 * @param[in] client vasum-server's client
464 * @param[in] id zone name
465 * @param[out] zone zone informations
466 * @return status of this function call
467 * @remark Use @p vsm_zone_free() to free memory occupied by @p zone
469 VsmStatus vsm_lookup_zone_by_id(VsmClient client, const char* id, VsmZone* zone);
472 * Get zone name with given terminal.
474 * @param[in] client vasum-server's client
475 * @param[in] terminal terminal id
476 * @param[out] id zone name with given terminal
477 * @return status of this function call
478 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
480 VsmStatus vsm_lookup_zone_by_terminal_id(VsmClient client, int terminal, VsmString* id);
483 * Set active (foreground) zone.
485 * @param[in] client vasum-server's client
486 * @param[in] id zone name
487 * @return status of this function call
489 VsmStatus vsm_set_active_zone(VsmClient client, const char* id);
492 * Create and add zone
494 * @param[in] client vasum-server's client
495 * @param[in] id zone id
496 * @param[in] tname template name, NULL is equivalent to "default"
497 * @return status of this function call
499 VsmStatus vsm_create_zone(VsmClient client, const char* id, const char* tname);
504 * @param[in] client vasum-server's client
505 * @param[in] id zone id
506 * @param[in] force if 0 data will be kept, otherwise data will be lost
507 * @return status of this function call
509 VsmStatus vsm_destroy_zone(VsmClient client, const char* id, int force);
514 * @param[in] client vasum-server's client
515 * @param[in] id zone name
516 * @return status of this function call
518 VsmStatus vsm_shutdown_zone(VsmClient client, const char* id);
523 * @param[in] client vasum-server's client
524 * @param[in] id zone name
525 * @return status of this function call
527 VsmStatus vsm_start_zone(VsmClient client, const char* id);
532 * @param[in] client vasum-server's client
533 * @param[in] id zone name
534 * @return status of this function call
536 VsmStatus vsm_lock_zone(VsmClient client, const char* id);
541 * @param[in] client vasum-server's client
542 * @param[in] id zone name
543 * @return status of this function call
545 VsmStatus vsm_unlock_zone(VsmClient client, const char* id);
548 * Register dbus state change callback function.
550 * @note The callback function will be invoked on a different thread.
552 * @param[in] client vasum-server's client
553 * @param[in] zoneDbusStateCallback callback function
554 * @param[in] data some extra data that will be passed to callback function
555 * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal,
556 * pointer can be NULL.
557 * @return status of this function call
559 VsmStatus vsm_add_state_callback(VsmClient client,
560 VsmZoneDbusStateCallback zoneDbusStateCallback,
562 VsmSubscriptionId* subscriptionId);
565 * Unregister dbus state change callback function.
567 * @param[in] client vasum-server's client
568 * @param[in] subscriptionId subscription identifier returned by vsm_add_state_callback
569 * @return status of this function call
571 VsmStatus vsm_del_state_callback(VsmClient client, VsmSubscriptionId subscriptionId);
574 * Grant access to device
576 * @param[in] client vasum-server's client
577 * @param[in] zone zone name
578 * @param[in] device device path
579 * @param[in] flags access flags
580 * @return status of this function call
582 VsmStatus vsm_grant_device(VsmClient client,
588 * Revoke access to device
590 * @param[in] client vasum-server's client
591 * @param[in] zone zone name
592 * @param[in] device device path
593 * @return status of this function call
595 VsmStatus vsm_revoke_device(VsmClient client, const char* zone, const char* device);
598 * Get array of netdev from given zone
600 * @param[in] client vasum-server's client
601 * @param[in] zone zone name
602 * @param[out] netdevIds array of netdev id
603 * @return status of this function call
604 * @remark Use vsm_array_string_free() to free memory occupied by @p netdevIds.
606 VsmStatus vsm_zone_get_netdevs(VsmClient client, const char* zone, VsmArrayString* netdevIds);
609 * Get ipv4 address for given netdevId
611 * @param[in] client vasum-server's client
612 * @param[in] zone zone name
613 * @param[in] netdevId netdev id
614 * @param[out] addr ipv4 address
615 * @return status of this function call
617 VsmStatus vsm_netdev_get_ipv4_addr(VsmClient client,
619 const char* netdevId,
620 struct in_addr *addr);
623 * Get ipv6 address for given netdevId
625 * @param[in] client vasum-server's client
626 * @param[in] zone zone name
627 * @param[in] netdevId netdev id
628 * @param[out] addr ipv6 address
629 * @return status of this function call
631 VsmStatus vsm_netdev_get_ipv6_addr(VsmClient client,
633 const char* netdevId,
634 struct in6_addr *addr);
637 * Set ipv4 address for given netdevId
639 * @param[in] client vasum-server's client
640 * @param[in] zone zone name
641 * @param[in] netdevId netdev id
642 * @param[in] addr ipv4 address
643 * @param[in] prefix bit-length of the network prefix
644 * @return status of this function call
646 VsmStatus vsm_netdev_set_ipv4_addr(VsmClient client,
648 const char* netdevId,
649 struct in_addr *addr,
653 * Set ipv6 address for given netdevId
655 * @param[in] client vasum-server's client
656 * @param[in] zone zone name
657 * @param[in] netdevId netdev id
658 * @param[in] addr ipv6 address
659 * @param[in] prefix bit-length of the network prefix
660 * @return status of this function call
662 VsmStatus vsm_netdev_set_ipv6_addr(VsmClient client,
664 const char* netdevId,
665 struct in6_addr *addr,
669 * Remove ipv4 address from netdev
671 * @param[in] client vasum-server's client
672 * @param[in] zone zone name
673 * @param[in] netdevId network device id
674 * @param[in] addr ipv4 address
675 * @param[in] prefix bit-length of the network prefix
676 * @return status of this function call
678 VsmStatus vsm_netdev_del_ipv4_addr(VsmClient client,
680 const char* netdevId,
681 struct in_addr* addr,
685 * Remove ipv6 address from netdev
687 * @param[in] client vasum-server's client
688 * @param[in] zone zone name
689 * @param[in] netdevId network device id
690 * @param[in] addr ipv6 address
691 * @param[in] prefix bit-length of the network prefix
692 * @return status of this function call
694 VsmStatus vsm_netdev_del_ipv6_addr(VsmClient client,
696 const char* netdevId,
697 struct in6_addr* addr,
701 * Turn up a network device in the zone
703 * @param[in] client vasum-server's client
704 * @param[in] zone zone name
705 * @param[in] netdevId netdev id
706 * @return status of this function call
708 VsmStatus vsm_netdev_up(VsmClient client,
710 const char* netdevId);
713 * Turn down a network device in the zone
715 * @param[in] client vasum-server's client
716 * @param[in] zone zone name
717 * @param[in] netdevId netdev id
718 * @return status of this function call
720 VsmStatus vsm_netdev_down(VsmClient client,
722 const char* netdevId);
726 * Create veth netdev in zone
728 * @param[in] client vasum-server's client
729 * @param[in] zone zone name
730 * @param[in] zoneDev in host network device id
731 * @param[in] hostDev in zone network device id
732 * @return status of this function call
734 VsmStatus vsm_create_netdev_veth(VsmClient client,
737 const char* hostDev);
739 * Create macvlab in zone
741 * @param[in] client vasum-server's client
742 * @param[in] zone zone name
743 * @param[in] zoneDev in host network device id
744 * @param[in] hostDev in zone network device id
745 * @return status of this function call
747 VsmStatus vsm_create_netdev_macvlan(VsmClient client,
751 enum macvlan_mode mode);
753 * Create/move phys netdev in/to zone
755 * @param[in] client vasum-server's client
756 * @param[in] zone zone name
757 * @param[in] devId network device id
758 * @return status of this function call
760 VsmStatus vsm_create_netdev_phys(VsmClient client, const char* zone, const char* devId);
763 * Get netdev informations
765 * @param[in] client vasum-server's client
766 * @param[in] zone zone name
767 * @param[in] netdevId network device id
768 * @param[out] netdev netdev informations
769 * @return status of this function call
770 * @remark Use vsm_netdev_free() to free memory occupied by @p netdev.
772 VsmStatus vsm_lookup_netdev_by_name(VsmClient client,
774 const char* netdevId,
778 * Remove netdev from zone
780 * @param[in] client vasum-server's client
781 * @param[in] zone zone name
782 * @param[in] devId network device id
783 * @return status of this function call
785 VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* devId);
788 * Create file, directory or pipe in zone
790 * Declare file, directory or pipe that will be created while zone startup
792 * @param[in] client vasum-server's client
793 * @param[in] type file type
794 * @param[in] zone zone id
795 * @param[in] path path to file
796 * @param[in] flags if O_CREAT bit is set then file will be created in zone,
797 * otherwise file will by copied from host;
798 * it is meaningful only when O_CREAT is set
799 * @param[in] mode mode of file
800 * @return status of this function call
802 VsmStatus vsm_declare_file(VsmClient client,
810 * Create mount point in zone
812 * Declare mount that will be created while zone startup
813 * Parameters are passed to mount system function
815 * @param[in] client vasum-server's client
816 * @param[in] source device path (path in host)
817 * @param[in] zone zone id
818 * @param[in] target mount point (path in zone)
819 * @param[in] type filesystem type
820 * @param[in] flags mount flags as in mount function
821 * @param[in] data additional data as in mount function
822 * @return status of this function call
824 VsmStatus vsm_declare_mount(VsmClient client,
833 * Create link in zone
835 * Declare link that will be created while zone startup
836 * Parameters are passed to link system function
838 * @param[in] client vasum-server's client
839 * @param[in] source path to link source (in host)
840 * @param[in] zone zone id
841 * @param[in] target path to link name (in zone)
842 * @return status of this function call
844 VsmStatus vsm_declare_link(VsmClient client,
850 * Get all declarations
852 * Gets all declarations of resourcies
853 * (@see ::vsm_declare_link, @see ::vsm_declare_mount, @see ::vsm_declare_linki)
855 * @param[in] client vasum-server's client
856 * @param[in] zone zone id
857 * @param[out] declarations array of declarations id
858 * @return status of this function call
860 VsmStatus vsm_list_declarations(VsmClient client,
862 VsmArrayString* declarations);
867 * Removes given declaration by its id (@see ::vsm_list_declarations)
869 * @param[in] client vasum-server's client
870 * @param[in] zone zone id
871 * @param[in] declaration declaration id
872 * @return status of this function call
874 VsmStatus vsm_remove_declaration(VsmClient client,
876 VsmString declaration);
885 * Functions using org.tizen.vasum.zone.manager D-Bus interface.
891 * Notification callback function signature.
893 * @param[in] zone source zone
894 * @param[in] application sending application name
895 * @param[in] message notification message
896 * @param data custom user's data pointer passed to vsm_add_notification_callback()
898 typedef void (*VsmNotificationCallback)(const char* zone,
899 const char* application,
903 * Send message to active zone.
905 * @param[in] client vasum-server's client
906 * @param[in] application application name
907 * @param[in] message message
908 * @return status of this function call
910 VsmStatus vsm_notify_active_zone(VsmClient client, const char* application, const char* message);
913 * Move file between zones.
915 * @param[in] client vasum-server's client
916 * @param[in] destZone destination zone id
917 * @param[in] path path to moved file
918 * @return status of this function call
920 VsmStatus vsm_file_move_request(VsmClient client, const char* destZone, const char* path);
923 * Register notification callback function.
925 * @note The callback function will be invoked on a different thread.
927 * @param[in] client vasum-server's client
928 * @param[in] notificationCallback callback function
929 * @param[in] data some extra data that will be passed to callback function
930 * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal,
931 * pointer can be NULL.
932 * @return status of this function call
934 VsmStatus vsm_add_notification_callback(VsmClient client,
935 VsmNotificationCallback notificationCallback,
937 VsmSubscriptionId* subscriptionId);
940 * Unregister notification callback function.
942 * @param[in] client vasum-server's client
943 * @param[in] subscriptionId subscription identifier returned by vsm_add_notification_callback
944 * @return status of this function call
946 VsmStatus vsm_del_notification_callback(VsmClient client, VsmSubscriptionId subscriptionId);
948 #endif /* __VASUM_WRAPPER_SOURCE__ */
956 #endif /* VASUM_CLIENT_H */