[5888] | 1 | //service-about.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2013 |
---|
| 5 | * |
---|
| 6 | * This file is part of roard a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
| 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include <roard/include/roard.h> |
---|
| 27 | |
---|
| 28 | static ssize_t __list(int * ids, size_t len) { |
---|
| 29 | struct roar_client * c; |
---|
| 30 | size_t i, j; |
---|
| 31 | |
---|
| 32 | if ( g_counters.cur.clients > len ) { |
---|
| 33 | roar_err_set(ROAR_ERROR_NOSPC); |
---|
| 34 | return -1; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | for (j = i = 0; i < ROAR_CLIENTS_MAX && j < len; i++) |
---|
| 38 | if ( clients_get(i, &c) == 0 ) |
---|
| 39 | ids[j++] = i; |
---|
| 40 | |
---|
| 41 | return j; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | static ssize_t __num(enum roar_service_num what) { |
---|
| 45 | switch (what) { |
---|
| 46 | case ROAR_SERVICE_NUM_DEFAULT: |
---|
| 47 | case ROAR_SERVICE_NUM_CURRENT: |
---|
| 48 | return g_counters.cur.clients; |
---|
| 49 | break; |
---|
| 50 | case ROAR_SERVICE_NUM_BUFFER: |
---|
| 51 | if ( ((double)g_counters.cur.clients * 1.5) > ROAR_CLIENTS_MAX ) |
---|
| 52 | return ROAR_CLIENTS_MAX; |
---|
| 53 | return (double)g_counters.cur.clients * 1.25; |
---|
| 54 | break; |
---|
| 55 | #ifndef DEBUG |
---|
| 56 | default: break; |
---|
| 57 | #endif |
---|
| 58 | } |
---|
| 59 | roar_err_set(ROAR_ERROR_NOTSUP); |
---|
| 60 | return -1; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | static int __get(int id, struct roar_client * client) { |
---|
| 64 | struct roar_client * c; |
---|
| 65 | |
---|
| 66 | if ( client == NULL ) { |
---|
| 67 | roar_err_set(ROAR_ERROR_FAULT); |
---|
| 68 | return -1; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | if ( clients_get(id, &c) == -1 ) |
---|
| 72 | return -1; |
---|
| 73 | |
---|
| 74 | memcpy(client, c, sizeof(struct roar_client)); |
---|
| 75 | client->acl = NULL; |
---|
| 76 | |
---|
| 77 | return 0; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | static int __status(int id) { |
---|
| 81 | struct roar_dl_librarypara * pluginpara; |
---|
| 82 | const struct roard_proto_handle * proto; |
---|
| 83 | struct roar_client_server * cs; |
---|
| 84 | struct roar_vio_calls vio; |
---|
| 85 | int ret, err; |
---|
| 86 | |
---|
| 87 | if ( clients_get_server(id, &cs) == -1 ) |
---|
| 88 | return -1; |
---|
| 89 | |
---|
| 90 | if ( (proto = clients_get_protohandle(ROAR_CLIENT(cs)->proto)) == NULL ) |
---|
| 91 | return -1; |
---|
| 92 | |
---|
| 93 | if ( proto->lhandle != NULL ) |
---|
| 94 | roar_dl_context_restore(proto->lhandle); |
---|
| 95 | |
---|
| 96 | pluginpara = roar_dl_getpara(proto->lhandle); |
---|
| 97 | |
---|
| 98 | switch (proto->type) { |
---|
| 99 | case ROARD_PROTO_TYPE_COMMON: |
---|
| 100 | if ( proto->impl.common->status == NULL ) { |
---|
| 101 | ret = -1; |
---|
| 102 | err = ROAR_ERROR_NOSYS; |
---|
| 103 | } else { |
---|
| 104 | roar_vio_open_fh_socket(&vio, clients_get_fh(id)); |
---|
| 105 | ret = proto->impl.common->status(id, &vio, &(cs->outbuf), &(cs->protoinst), proto->para, proto->paralen, pluginpara); |
---|
| 106 | } |
---|
| 107 | break; |
---|
| 108 | default: |
---|
| 109 | ret = -1; |
---|
| 110 | err = ROAR_ERROR_NOSYS; |
---|
| 111 | break; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | if ( pluginpara != NULL ) |
---|
| 115 | roar_dl_para_unref(pluginpara); |
---|
| 116 | |
---|
| 117 | if ( proto->lhandle != NULL ) |
---|
| 118 | roar_dl_context_store(proto->lhandle); |
---|
| 119 | |
---|
| 120 | roar_err_set(err); |
---|
| 121 | return ret; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | static int __set_ids(int id, int clear, int pid, int uid, int gid) { |
---|
| 125 | struct roar_client * c; |
---|
| 126 | |
---|
| 127 | // just to check if the client exist. |
---|
| 128 | if ( clients_get(id, &c) == -1 ) |
---|
| 129 | return -1; |
---|
| 130 | |
---|
| 131 | // TODO: add proper error handling here. |
---|
| 132 | |
---|
| 133 | if ( pid != -1 || clear ) |
---|
| 134 | clients_set_pid(id, pid); |
---|
| 135 | |
---|
| 136 | if ( uid != -1 || clear ) |
---|
| 137 | clients_set_uid(id, uid); |
---|
| 138 | |
---|
| 139 | if ( gid != -1 || clear ) |
---|
| 140 | clients_set_gid(id, gid); |
---|
| 141 | |
---|
| 142 | return 0; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | static int __set_proto(int id, int proto) { |
---|
| 146 | (void)id, (void)proto; |
---|
| 147 | |
---|
| 148 | roar_err_set(ROAR_ERROR_NOSYS); |
---|
| 149 | return -1; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | static struct roar_service_client api = { |
---|
| 154 | .list = __list, |
---|
| 155 | .num = __num, |
---|
| 156 | .get = __get, |
---|
| 157 | .kick = (int(*)(int id, int error, const char * msg))clients_delete, |
---|
| 158 | .status = __status, |
---|
| 159 | |
---|
| 160 | .set_ids = __set_ids, |
---|
| 161 | .set_name = clients_set_name, |
---|
| 162 | .set_proto = __set_proto, /* dummy */ |
---|
| 163 | .exec = client_stream_exec |
---|
| 164 | }; |
---|
| 165 | |
---|
| 166 | ROAR_DL_PLUGIN_REG_SERVICES_GET_API(get_api, api) |
---|
| 167 | |
---|
| 168 | static const struct roar_dl_service service[1] = { |
---|
| 169 | { |
---|
| 170 | .appname = NULL, |
---|
| 171 | .appabi = NULL, |
---|
| 172 | .servicename = ROAR_SERVICE_CLIENT_NAME, |
---|
| 173 | .serviceabi = ROAR_SERVICE_CLIENT_ABI, |
---|
| 174 | .description = "Access to client management", |
---|
| 175 | .flags = ROAR_DL_SERVICE_FLAGS_NONE, |
---|
| 176 | .userdata = NULL, |
---|
| 177 | .get_api = get_api |
---|
| 178 | } |
---|
| 179 | }; |
---|
| 180 | |
---|
| 181 | ROAR_DL_PLUGIN_REG_SERVICES(service); |
---|
| 182 | |
---|
| 183 | ROAR_DL_PLUGIN_START(service_client) { |
---|
| 184 | ROAR_DL_PLUGIN_META_PRODUCT_NIV("service-client", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); |
---|
| 185 | ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); |
---|
| 186 | ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0); |
---|
| 187 | ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org"); |
---|
| 188 | ROAR_DL_PLUGIN_META_DESC("This plugin provides an interface to client control features of roard."); |
---|
| 189 | ROAR_DL_PLUGIN_REG_FNFUNC(ROAR_DL_FN_SERVICE); |
---|
| 190 | } ROAR_DL_PLUGIN_END |
---|
| 191 | |
---|
| 192 | //ll |
---|