factory.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef NETSNMP_FACTORY_H
  2. #define NETSNMP_FACTORY_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. typedef void * (netsnmp_factory_produce_f)(void);
  7. typedef int (netsnmp_factory_produce_noalloc_f)(void *);
  8. typedef struct netsnmp_factory_s {
  9. /*
  10. * a string describing the product the factory creates
  11. */
  12. const char *product;
  13. /*
  14. * a function to create an object in newly allcoated memory
  15. */
  16. netsnmp_factory_produce_f *produce;
  17. /*
  18. * a function to create an object in previously allcoated memory
  19. */
  20. netsnmp_factory_produce_noalloc_f *produce_noalloc;
  21. } netsnmp_factory;
  22. /*
  23. * init factory registry
  24. */
  25. void netsnmp_factory_init(void);
  26. /*
  27. * register a factory type
  28. */
  29. int netsnmp_factory_register(netsnmp_factory *f);
  30. /*
  31. * get a factory
  32. */
  33. netsnmp_factory* netsnmp_factory_get(const char* product);
  34. /*
  35. * ask a factory to produce an object
  36. */
  37. void * netsnmp_factory_produce(const char* product);
  38. /*
  39. * ask a factory to produce an object in the provided memory
  40. */
  41. int netsnmp_factory_produce_noalloc(const char *product, void *memory);
  42. /*
  43. * factory return codes
  44. */
  45. enum {
  46. FACTORY_NOERROR = 0,
  47. FACTORY_EXISTS,
  48. FACTORY_NOTFOUND,
  49. FACTORY_NOMEMORY,
  50. FACTORY_GENERR,
  51. FACTORY_MAXIMUM_ERROR
  52. };
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56. #endif /* NETSNMP_FACTORY_H */