Statistics
| Branch: | Revision:

grapes / src / Chunkiser / input-stream.c @ fd1d8d92

History | View | Annotate | Download (991 Bytes)

1 c0c735aa Luca Abeni
#include <stdint.h>
2 89aef955 Luca Abeni
#include <stdlib.h>
3 fd1d8d92 Luca Abeni
#include <string.h>
4 c0c735aa Luca Abeni
5 606948b2 Luca Abeni
#include "chunk.h"
6 fd1d8d92 Luca Abeni
#include "config.h"
7 c0c735aa Luca Abeni
#include "chunkiser.h"
8
#include "chunkiser_iface.h"
9
10
extern struct chunkiser_iface in_avf;
11 91e9c5d5 Luca Abeni
extern struct chunkiser_iface in_dummy;
12 c0c735aa Luca Abeni
13
static struct chunkiser_iface *in;
14
15
struct input_stream *input_stream_open(const char *fname, int *period, const char *config)
16
{
17 fd1d8d92 Luca Abeni
  struct tag *cfg_tags;
18
19 89aef955 Luca Abeni
#ifdef AVF
20 c0c735aa Luca Abeni
  in = &in_avf;
21 89aef955 Luca Abeni
#else
22 91e9c5d5 Luca Abeni
  in = &in_dummy;
23 89aef955 Luca Abeni
#endif
24 fd1d8d92 Luca Abeni
  cfg_tags = config_parse(config);
25
26
  if (cfg_tags) {
27
    const char *type;
28
29
    type = config_value_str(cfg_tags, "chunkiser");
30
    if (type && !strcmp(type, "dummy")) {
31
      in = &in_dummy;
32
    }
33
  }
34 91e9c5d5 Luca Abeni
35 c0c735aa Luca Abeni
  return in->open(fname, period, config);
36
}
37
38
void input_stream_close(struct input_stream *s)
39
{
40
  return in->close(s);
41
}
42
43 606948b2 Luca Abeni
int chunkise(struct input_stream *s, struct chunk *c)
44 c0c735aa Luca Abeni
{
45 606948b2 Luca Abeni
  c->data = in->chunkise(s, c->id, &c->size, &c->timestamp);
46
  if (c->data == NULL) {
47
    if (c->size < 0) {
48
      return -1;
49
    }
50
51
    return 0;
52
  }
53
54
  return 1;
55 c0c735aa Luca Abeni
}