int storage_init (char *params, void **config) { struct json_conf *conf; try { /* Create configuration */ conf = new struct json_conf; /* Create storage */ conf->storage = new Storage(); /* Process params */ process_startup_xml(conf, params); /* Configure metadata processing */ conf->storage->setMetadataProcessing(conf->metadata); /* Save configuration */ *config = conf; } catch (std::exception &e) { *config = NULL; MSG_ERROR(msg_module, "%s", e.what()); /* Free allocated memory */ delete conf->storage; delete conf; return 1; } MSG_DEBUG(msg_module, "initialized"); return 0; }
int storage_init(char *params, void **config) { MSG_DEBUG(msg_module, "Fastbit plugin: initialization"); struct fastbit_config *c = NULL; /* Create config structure */ *config = new struct fastbit_config; if (*config == NULL) { MSG_ERROR(msg_module, "Memory allocation failed (%s:%d)", __FILE__, __LINE__); return 1; } c = (struct fastbit_config*) *config; c->od_infos = new std::map<std::string, std::map<uint32_t, struct od_info>*>; if (c->od_infos == NULL) { MSG_ERROR(msg_module, "Memory allocation failed (%s:%d)", __FILE__, __LINE__); return 1; } c->index_en_id = new std::vector<std::string>; if (c->index_en_id == NULL) { MSG_ERROR(msg_module, "Memory allocation failed (%s:%d)", __FILE__, __LINE__); return 1; } c->dirs = new std::vector<std::string>; if (c->dirs == NULL) { MSG_ERROR(msg_module, "Memory allocation failed (%s:%d)", __FILE__, __LINE__); return 1; } /* Parse configuration xml and updated configure structure according to it */ if (process_startup_xml(params, c)) { MSG_ERROR(msg_module, "Unable to parse plugin configuration"); return 1; } /* On startup we expect to write to new directory */ c->new_dir = true; /* Create index thread */ if (pthread_create(&c->index_thread, NULL, reorder_index, c) != 0) { MSG_ERROR(msg_module, "pthread_create"); } return 0; }
/** * \brief Plugin initialization * * \param[in] params xml configuration * \param[in] ip_config intermediate process config * \param[in] ip_id intermediate process ID for template manager * \param[in] template_mgr template manager * \param[out] config config storage * \return 0 on success */ int intermediate_init(char* params, void* ip_config, uint32_t ip_id, ipfix_template_mgr* template_mgr, void** config) { /* Suppress compiler warning */ (void) ip_id; (void) template_mgr; if (!params) { MSG_ERROR(msg_module, "Missing plugin configuration"); return 1; } try { /* Create configuration */ plugin_conf *conf = new plugin_conf; /* Process params */ process_startup_xml(conf, params); /* Create RRD template */ for (uint16_t i = 0; i < fields.size(); ++i) { if (i > 0) { conf->templ += ":"; } conf->templ += fields[i]; } /* Save configuration */ conf->ip_config = ip_config; *config = conf; } catch (std::exception &e) { *config = NULL; MSG_ERROR(msg_module, "%s", e.what()); return 1; } MSG_DEBUG(msg_module, "initialized"); return 0; }