summaryrefslogtreecommitdiff
path: root/lib/gibber/gibber-r-multicast-sender.h
blob: 2642318cb944f724cac7e2a9752d7cf631ee5e88 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * gibber-r-multicast-sender.h - Header for GibberRMulticastSender
 * Copyright (C) 2006 Collabora Ltd.
 * @author Sjoerd Simons <sjoerd@luon.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef __GIBBER_R_MULTICAST_SENDER_H__
#define __GIBBER_R_MULTICAST_SENDER_H__

#include <glib-object.h>

#include "gibber-r-multicast-packet.h"

G_BEGIN_DECLS

typedef struct _GibberRMulticastSenderGroup GibberRMulticastSenderGroup;

struct _GibberRMulticastSenderGroup {
  /* <public>
   * GUINT_TO_POINTER (sender_id) => owned GibberRMulticastSender */
  GHashTable *senders;
  /* <private> */
  gboolean popping;
  gboolean stopped;
  /* queue of GibberRMulticast GibberRMulticastSender */
  GQueue *pop_queue;
  /* GArray of pending removal GibberRMulticastSenders */
  GPtrArray *pending_removal;
};

typedef struct _GibberRMulticastSender GibberRMulticastSender;
typedef struct _GibberRMulticastSenderClass GibberRMulticastSenderClass;

struct _GibberRMulticastSenderClass {
    GObjectClass parent_class;
};

typedef enum {
  /* We have no info about this sender whatsoever */
  GIBBER_R_MULTICAST_SENDER_STATE_NEW = 0,
  /* We know the sequence number we have to start from, but haven't send out
   * any data yet */
  GIBBER_R_MULTICAST_SENDER_STATE_PREPARING,
  /* Non-data Packets are flowing */
  GIBBER_R_MULTICAST_SENDER_STATE_RUNNING,
  /* Data is flowing */
  GIBBER_R_MULTICAST_SENDER_STATE_DATA_RUNNING,
  /* Node has failed, still pop packets but stop depending on it */
  GIBBER_R_MULTICAST_SENDER_STATE_FAILED,
  GIBBER_R_MULTICAST_SENDER_STATE_UNKNOWN_FAILED,
  GIBBER_R_MULTICAST_SENDER_STATE_STOPPED,
  /* Will be removed as soon as all dependencies are resolved */
  GIBBER_R_MULTICAST_SENDER_STATE_PENDING_REMOVAL,
} GibberRMulticastSenderState;

struct _GibberRMulticastSender {
    GObject parent;
    gchar *name;
    guint32 id;

    GibberRMulticastSenderState state;

    /* Next packet we want to send out */
    guint32 next_output_packet;
    /* Next data packet we want to send out. Can be different from
     * next_output_packet iff holding back data or a fragmented data message is
     * interleaved with control messages.. Guaranteed to be <=
     * next_output_packet */
    guint32 next_output_data_packet;

    /* Next packet we expect from the sender */
    guint32 next_input_packet;
};

GType gibber_r_multicast_sender_get_type (void);

/* TYPE MACROS */
#define GIBBER_TYPE_R_MULTICAST_SENDER \
  (gibber_r_multicast_sender_get_type ())
#define GIBBER_R_MULTICAST_SENDER(obj) \
  (G_TYPE_CHECK_INSTANCE_CAST((obj), GIBBER_TYPE_R_MULTICAST_SENDER, \
   GibberRMulticastSender))
#define GIBBER_R_MULTICAST_SENDER_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_CAST((klass), GIBBER_TYPE_R_MULTICAST_SENDER, \
   GibberRMulticastSenderClass))
#define GIBBER_IS_R_MULTICAST_SENDER(obj) \
  (G_TYPE_CHECK_INSTANCE_TYPE((obj), GIBBER_TYPE_R_MULTICAST_SENDER))
#define GIBBER_IS_R_MULTICAST_SENDER_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_TYPE((klass), GIBBER_TYPE_R_MULTICAST_SENDER))
#define GIBBER_R_MULTICAST_SENDER_GET_CLASS(obj) \
  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIBBER_TYPE_R_MULTICAST_SENDER, \
   GibberRMulticastSenderClass))

GibberRMulticastSenderGroup *gibber_r_multicast_sender_group_new (void);

void gibber_r_multicast_sender_group_free (GibberRMulticastSenderGroup *group);
void gibber_r_multicast_sender_group_stop (GibberRMulticastSenderGroup *group);
void gibber_r_multicast_sender_group_add (GibberRMulticastSenderGroup *group,
    GibberRMulticastSender *sender);

GibberRMulticastSender * gibber_r_multicast_sender_group_lookup (
    GibberRMulticastSenderGroup *group, guint32 sender_id);

GibberRMulticastSender * gibber_r_multicast_sender_group_lookup_by_name (
    GibberRMulticastSenderGroup *group, const gchar *name);

void gibber_r_multicast_sender_group_remove (
    GibberRMulticastSenderGroup *group, guint32 sender_id);

gboolean gibber_r_multicast_sender_group_push_packet (
  GibberRMulticastSenderGroup *group, GibberRMulticastPacket *packet);

GibberRMulticastSender *gibber_r_multicast_sender_new (guint32 id,
    const gchar *name, GibberRMulticastSenderGroup *group);

/* Sequence for this sender starts at packet_id */
void gibber_r_multicast_sender_update_start (GibberRMulticastSender *sender,
    guint32 packet_id);

void gibber_r_multicast_sender_update_end (GibberRMulticastSender *sender,
    guint32 packet_id);

void gibber_r_multicast_sender_set_failed (GibberRMulticastSender *sender);

void gibber_r_multicast_sender_set_data_start (GibberRMulticastSender *sender,
    guint32 packet_id);

/* Tell the sender to not signal data starting from this packet */
void gibber_r_multicast_sender_hold_data (GibberRMulticastSender *sender,
  guint32 packet_id);


/* Stop holding back data of the sender */
void gibber_r_multicast_sender_release_data (GibberRMulticastSender *sender);

void gibber_r_multicast_sender_push (GibberRMulticastSender *sender,
     GibberRMulticastPacket *packet);

void
gibber_r_multicast_senders_updated (GibberRMulticastSender *sender);

/* Returns TRUE if we were up to dated */
gboolean gibber_r_multicast_sender_seen (GibberRMulticastSender *sender,
    guint32 id);

gboolean gibber_r_multicast_sender_repair_request (
    GibberRMulticastSender *sender, guint32 id);

void gibber_r_multicast_sender_whois_push (GibberRMulticastSender *sender,
    const GibberRMulticastPacket *packet);

void gibber_r_multicast_sender_set_packet_repeat (
    GibberRMulticastSender *sender, guint32 packet_id, gboolean repeat);

/* Returns the amount of unpopped or unacked packets */
guint gibber_r_multicast_sender_packet_cache_size (
    GibberRMulticastSender *sender);

/* Ack management */
void gibber_r_multicast_sender_ack (GibberRMulticastSender *sender,
    guint32 ack);

/* Stop all pending requests, only reply to repair requests */
void gibber_r_multicast_sender_stop (GibberRMulticastSender *sender);

/* Trigger failure detection, for testing only */
void _gibber_r_multicast_TEST_sender_fail (GibberRMulticastSender *sender);

G_END_DECLS

#endif /* #ifndef __GIBBER_R_MULTICAST_SENDER_H__*/