net-snmp 5.7
factory.h
00001 #ifndef NETSNMP_FACTORY_H
00002 #define NETSNMP_FACTORY_H
00003 
00004 
00005 #ifdef __cplusplus
00006 extern "C" {
00007 #endif
00008 
00009     typedef void * (netsnmp_factory_produce_f)(void);
00010     typedef int (netsnmp_factory_produce_noalloc_f)(void *);
00011 
00012     typedef struct netsnmp_factory_s {
00013         /*
00014          * a string describing the product the factory creates
00015          */
00016         const char                           *product;
00017 
00018         /*
00019          * a function to create an object in newly allcoated memory
00020          */
00021         netsnmp_factory_produce_f            *produce;
00022 
00023         /*
00024          * a function to create an object in previously allcoated memory
00025          */
00026         netsnmp_factory_produce_noalloc_f    *produce_noalloc;
00027 
00028     } netsnmp_factory;
00029 
00030     /*
00031      * init factory registry
00032      */
00033     void netsnmp_factory_init(void);
00034 
00035     /*
00036      * register a factory type
00037      */
00038     int  netsnmp_factory_register(netsnmp_factory *f);
00039 
00040     /*
00041      * get a factory
00042      */
00043     netsnmp_factory* netsnmp_factory_get(const char* product);
00044 
00045     /*
00046      * ask a factory to produce an object
00047      */
00048     void * netsnmp_factory_produce(const char* product);
00049 
00050     /*
00051      * ask a factory to produce an object in the provided memory
00052      */
00053     int netsnmp_factory_produce_noalloc(const char *product, void *memory);
00054 
00055     /*
00056      * factory return codes
00057      */
00058     enum {
00059         FACTORY_NOERROR = 0,
00060         FACTORY_EXISTS,
00061         FACTORY_NOTFOUND,
00062         FACTORY_NOMEMORY,
00063         FACTORY_GENERR,
00064         FACTORY_MAXIMUM_ERROR
00065     };
00066 
00067 #ifdef __cplusplus
00068 }
00069 #endif
00070 
00071 
00072 #endif /* NETSNMP_FACTORY_H */