154c2af9b39900c28d81bf9867113d63bd89a890
[profile/ivi/speech-recognition.git] / src / daemon / client.h
1 /*
2  * Copyright (c) 2012, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *   * Redistributions of source code must retain the above copyright notice,
9  *     this list of conditions and the following disclaimer.
10  *   * Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *   * Neither the name of Intel Corporation nor the names of its contributors
14  *     may be used to endorse or promote products derived from this software
15  *     without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef __SRS_DAEMON_CLIENT_H__
31 #define __SRS_DAEMON_CLIENT_H__
32
33 typedef struct srs_client_s srs_client_t;
34
35 #include "src/daemon/context.h"
36 #include "src/daemon/resourceif.h"
37
38
39 /*
40  * client types
41  */
42
43 typedef enum {
44     SRS_CLIENT_TYPE_UNKNOWN = 0,
45     SRS_CLIENT_TYPE_DBUS,                /* external D-BUS client */
46     SRS_CLIENT_TYPE_BUILTIN,             /* builtin client */
47 } srs_client_type_t;
48
49
50 /*
51  * voice focus types
52  */
53
54 typedef enum {
55     SRS_VOICE_FOCUS_NONE = 0,            /* focus released */
56     SRS_VOICE_FOCUS_SHARED,              /* normal shared voice focus */
57     SRS_VOICE_FOCUS_EXCLUSIVE,           /* exclusive voice focus */
58 } srs_voice_focus_t;
59
60
61 /*
62  * client commands
63  */
64
65 typedef struct {
66     char **tokens;                       /* tokens of this command */
67     int    ntoken;                       /* number of tokens */
68 } srs_command_t;
69
70
71 /*
72  * connected clients
73  */
74
75 typedef struct {
76     int (*notify_focus)(srs_client_t *c, srs_voice_focus_t focus);
77     int (*notify_command)(srs_client_t *c, int ntoken, char **tokens);
78 } srs_client_ops_t;
79
80
81 struct srs_client_s {
82     mrp_list_hook_t         hook;        /* to list of clients */
83     srs_client_type_t       type;        /* client type */
84     char                   *name;        /* client name */
85     char                   *appclass;    /* client application class */
86     srs_command_t          *commands;    /* client command set */
87     int                     ncommand;    /* number of commands */
88     char                   *id;          /* client id */
89     srs_context_t          *srs;         /* context back pointer */
90     mrp_res_resource_set_t *rset;        /* resource set */
91     srs_voice_focus_t       requested;   /* requested voice focus */
92     srs_voice_focus_t       granted;     /* granted voice focus */
93     srs_voice_focus_t       focus;       /* requested voice focus */
94     int                     enabled : 1; /* interested in commands */
95     int                     allowed : 1; /* has resource granted */
96     srs_client_ops_t       *ops;         /* client ops (notifications)  */
97 };
98
99
100 /** Create a new client. */
101 srs_client_t *client_create(srs_context_t *srs, srs_client_type_t type,
102                             const char *name, const char *appclass,
103                             char **commands, int ncommand,
104                             const char *id, srs_client_ops_t *ops);
105
106 /** Destroy a client. */
107 void client_destroy(srs_client_t *c);
108
109 /** Look up a client by its id. */
110 srs_client_t *client_lookup_by_id(srs_context_t *srs, const char *id);
111
112 /** Request client focus change. */
113 int client_request_focus(srs_client_t *c, srs_voice_focus_t focus);
114
115 /** Create resources for all registered clients. */
116 void client_create_resources(srs_context_t *srs);
117
118 /** Reset the resource sets of all clients. */
119 void client_reset_resources(srs_context_t *srs);
120
121 /** Deliver a resource notification event to the client. */
122 void client_resource_event(srs_client_t *c, srs_resset_event_t event);
123
124 #endif /* __SRS_DAEMON_CLIENT_H__ */