summaryrefslogtreecommitdiff
path: root/include/net-snmp/library/factory.h
blob: faf82a2274793cf0ec13530c2ddfaa20bbadb40d (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
#ifndef NETSNMP_FACTORY_H
#define NETSNMP_FACTORY_H


#ifdef __cplusplus
extern "C" {
#endif

    typedef void * (netsnmp_factory_produce_f)(void);
    typedef int (netsnmp_factory_produce_noalloc_f)(void *);

    typedef struct netsnmp_factory_s {
        /*
         * a string describing the product the factory creates
         */
        const char                           *product;

        /*
         * a function to create an object in newly allcoated memory
         */
        netsnmp_factory_produce_f            *produce;

        /*
         * a function to create an object in previously allcoated memory
         */
        netsnmp_factory_produce_noalloc_f    *produce_noalloc;

    } netsnmp_factory;

    /*
     * init factory registry
     */
    void netsnmp_factory_init(void);

    /*
     * register a factory type
     */
    int  netsnmp_factory_register(netsnmp_factory *f);

    /*
     * get a factory
     */
    netsnmp_factory* netsnmp_factory_get(const char* product);

    /*
     * ask a factory to produce an object
     */
    void * netsnmp_factory_produce(const char* product);

    /*
     * ask a factory to produce an object in the provided memory
     */
    int netsnmp_factory_produce_noalloc(const char *product, void *memory);

    /*
     * factory return codes
     */
    enum {
        FACTORY_NOERROR = 0,
        FACTORY_EXISTS,
        FACTORY_NOTFOUND,
        FACTORY_NOMEMORY,
        FACTORY_GENERR,
        FACTORY_MAXIMUM_ERROR
    };

#ifdef __cplusplus
}
#endif


#endif /* NETSNMP_FACTORY_H */