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;
193 * Do not call this function if an application creates a glib loop itself.
194 * Otherwise, call it before any other function from this library.
196 * @return status of this function call
198 VsmStatus vsm_start_glib_loop();
203 * Call only if vsm_start_glib_loop() was called.
205 * @return status of this function call
207 VsmStatus vsm_stop_glib_loop();
210 * Create a new vasum-server's client.
212 * @return Created client pointer or NULL on failure.
214 VsmClient vsm_client_create();
217 * Release client resources.
219 * @param[in] client vasum-server's client
221 void vsm_client_free(VsmClient client);
224 * Get status code of last vasum-server communication.
226 * @param[in] client vasum-server's client
227 * @return status of this function call
229 VsmStatus vsm_get_status(VsmClient client);
232 * Get status message of the last vasum-server communication.
234 * @param[in] client vasum-server's client
235 * @return last status message from vasum-server communication
237 const char* vsm_get_status_message(VsmClient client);
240 * Connect client to the vasum-server.
242 * @param[in] client vasum-server's client
243 * @return status of this function call
245 VsmStatus vsm_connect(VsmClient client);
248 * Connect client to the vasum-server via custom address.
250 * @param[in] client vasum-server's client
251 * @param[in] address dbus address
252 * @return status of this function call
254 VsmStatus vsm_connect_custom(VsmClient client, const char* address);
257 * Release VsmArrayString.
259 * @param[in] astring VsmArrayString
261 void vsm_array_string_free(VsmArrayString astring);
266 * @param string VsmString
268 void vsm_string_free(VsmString string);
273 * @param zone VsmZone
275 void vsm_zone_free(VsmZone zone);
280 * @param netdev VsmNetdev
282 void vsm_netdev_free(VsmNetdev netdev);
287 * Functions using org.tizen.vasum.host.manager D-Bus interface.
293 * Zone's D-Bus state change callback function signature.
295 * @param[in] zoneId affected zone id
296 * @param[in] dbusAddress new D-Bus address
297 * @param data custom user's data pointer passed to vsm_add_state_callback() function
299 typedef void (*VsmZoneDbusStateCallback)(const char* zoneId,
300 const char* dbusAddress,
304 * Get dbus address of each zone.
306 * @param[in] client vasum-server's client
307 * @param[out] keys array of zones name
308 * @param[out] values array of zones dbus address
309 * @return status of this function call
310 * @post keys[i] corresponds to values[i]
311 * @remark Use vsm_array_string_free() to free memory occupied by @p keys and @p values.
313 VsmStatus vsm_get_zone_dbuses(VsmClient client, VsmArrayString* keys, VsmArrayString* values);
318 * @param[in] client vasum-server's client
319 * @param[out] array array of zones name
320 * @return status of this function call
321 * @remark Use vsm_array_string_free() to free memory occupied by @p array.
323 VsmStatus vsm_get_zone_ids(VsmClient client, VsmArrayString* array);
326 * Get active (foreground) zone name.
328 * @param[in] client vasum-server's client
329 * @param[out] id active zone name
330 * @return status of this function call
331 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
333 VsmStatus vsm_get_active_zone_id(VsmClient client, VsmString* id);
336 * Get zone name of process with given pid.
338 * @param[in] client vasum-server's client
339 * @param[in] pid process id
340 * @param[out] id active zone name
341 * @return status of this function call
342 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
344 VsmStatus vsm_lookup_zone_by_pid(VsmClient client, int pid, VsmString* id);
347 * Get zone informations of zone with given id.
349 * @param[in] client vasum-server's client
350 * @param[in] id zone name
351 * @param[out] zone zone informations
352 * @return status of this function call
353 * @remark Use @p vsm_zone_free() to free memory occupied by @p zone
355 VsmStatus vsm_lookup_zone_by_id(VsmClient client, const char* id, VsmZone* zone);
358 * Get zone name with given terminal.
360 * @param[in] client vasum-server's client
361 * @param[in] terminal terminal id
362 * @param[out] id zone name with given terminal
363 * @return status of this function call
364 * @remark Use @p vsm_string_free() to free memory occupied by @p id.
366 VsmStatus vsm_lookup_zone_by_terminal_id(VsmClient client, int terminal, VsmString* id);
369 * Set active (foreground) zone.
371 * @param[in] client vasum-server's client
372 * @param[in] id zone name
373 * @return status of this function call
375 VsmStatus vsm_set_active_zone(VsmClient client, const char* id);
378 * Create and add zone
380 * @param[in] client vasum-server's client
381 * @param[in] id zone id
382 * @param[in] tname template name, NULL is equivalent to "default"
383 * @return status of this function call
385 VsmStatus vsm_create_zone(VsmClient client, const char* id, const char* tname);
390 * @param[in] client vasum-server's client
391 * @param[in] id zone id
392 * @param[in] force if 0 data will be kept, otherwise data will be lost
393 * @return status of this function call
395 VsmStatus vsm_destroy_zone(VsmClient client, const char* id, int force);
400 * @param[in] client vasum-server's client
401 * @param[in] id zone name
402 * @return status of this function call
404 VsmStatus vsm_shutdown_zone(VsmClient client, const char* id);
409 * @param[in] client vasum-server's client
410 * @param[in] id zone name
411 * @return status of this function call
413 VsmStatus vsm_start_zone(VsmClient client, const char* id);
418 * @param[in] client vasum-server's client
419 * @param[in] id zone name
420 * @return status of this function call
422 VsmStatus vsm_lock_zone(VsmClient client, const char* id);
427 * @param[in] client vasum-server's client
428 * @param[in] id zone name
429 * @return status of this function call
431 VsmStatus vsm_unlock_zone(VsmClient client, const char* id);
434 * Register dbus state change callback function.
436 * @note The callback function will be invoked on a different thread.
438 * @param[in] client vasum-server's client
439 * @param[in] zoneDbusStateCallback callback function
440 * @param[in] data some extra data that will be passed to callback function
441 * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal,
442 * pointer can be NULL.
443 * @return status of this function call
445 VsmStatus vsm_add_state_callback(VsmClient client,
446 VsmZoneDbusStateCallback zoneDbusStateCallback,
448 VsmSubscriptionId* subscriptionId);
451 * Unregister dbus state change callback function.
453 * @param[in] client vasum-server's client
454 * @param[in] subscriptionId subscription identifier returned by vsm_add_state_callback
455 * @return status of this function call
457 VsmStatus vsm_del_state_callback(VsmClient client, VsmSubscriptionId subscriptionId);
460 * Grant access to device
462 * @param[in] client vasum-server's client
463 * @param[in] zone zone name
464 * @param[in] device device path
465 * @param[in] flags access flags
466 * @return status of this function call
468 VsmStatus vsm_grant_device(VsmClient client,
474 * Revoke access to device
476 * @param[in] client vasum-server's client
477 * @param[in] zone zone name
478 * @param[in] device device path
479 * @return status of this function call
481 VsmStatus vsm_revoke_device(VsmClient client, const char* zone, const char* device);
484 * Get array of netdev from given zone
486 * @param[in] client vasum-server's client
487 * @param[in] zone zone name
488 * @param[out] netdevIds array of netdev id
489 * @return status of this function call
490 * @remark Use vsm_array_string_free() to free memory occupied by @p netdevIds.
492 VsmStatus vsm_zone_get_netdevs(VsmClient client, const char* zone, VsmArrayString* netdevIds);
495 * Get ipv4 address for given netdevId
497 * @param[in] client vasum-server's client
498 * @param[in] zone zone name
499 * @param[in] netdevId netdev id
500 * @param[out] addr ipv4 address
501 * @return status of this function call
503 VsmStatus vsm_netdev_get_ipv4_addr(VsmClient client,
505 const char* netdevId,
506 struct in_addr *addr);
509 * Get ipv6 address for given netdevId
511 * @param[in] client vasum-server's client
512 * @param[in] zone zone name
513 * @param[in] netdevId netdev id
514 * @param[out] addr ipv6 address
515 * @return status of this function call
517 VsmStatus vsm_netdev_get_ipv6_addr(VsmClient client,
519 const char* netdevId,
520 struct in6_addr *addr);
523 * Set ipv4 address for given netdevId
525 * @param[in] client vasum-server's client
526 * @param[in] zone zone name
527 * @param[in] netdevId netdev id
528 * @param[in] addr ipv4 address
529 * @param[in] prefix bit-length of the network prefix
530 * @return status of this function call
532 VsmStatus vsm_netdev_set_ipv4_addr(VsmClient client,
534 const char* netdevId,
535 struct in_addr *addr,
539 * Set ipv6 address for given netdevId
541 * @param[in] client vasum-server's client
542 * @param[in] zone zone name
543 * @param[in] netdevId netdev id
544 * @param[in] addr ipv6 address
545 * @param[in] prefix bit-length of the network prefix
546 * @return status of this function call
548 VsmStatus vsm_netdev_set_ipv6_addr(VsmClient client,
550 const char* netdevId,
551 struct in6_addr *addr,
555 * Remove ipv4 address from netdev
557 * @param[in] client vasum-server's client
558 * @param[in] zone zone name
559 * @param[in] netdevId network device id
560 * @param[in] addr ipv4 address
561 * @param[in] prefix bit-length of the network prefix
562 * @return status of this function call
564 VsmStatus vsm_netdev_del_ipv4_addr(VsmClient client,
566 const char* netdevId,
567 struct in_addr* addr,
571 * Remove ipv6 address from netdev
573 * @param[in] client vasum-server's client
574 * @param[in] zone zone name
575 * @param[in] netdevId network device id
576 * @param[in] addr ipv6 address
577 * @param[in] prefix bit-length of the network prefix
578 * @return status of this function call
580 VsmStatus vsm_netdev_del_ipv6_addr(VsmClient client,
582 const char* netdevId,
583 struct in6_addr* addr,
587 * Turn up a network device in the zone
589 * @param[in] client vasum-server's client
590 * @param[in] zone zone name
591 * @param[in] netdevId netdev id
592 * @return status of this function call
594 VsmStatus vsm_netdev_up(VsmClient client,
596 const char* netdevId);
599 * Turn down a network device in the zone
601 * @param[in] client vasum-server's client
602 * @param[in] zone zone name
603 * @param[in] netdevId netdev id
604 * @return status of this function call
606 VsmStatus vsm_netdev_down(VsmClient client,
608 const char* netdevId);
612 * Create veth netdev 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_veth(VsmClient client,
623 const char* hostDev);
625 * Create macvlab in zone
627 * @param[in] client vasum-server's client
628 * @param[in] zone zone name
629 * @param[in] zoneDev in host network device id
630 * @param[in] hostDev in zone network device id
631 * @return status of this function call
633 VsmStatus vsm_create_netdev_macvlan(VsmClient client,
637 enum macvlan_mode mode);
639 * Create/move phys netdev in/to zone
641 * @param[in] client vasum-server's client
642 * @param[in] zone zone name
643 * @param[in] devId network device id
644 * @return status of this function call
646 VsmStatus vsm_create_netdev_phys(VsmClient client, const char* zone, const char* devId);
649 * Get netdev informations
651 * @param[in] client vasum-server's client
652 * @param[in] zone zone name
653 * @param[in] netdevId network device id
654 * @param[out] netdev netdev informations
655 * @return status of this function call
656 * @remark Use vsm_netdev_free() to free memory occupied by @p netdev.
658 VsmStatus vsm_lookup_netdev_by_name(VsmClient client,
660 const char* netdevId,
664 * Remove netdev from zone
666 * @param[in] client vasum-server's client
667 * @param[in] zone zone name
668 * @param[in] devId network device id
669 * @return status of this function call
671 VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* devId);
674 * Create file, directory or pipe in zone
676 * Declare file, directory or pipe that will be created while zone startup
678 * @param[in] client vasum-server's client
679 * @param[in] type file type
680 * @param[in] zone zone id
681 * @param[in] path path to file
682 * @param[in] flags if O_CREAT bit is set then file will be created in zone,
683 * otherwise file will by copied from host;
684 * it is meaningful only when O_CREAT is set
685 * @param[in] mode mode of file
686 * @return status of this function call
688 VsmStatus vsm_declare_file(VsmClient client,
696 * Create mount point in zone
698 * Declare mount that will be created while zone startup
699 * Parameters are passed to mount system function
701 * @param[in] client vasum-server's client
702 * @param[in] source device path (path in host)
703 * @param[in] zone zone id
704 * @param[in] target mount point (path in zone)
705 * @param[in] type filesystem type
706 * @param[in] flags mount flags as in mount function
707 * @param[in] data additional data as in mount function
708 * @return status of this function call
710 VsmStatus vsm_declare_mount(VsmClient client,
719 * Create link in zone
721 * Declare link that will be created while zone startup
722 * Parameters are passed to link system function
724 * @param[in] client vasum-server's client
725 * @param[in] source path to link source (in host)
726 * @param[in] zone zone id
727 * @param[in] target path to link name (in zone)
728 * @return status of this function call
730 VsmStatus vsm_declare_link(VsmClient client,
736 * Get all declarations
738 * Gets all declarations of resourcies
739 * (@see ::vsm_declare_link, @see ::vsm_declare_mount, @see ::vsm_declare_linki)
741 * @param[in] client vasum-server's client
742 * @param[in] zone zone id
743 * @param[out] declarations array of declarations id
744 * @return status of this function call
746 VsmStatus vsm_list_declarations(VsmClient client,
748 VsmArrayString* declarations);
753 * Removes given declaration by its id (@see ::vsm_list_declarations)
755 * @param[in] client vasum-server's client
756 * @param[in] zone zone id
757 * @param[in] declaration declaration id
758 * @return status of this function call
760 VsmStatus vsm_remove_declaration(VsmClient client,
762 VsmString declaration);
771 * Functions using org.tizen.vasum.zone.manager D-Bus interface.
777 * Notification callback function signature.
779 * @param[in] zone source zone
780 * @param[in] application sending application name
781 * @param[in] message notification message
782 * @param data custom user's data pointer passed to vsm_add_notification_callback()
784 typedef void (*VsmNotificationCallback)(const char* zone,
785 const char* application,
789 * Send message to active zone.
791 * @param[in] client vasum-server's client
792 * @param[in] application application name
793 * @param[in] message message
794 * @return status of this function call
796 VsmStatus vsm_notify_active_zone(VsmClient client, const char* application, const char* message);
799 * Move file between zones.
801 * @param[in] client vasum-server's client
802 * @param[in] destZone destination zone id
803 * @param[in] path path to moved file
804 * @return status of this function call
806 VsmStatus vsm_file_move_request(VsmClient client, const char* destZone, const char* path);
809 * Register notification callback function.
811 * @note The callback function will be invoked on a different thread.
813 * @param[in] client vasum-server's client
814 * @param[in] notificationCallback callback function
815 * @param[in] data some extra data that will be passed to callback function
816 * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal,
817 * pointer can be NULL.
818 * @return status of this function call
820 VsmStatus vsm_add_notification_callback(VsmClient client,
821 VsmNotificationCallback notificationCallback,
823 VsmSubscriptionId* subscriptionId);
826 * Unregister notification callback function.
828 * @param[in] client vasum-server's client
829 * @param[in] subscriptionId subscription identifier returned by vsm_add_notification_callback
830 * @return status of this function call
832 VsmStatus vsm_del_notification_callback(VsmClient client, VsmSubscriptionId subscriptionId);
840 #endif /* VASUM_CLIENT_H */