1 /* PipeWire
2 *
3 * Copyright © 2020 Wim Taymans
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 #include <stdint.h>
26
27 #include <spa/utils/result.h>
28 #include <pipewire/log.h>
29
30 #include "defs.h"
31 #include "client.h"
32 #include "commands.h"
33 #include "message.h"
34 #include "log.h"
35
reply_new(const struct client * client,uint32_t tag)36 struct message *reply_new(const struct client *client, uint32_t tag)
37 {
38 struct message *reply = message_alloc(client->impl, -1, 0);
39
40 pw_log_debug("client %p: new reply tag:%u", client, tag);
41
42 message_put(reply,
43 TAG_U32, COMMAND_REPLY,
44 TAG_U32, tag,
45 TAG_INVALID);
46
47 return reply;
48 }
49
reply_error(struct client * client,uint32_t command,uint32_t tag,int res)50 int reply_error(struct client *client, uint32_t command, uint32_t tag, int res)
51 {
52 struct impl *impl = client->impl;
53 struct message *reply;
54 uint32_t error = res_to_err(res);
55 const char *name;
56 enum spa_log_level level;
57
58 if (command < COMMAND_MAX)
59 name = commands[command].name;
60 else
61 name = "invalid";
62
63 switch (res) {
64 case -ENOENT:
65 case -ENOTSUP:
66 level = SPA_LOG_LEVEL_INFO;
67 break;
68 default:
69 level = SPA_LOG_LEVEL_WARN;
70 break;
71 }
72
73 pw_log(level, "client %p [%s]: ERROR command:%d (%s) tag:%u error:%u (%s)",
74 client, client->name, command, name, tag, error, spa_strerror(res));
75
76 reply = message_alloc(impl, -1, 0);
77 message_put(reply,
78 TAG_U32, COMMAND_ERROR,
79 TAG_U32, tag,
80 TAG_U32, error,
81 TAG_INVALID);
82
83 return client_queue_message(client, reply);
84 }
85