aboutsummaryrefslogtreecommitdiffstats
path: root/lib/server.h
blob: 3cc0ed978227652ec2c3d27d71d007e97fe829ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* PipeWire AGL Cluster IPC
 *
 * Copyright © 2021 Collabora Ltd.
 *    @author Julian Bouzas <julian.bouzas@collabora.com>
 *
 * SPDX-License-Identifier: MIT
 */

#ifndef __ICIPC_SERVER_H__
#define __ICIPC_SERVER_H__

#include <spa/pod/pod.h>

#include "defs.h"

#include "receiver.h"

#ifdef __cplusplus
extern "C" {
#endif

#define icipc_server_to_receiver(self) ((struct icipc_receiver *)(self))

struct icipc_server;

typedef void (*icipc_server_client_handler_func_t) (struct icipc_server *self,
                                                    int client_fd,
                                                    enum icipc_receiver_sender_state client_state,
                                                    void *data);

typedef bool (*icipc_server_request_handler_func_t) (struct icipc_server *self,
                                                     int client_fd,
                                                     const char *name,
                                                     const struct spa_pod *args,
                                                     void *data);

ICIPC_API
struct icipc_server *
icipc_server_new (const char *path, bool start);

ICIPC_API
void
icipc_server_free (struct icipc_server *self);

ICIPC_API
void
icipc_server_set_client_handler (struct icipc_server *self,
                                 icipc_server_client_handler_func_t handler,
                                 void *data);

ICIPC_API
void
icipc_server_clear_client_handler (struct icipc_server *self);

ICIPC_API
bool
icipc_server_set_request_handler (struct icipc_server *self,
                                  const char *name,
                                  icipc_server_request_handler_func_t handler,
                                  void *data);

ICIPC_API
void
icipc_server_clear_request_handler (struct icipc_server *self,
                                    const char *name);

/* for request handlers only */

ICIPC_API
bool
icipc_server_reply_ok (struct icipc_server *self,
                       int client_fd,
                       const struct spa_pod *value);

ICIPC_API
bool
icipc_server_reply_error (struct icipc_server *self,
                          int client_fd,
                          const char *msg);

#ifdef __cplusplus
}
#endif

#endif