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