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>
84 #include <linux/if_link.h>
92 * vasum-server's client pointer.
94 typedef void* VsmClient;
97 * NULL-terminated string type.
99 * @sa vsm_array_string_free
101 typedef char* VsmString;
104 * NULL-terminated array of strings type.
106 * @sa vsm_string_free
108 typedef VsmString* VsmArrayString;
111 * Completion status of communication function.
114 VSMCLIENT_CUSTOM_ERROR, /**< User specified error */
115 VSMCLIENT_IO_ERROR, /**< Input/Output error */
116 VSMCLIENT_OPERATION_FAILED, /**< Operation failed */
117 VSMCLIENT_INVALID_ARGUMENT, /**< Invalid argument */
118 VSMCLIENT_OTHER_ERROR, /**< Other error */
119 VSMCLIENT_SUCCESS /**< Success */
125 typedef unsigned int VsmSubscriptionId;
145 * Zone information structure
157 typedef VsmZoneStructure* VsmZone;
160 * Netowrk device type
169 * Network device information structure
174 } VsmNetdevStructure;
177 * Network device information
179 typedef VsmNetdevStructure* VsmNetdev;
190 #ifndef __VASUM_WRAPPER_SOURCE__
194 * Do not call this function if an application creates a glib loop itself.
195 * Otherwise, call it before any other function from this library.
197 * @return status of this function call
199 VsmStatus vsm_start_glib_loop();
204 * Call only if vsm_start_glib_loop() was called.
206 * @return status of this function call
208 VsmStatus vsm_stop_glib_loop();
211 * Create a new vasum-server's client.
213 * @return Created client pointer or NULL on failure.
215 VsmClient vsm_client_create();
218 * Release client resources.
220 * @param[in] client vasum-server's client
222 void vsm_client_free(VsmClient client);
225 * Get status code of last vasum-server communication.
227 * @param[in] client vasum-server's client
228 * @return status of this function call
230 VsmStatus vsm_get_status(VsmClient client);
233 * Get status message of the last vasum-server communication.
235 * @param[in] client vasum-server's client
236 * @return last status message from vasum-server communication
238 const char* vsm_get_status_message(VsmClient client);
241 * Connect client to the vasum-server.
243 * @param[in] client vasum-server's client
244 * @return status of this function call
246 VsmStatus vsm_connect(VsmClient client);
249 * Connect client to the vasum-server via custom address.
251 * @param[in] client vasum-server's client
252 * @param[in] address dbus address
253 * @return status of this function call
255 VsmStatus vsm_connect_custom(VsmClient client, const char* address);
258 * Release VsmArrayString.
260 * @param[in] astring VsmArrayString
262 void vsm_array_string_free(VsmArrayString astring);
267 * @param string VsmString
269 void vsm_string_free(VsmString string);
274 * @param zone VsmZone
276 void vsm_zone_free(VsmZone zone);
281 * @param netdev VsmNetdev
283 void vsm_netdev_free(VsmNetdev netdev);
288 * Functions using org.tizen.vasum.host.manager D-Bus interface.
294 * Zone's D-Bus state change callback function signature.
296 * @param[in] zoneId affected zone id
297 * @param[in] address new D-Bus address
298 * @param data custom user's data pointer passed to vsm_add_state_callback() function
300 typedef void (*VsmZoneDbusStateCallback)(const char* zoneId,
305 * Get dbus address of each zone.
307 * @param[in] client vasum-server's client
308 * @param[out] keys array of zones name
309 * @param[out] values array of zones dbus address
310 * @return status of this function call
311 * @post keys[i] corresponds to values[i]
312 * @remark Use vsm_array_string_free() to free memory occupied by @p keys and @p values.
314 VsmStatus vsm_get_zone_dbuses(VsmClient client, VsmArrayString* keys, VsmArrayString* values);
319 * @param[in] client vasum-server's client
320 * @param[out] array array of zones name
321 * @return status of this function call
322 * @remark Use vsm_array_string_free() to free memory occupied by @p array.
324 VsmStatus vsm_get_zone_ids(VsmClient client, VsmArrayString* array);
327 * Get active (foreground) zone name.
329 * @param[in] client vasum-server's client
330 * @param[out] id active zone name
331 * @return status of this function call
332 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
334 VsmStatus vsm_get_active_zone_id(VsmClient client, VsmString* id);
337 * Get zone name of process with given pid.
339 * @param[in] client vasum-server's client
340 * @param[in] pid process id
341 * @param[out] id active zone name
342 * @return status of this function call
343 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
345 VsmStatus vsm_lookup_zone_by_pid(VsmClient client, int pid, VsmString* id);
348 * Get zone informations of zone with given id.
350 * @param[in] client vasum-server's client
351 * @param[in] id zone name
352 * @param[out] zone zone informations
353 * @return status of this function call
354 * @remark Use @p vsm_zone_free() to free memory occupied by @p zone
356 VsmStatus vsm_lookup_zone_by_id(VsmClient client, const char* id, VsmZone* zone);
359 * Get zone name with given terminal.
361 * @param[in] client vasum-server's client
362 * @param[in] terminal terminal id
363 * @param[out] id zone name with given terminal
364 * @return status of this function call
365 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
367 VsmStatus vsm_lookup_zone_by_terminal_id(VsmClient client, int terminal, VsmString* id);
370 * Set active (foreground) zone.
372 * @param[in] client vasum-server's client
373 * @param[in] id zone name
374 * @return status of this function call
376 VsmStatus vsm_set_active_zone(VsmClient client, const char* id);
379 * Create and add zone
381 * @param[in] client vasum-server's client
382 * @param[in] id zone id
383 * @param[in] tname template name, NULL is equivalent to "default"
384 * @return status of this function call
386 VsmStatus vsm_create_zone(VsmClient client, const char* id, const char* tname);
391 * @param[in] client vasum-server's client
392 * @param[in] id zone id
393 * @param[in] force if 0 data will be kept, otherwise data will be lost
394 * @return status of this function call
396 VsmStatus vsm_destroy_zone(VsmClient client, const char* id, int force);
401 * @param[in] client vasum-server's client
402 * @param[in] id zone name
403 * @return status of this function call
405 VsmStatus vsm_shutdown_zone(VsmClient client, const char* id);
410 * @param[in] client vasum-server's client
411 * @param[in] id zone name
412 * @return status of this function call
414 VsmStatus vsm_start_zone(VsmClient client, const char* id);
419 * @param[in] client vasum-server's client
420 * @param[in] id zone name
421 * @return status of this function call
423 VsmStatus vsm_lock_zone(VsmClient client, const char* id);
428 * @param[in] client vasum-server's client
429 * @param[in] id zone name
430 * @return status of this function call
432 VsmStatus vsm_unlock_zone(VsmClient client, const char* id);
435 * Register dbus state change callback function.
437 * @note The callback function will be invoked on a different thread.
439 * @param[in] client vasum-server's client
440 * @param[in] zoneDbusStateCallback callback function
441 * @param[in] data some extra data that will be passed to callback function
442 * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal,
443 * pointer can be NULL.
444 * @return status of this function call
446 VsmStatus vsm_add_state_callback(VsmClient client,
447 VsmZoneDbusStateCallback zoneDbusStateCallback,
449 VsmSubscriptionId* subscriptionId);
452 * Unregister dbus state change callback function.
454 * @param[in] client vasum-server's client
455 * @param[in] subscriptionId subscription identifier returned by vsm_add_state_callback
456 * @return status of this function call
458 VsmStatus vsm_del_state_callback(VsmClient client, VsmSubscriptionId subscriptionId);
461 * Grant access to device
463 * @param[in] client vasum-server's client
464 * @param[in] zone zone name
465 * @param[in] device device path
466 * @param[in] flags access flags
467 * @return status of this function call
469 VsmStatus vsm_grant_device(VsmClient client,
475 * Revoke access to device
477 * @param[in] client vasum-server's client
478 * @param[in] zone zone name
479 * @param[in] device device path
480 * @return status of this function call
482 VsmStatus vsm_revoke_device(VsmClient client, const char* zone, const char* device);
485 * Get array of netdev from given zone
487 * @param[in] client vasum-server's client
488 * @param[in] zone zone name
489 * @param[out] netdevIds array of netdev id
490 * @return status of this function call
491 * @remark Use vsm_array_string_free() to free memory occupied by @p netdevIds.
493 VsmStatus vsm_zone_get_netdevs(VsmClient client, const char* zone, VsmArrayString* netdevIds);
496 * Get ipv4 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 ipv4 address
502 * @return status of this function call
504 VsmStatus vsm_netdev_get_ipv4_addr(VsmClient client,
506 const char* netdevId,
507 struct in_addr *addr);
510 * Get ipv6 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[out] addr ipv6 address
516 * @return status of this function call
518 VsmStatus vsm_netdev_get_ipv6_addr(VsmClient client,
520 const char* netdevId,
521 struct in6_addr *addr);
524 * Set ipv4 address for given netdevId
526 * @param[in] client vasum-server's client
527 * @param[in] zone zone name
528 * @param[in] netdevId netdev id
529 * @param[in] addr ipv4 address
530 * @param[in] prefix bit-length of the network prefix
531 * @return status of this function call
533 VsmStatus vsm_netdev_set_ipv4_addr(VsmClient client,
535 const char* netdevId,
536 struct in_addr *addr,
540 * Set ipv6 address for given netdevId
542 * @param[in] client vasum-server's client
543 * @param[in] zone zone name
544 * @param[in] netdevId netdev id
545 * @param[in] addr ipv6 address
546 * @param[in] prefix bit-length of the network prefix
547 * @return status of this function call
549 VsmStatus vsm_netdev_set_ipv6_addr(VsmClient client,
551 const char* netdevId,
552 struct in6_addr *addr,
556 * Remove ipv4 address from netdev
558 * @param[in] client vasum-server's client
559 * @param[in] zone zone name
560 * @param[in] netdevId network device id
561 * @param[in] addr ipv4 address
562 * @param[in] prefix bit-length of the network prefix
563 * @return status of this function call
565 VsmStatus vsm_netdev_del_ipv4_addr(VsmClient client,
567 const char* netdevId,
568 struct in_addr* addr,
572 * Remove ipv6 address from netdev
574 * @param[in] client vasum-server's client
575 * @param[in] zone zone name
576 * @param[in] netdevId network device id
577 * @param[in] addr ipv6 address
578 * @param[in] prefix bit-length of the network prefix
579 * @return status of this function call
581 VsmStatus vsm_netdev_del_ipv6_addr(VsmClient client,
583 const char* netdevId,
584 struct in6_addr* addr,
588 * Turn up a network device in the zone
590 * @param[in] client vasum-server's client
591 * @param[in] zone zone name
592 * @param[in] netdevId netdev id
593 * @return status of this function call
595 VsmStatus vsm_netdev_up(VsmClient client,
597 const char* netdevId);
600 * Turn down a network device in the zone
602 * @param[in] client vasum-server's client
603 * @param[in] zone zone name
604 * @param[in] netdevId netdev id
605 * @return status of this function call
607 VsmStatus vsm_netdev_down(VsmClient client,
609 const char* netdevId);
613 * Create veth netdev in zone
615 * @param[in] client vasum-server's client
616 * @param[in] zone zone name
617 * @param[in] zoneDev in host network device id
618 * @param[in] hostDev in zone network device id
619 * @return status of this function call
621 VsmStatus vsm_create_netdev_veth(VsmClient client,
624 const char* hostDev);
626 * Create macvlab in zone
628 * @param[in] client vasum-server's client
629 * @param[in] zone zone name
630 * @param[in] zoneDev in host network device id
631 * @param[in] hostDev in zone network device id
632 * @return status of this function call
634 VsmStatus vsm_create_netdev_macvlan(VsmClient client,
638 enum macvlan_mode mode);
640 * Create/move phys netdev in/to zone
642 * @param[in] client vasum-server's client
643 * @param[in] zone zone name
644 * @param[in] devId network device id
645 * @return status of this function call
647 VsmStatus vsm_create_netdev_phys(VsmClient client, const char* zone, const char* devId);
650 * Get netdev informations
652 * @param[in] client vasum-server's client
653 * @param[in] zone zone name
654 * @param[in] netdevId network device id
655 * @param[out] netdev netdev informations
656 * @return status of this function call
657 * @remark Use vsm_netdev_free() to free memory occupied by @p netdev.
659 VsmStatus vsm_lookup_netdev_by_name(VsmClient client,
661 const char* netdevId,
665 * Remove netdev from zone
667 * @param[in] client vasum-server's client
668 * @param[in] zone zone name
669 * @param[in] devId network device id
670 * @return status of this function call
672 VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* devId);
675 * Create file, directory or pipe in zone
677 * Declare file, directory or pipe that will be created while zone startup
679 * @param[in] client vasum-server's client
680 * @param[in] type file type
681 * @param[in] zone zone id
682 * @param[in] path path to file
683 * @param[in] flags if O_CREAT bit is set then file will be created in zone,
684 * otherwise file will by copied from host;
685 * it is meaningful only when O_CREAT is set
686 * @param[in] mode mode of file
687 * @return status of this function call
689 VsmStatus vsm_declare_file(VsmClient client,
697 * Create mount point in zone
699 * Declare mount that will be created while zone startup
700 * Parameters are passed to mount system function
702 * @param[in] client vasum-server's client
703 * @param[in] source device path (path in host)
704 * @param[in] zone zone id
705 * @param[in] target mount point (path in zone)
706 * @param[in] type filesystem type
707 * @param[in] flags mount flags as in mount function
708 * @param[in] data additional data as in mount function
709 * @return status of this function call
711 VsmStatus vsm_declare_mount(VsmClient client,
720 * Create link in zone
722 * Declare link that will be created while zone startup
723 * Parameters are passed to link system function
725 * @param[in] client vasum-server's client
726 * @param[in] source path to link source (in host)
727 * @param[in] zone zone id
728 * @param[in] target path to link name (in zone)
729 * @return status of this function call
731 VsmStatus vsm_declare_link(VsmClient client,
737 * Get all declarations
739 * Gets all declarations of resourcies
740 * (@see ::vsm_declare_link, @see ::vsm_declare_mount, @see ::vsm_declare_linki)
742 * @param[in] client vasum-server's client
743 * @param[in] zone zone id
744 * @param[out] declarations array of declarations id
745 * @return status of this function call
747 VsmStatus vsm_list_declarations(VsmClient client,
749 VsmArrayString* declarations);
754 * Removes given declaration by its id (@see ::vsm_list_declarations)
756 * @param[in] client vasum-server's client
757 * @param[in] zone zone id
758 * @param[in] declaration declaration id
759 * @return status of this function call
761 VsmStatus vsm_remove_declaration(VsmClient client,
763 VsmString declaration);
772 * Functions using org.tizen.vasum.zone.manager D-Bus interface.
778 * Notification callback function signature.
780 * @param[in] zone source zone
781 * @param[in] application sending application name
782 * @param[in] message notification message
783 * @param data custom user's data pointer passed to vsm_add_notification_callback()
785 typedef void (*VsmNotificationCallback)(const char* zone,
786 const char* application,
790 * Send message to active zone.
792 * @param[in] client vasum-server's client
793 * @param[in] application application name
794 * @param[in] message message
795 * @return status of this function call
797 VsmStatus vsm_notify_active_zone(VsmClient client, const char* application, const char* message);
800 * Move file between zones.
802 * @param[in] client vasum-server's client
803 * @param[in] destZone destination zone id
804 * @param[in] path path to moved file
805 * @return status of this function call
807 VsmStatus vsm_file_move_request(VsmClient client, const char* destZone, const char* path);
810 * Register notification callback function.
812 * @note The callback function will be invoked on a different thread.
814 * @param[in] client vasum-server's client
815 * @param[in] notificationCallback callback function
816 * @param[in] data some extra data that will be passed to callback function
817 * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal,
818 * pointer can be NULL.
819 * @return status of this function call
821 VsmStatus vsm_add_notification_callback(VsmClient client,
822 VsmNotificationCallback notificationCallback,
824 VsmSubscriptionId* subscriptionId);
827 * Unregister notification callback function.
829 * @param[in] client vasum-server's client
830 * @param[in] subscriptionId subscription identifier returned by vsm_add_notification_callback
831 * @return status of this function call
833 VsmStatus vsm_del_notification_callback(VsmClient client, VsmSubscriptionId subscriptionId);
835 #endif /* __VASUM_WRAPPER_SOURCE__ */
843 #endif /* VASUM_CLIENT_H */