tizen 2.3 release
[external/buxton.git] / docs / buxton_set_label.3
1 '\" t
2 .TH "BUXTON_SET_LABEL" "3" "buxton 1" "buxton_set_label"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el       .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 buxton_set_label \- Set the Smack label for a group or key
24
25 .SH "SYNOPSIS"
26 .nf
27 \fB
28 #include <buxton.h>
29 \fR
30 .sp
31 \fB
32 int buxton_set_label(BuxtonClient \fIclient\fB,
33 .br
34                      BuxtonKey \fIkey\fB,
35 .br
36                      char *\fIvalue\fB,
37 .br
38                      BuxtonCallback \fIcallback\fB,
39 .br
40                      void *\fIdata\fB,
41 .br
42                      bool \fIsync\fB)
43 \fR
44 .fi
45
46 .SH "DESCRIPTION"
47 .PP
48 This function is used to set a Smack label, \fIvalue\fR, on a group
49 or key, referred to by \fIkey\fR, on behalf of \fIclient\fR.
50
51 Note that setting a Smack label is always a privileged operation, so
52 this operation will fail for unprivileged clients\&.
53
54 Both functions accept optional callback functions to register with
55 the daemon, referenced by the \fIcallback\fR argument; the callback
56 function is called upon completion of the operation\&. The \fIdata\fR
57 argument is a pointer to arbitrary userdata that is passed along to
58 the callback function\&. Additonally, the \fIsync\fR argument
59 controls whether the operation should be synchronous or not; if
60 \fIsync\fR is false, the operation is asynchronous\&.
61
62 .SH "CODE EXAMPLE"
63 .nf
64 .sp
65 #define _GNU_SOURCE
66 #include <poll.h>
67 #include <stdio.h>
68 #include <stdlib.h>
69 #include <string.h>
70
71 #include "buxton.h"
72
73 void set_label_cb(BuxtonResponse response, void *data)
74 {
75         BuxtonKey key;
76         char *name;
77
78         if (buxton_response_status(response) != 0) {
79                 printf("Failed to set label\\n");
80                 return;
81         }
82
83         key = buxton_response_key(response);
84         name = buxton_key_get_name(key);
85         printf("Set label for key %s\\n", name);
86         buxton_key_free(key);
87         free(name);
88 }
89
90 int main(void)
91 {
92         BuxtonClient client;
93         BuxtonKey key;
94         struct pollfd pfd[1];
95         int r;
96         int fd;
97         char* label = "label-test";
98
99         if ((fd = buxton_open(&client)) < 0) {
100                 printf("couldn't connect\\n");
101                 return -1;
102         }
103
104         key = buxton_key_create("hello", "test", "user", INT32);
105         if (!key) {
106                 return -1;
107         }
108
109         if (buxton_set_label(client, key, label, set_label_cb,
110                              NULL, false)) {
111                 printf("set label call failed to run\\n");
112                 return -1;
113         }
114
115         pfd[0].fd = fd;
116         pfd[0].events = POLLIN;
117         pfd[0].revents = 0;
118         r = poll(pfd, 1, 5000);
119
120         if (r <= 0) {
121                 printf("poll error\\n");
122                 return -1;
123         }
124
125         if (!buxton_client_handle_response(client)) {
126                 printf("bad response from daemon\\n");
127                 return -1;
128         }
129
130         buxton_key_free(key);
131         buxton_close(client);
132         return 0;
133 }
134 .fi
135
136 .SH "RETURN VALUE"
137 .PP
138 Returns 0 on success, and a non\-zero value on failure\&.
139
140 .SH "COPYRIGHT"
141 .PP
142 Copyright 2014 Intel Corporation\&. License: Creative Commons
143 Attribution\-ShareAlike 3.0 Unported\s-2\u[1]\d\s+2, with exception
144 for code examples found in the \fBCODE EXAMPLE\fR section, which are
145 licensed under the MIT license provided in the \fIdocs/LICENSE.MIT\fR
146 file from this buxton distribution\&.
147
148 .SH "SEE ALSO"
149 .PP
150 \fBbuxton\fR(7),
151 \fBbuxtond\fR(8),
152 \fBbuxton\-api\fR(7)
153
154 .SH "NOTES"
155 .IP " 1." 4
156 Creative Commons Attribution\-ShareAlike 3.0 Unported
157 .RS 4
158 \%http://creativecommons.org/licenses/by-sa/3.0/
159 .RE