src/simple_hello.c
author Tero Marttila <terom@fixme.fi>
Sat, 13 Dec 2008 20:58:27 +0200
branchnew-evsql
changeset 55 0b92d553400a
parent 10 e74c23297b11
permissions -rw-r--r--
evsql: more improvements
terom@6
     1
#include <event2/event.h>
terom@6
     2
terom@6
     3
#include "lib/log.h"
terom@6
     4
#include "lib/signals.h"
terom@6
     5
#include "evfuse.h"
terom@6
     6
#include "simple.h"
terom@6
     7
terom@6
     8
static struct hello {
terom@6
     9
    struct event_base *ev_base;
terom@6
    10
terom@6
    11
    struct signals *signals;
terom@6
    12
terom@6
    13
    struct simple_fs *fs;
terom@6
    14
terom@6
    15
    struct evfuse *ev_fuse;
terom@6
    16
terom@6
    17
} ctx;
terom@6
    18
terom@6
    19
static struct simple_node node_list[] = {
terom@6
    20
    {   1,  S_IFDIR,    0555,   0,  NULL,       NULL                },
terom@6
    21
    {   2,  S_IFREG,    0444,   1,  "hello",    "Hello World!\n"    },
terom@6
    22
    {   3,  S_IFREG,    0444,   1,  "foo",      "Foo\n"             },
terom@10
    23
    {   4,  S_IFREG,    0444,   1,  "bar",      "Bar\n"             },
terom@10
    24
    {   5,  S_IFDIR,    0555,   1,  "test",     NULL                },
terom@10
    25
    {   6,  S_IFREG,    0444,   5,  "file0",    "data0\n"           },
terom@10
    26
    {   7,  S_IFREG,    0444,   5,  "file1",    "data1\n"           },
terom@10
    27
    {   8,  S_IFLNK,    0444,   1,  "lnk0",     "test/file0"        },
terom@10
    28
    {   0,  0,          0,      0,  NULL,       NULL                },
terom@6
    29
};
terom@6
    30
terom@6
    31
int main (int argc, char **argv) {
terom@6
    32
    struct fuse_args fuse_args = FUSE_ARGS_INIT(argc, argv);
terom@6
    33
    
terom@6
    34
    // init libevent
terom@6
    35
    if ((ctx.ev_base = event_base_new()) == NULL)
terom@6
    36
        ERROR("event_base_new");
terom@6
    37
    
terom@6
    38
    // setup signals
terom@6
    39
    if ((ctx.signals = signals_default(ctx.ev_base)) == NULL)
terom@6
    40
        ERROR("signals_default");
terom@6
    41
    
terom@6
    42
    // setup fs
terom@6
    43
    if ((ctx.fs = simple_new(node_list)) == NULL)
terom@6
    44
        ERROR("simple_new");
terom@6
    45
terom@6
    46
    // open fuse
terom@6
    47
    if ((ctx.ev_fuse = evfuse_new(ctx.ev_base, &fuse_args, simple_init(), ctx.fs)) == NULL)
terom@6
    48
        ERROR("evfuse_new");
terom@6
    49
terom@6
    50
    // run libevent
terom@6
    51
    INFO("running libevent loop");
terom@6
    52
terom@6
    53
    if (event_base_dispatch(ctx.ev_base))
terom@6
    54
        PERROR("event_base_dispatch");
terom@6
    55
    
terom@6
    56
    // clean shutdown
terom@6
    57
terom@6
    58
error :
terom@6
    59
    // cleanup
terom@6
    60
    if (ctx.ev_fuse)
terom@6
    61
        evfuse_free(ctx.ev_fuse);
terom@27
    62
terom@6
    63
/*
terom@6
    64
    if (ctx.fs)
terom@6
    65
        simple_close(ctx.fs);
terom@6
    66
*/
terom@6
    67
terom@6
    68
    if (ctx.signals)
terom@6
    69
        signals_free(ctx.signals);
terom@6
    70
terom@6
    71
    if (ctx.ev_base)
terom@6
    72
        event_base_free(ctx.ev_base);
terom@6
    73
    
terom@6
    74
    fuse_opt_free_args(&fuse_args);
terom@6
    75
}
terom@6
    76