Statistics
| Branch: | Revision:

grapes / src / Chunkiser / output-stream.c @ 4cdd16a7

History | View | Annotate | Download (1.14 KB)

1
#include <stdint.h>
2
#include <stdlib.h>
3
#include <string.h>
4

    
5
#include "chunk.h"
6
#include "config.h"
7
#include "chunkiser.h"
8
#include "dechunkiser_iface.h"
9

    
10
extern struct dechunkiser_iface out_avf;
11
extern struct dechunkiser_iface out_raw;
12

    
13
struct output_stream {
14
  struct dechunkiser_ctx *c;
15
  struct dechunkiser_iface *out;
16
};
17

    
18
struct output_stream *out_stream_init(const char *fname, const char *config)
19
{
20
  struct tag *cfg_tags;
21
  struct output_stream *res;
22

    
23
  res = malloc(sizeof(struct output_stream));
24
  if (res == NULL) {
25
    return NULL;
26
  }
27

    
28
#ifdef AVF
29
  res->out = &out_avf;
30
#else
31
  res->out = &out_raw;
32
#endif
33
  cfg_tags = config_parse(config);
34
  if (cfg_tags) {
35
    const char *type;
36

    
37
    type = config_value_str(cfg_tags, "dechunkiser");
38
    if (type && !strcmp(type, "raw")) {
39
      res->out = &out_raw;
40
    }
41
  }
42
  free(cfg_tags);
43

    
44
  res->c = res->out->open(fname, config);
45
  if (res->c == NULL) {
46
    free(res);
47

    
48
    return NULL;
49
  }
50

    
51
  return res;
52
}
53

    
54
void out_stream_close(struct output_stream *s)
55
{
56
  s->out->close(s->c);
57
  free(s);
58
}
59

    
60
void chunk_write(struct output_stream *o, const struct chunk *c)
61
{
62
  o->out->write(o->c, c->id, c->data, c->size);
63
}