summaryrefslogtreecommitdiff
path: root/include/ouroboros/cdap.h
blob: e26f192bf82b5981cc8054620a5615d99c38234a (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
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Ouroboros - Copyright (C) 2016
 *
 * The Common Distributed Application Protocol
 *
 *    Sander Vrijders   <sander.vrijders@intec.ugent.be>
 *    Dimitri Staessens <dimitri.staessens@intec.ugent.be>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef OUROBOROS_CDAP_H
#define OUROBOROS_CDAP_H

#include <ouroboros/common.h>

#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>

#define F_SYNC 0x0001

struct cdap;

/* Callback functions that work on the application's RIB */
struct cdap_ops {
        int (* cdap_reply)(struct cdap * instance,
                           int           invoke_id,
                           int           result,
                           buffer_t *    val,
                           size_t        len);

        int (* cdap_read)(struct cdap * instance,
                          char *        name);
        int (* cdap_write)(struct cdap * instance,
                           char *        name,
                           buffer_t *    val,
                           size_t        len,
                           uint32_t      flags);

        int (* cdap_create)(struct cdap * instance,
                            char *        name,
                            buffer_t      val);
        int (* cdap_delete)(struct cdap * instance,
                            char *        name,
                            buffer_t      val);

        int (* cdap_start)(struct cdap * instance,
                           char *        name);
        int (* cdap_stop)(struct cdap * instance,
                          char *        name);
};

/* Assumes flow is blocking */
struct cdap * cdap_create(struct cdap_ops * ops,
                          int               fd);
int           cdap_destroy(struct cdap * instance);

/* Returns a positive invoke-id on success to be used in the callback */
int           cdap_send_read(struct cdap * instance,
                             char *        name);
int           cdap_send_write(struct cdap * instance,
                              char *        name,
                              buffer_t *    val,
                              size_t        len,
                              uint32_t      flags);

int           cdap_send_create(struct cdap * instance,
                               char *        name,
                               buffer_t      val);
int           cdap_send_delete(struct cdap * instance,
                               char *        name,
                               buffer_t      val);

int           cdap_send_start(struct cdap * instance,
                              char *        name);
int           cdap_send_stop(struct cdap * instance,
                             char *        name);

/* Can only be called following a callback function */
int           cdap_send_reply(struct cdap * instance,
                              int           invoke_id,
                              int           result,
                              buffer_t *    val,
                              size_t        len);
#endif