<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/11154">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">sorcery.c: Sorcery enhancements for wizard management<br><br>Added ability to specifiy a wizard is read-only when applying<br>it to a specific object type. This allows you to specify<br>create, update and delete callbacks for the wizard but limit<br>which object types can use them.<br><br>Added 2 new sorcery wizard functions:<br><br>* ast_sorcery_object_type_insert_wizard which does the same thing<br> as the existing ast_sorcery_insert_wizard_mapping function but<br> accepts the new read-only flag and also returns the<br> ast_sorcery_wizard structure used and it's internal data structure.<br> This allows immediate use of the wizard's callbacks without<br> having to register a "wizard mapped" observer.<br><br>* ast_sorcery_object_type_apply_wizard which does the same<br> thing as the existing ast_sorcery_apply_wizard_mapping function<br> but has the added same capabilities of<br> ast_sorcery_object_type_insert_wizard.<br><br>* The original logic in __ast_sorcery_insert_wizard_mapping was moved<br> to __ast_sorcery_object_type_insert_wizard and enhanced for the<br> new capabilities, then __ast_sorcery_insert_wizard_mapping was<br> refactored to just call __ast_sorcery_insert_wizard_mapping.<br><br>* Added a unit test to test_sorcery.c to test the read-only<br> capability.<br><br>Change-Id: I40f35840252e4313d99e11dbd80e270a3aa10605<br>---<br>M include/asterisk/sorcery.h<br>M main/sorcery.c<br>M tests/test_sorcery.c<br>3 files changed, 173 insertions(+), 22 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/54/11154/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/sorcery.h b/include/asterisk/sorcery.h</span><br><span>index 73ed060..dab6853 100644</span><br><span>--- a/include/asterisk/sorcery.h</span><br><span>+++ b/include/asterisk/sorcery.h</span><br><span>@@ -570,6 +570,61 @@</span><br><span> (caching), (position))</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Insert an additional object wizard mapping at a specific position</span><br><span style="color: hsl(120, 100%, 40%);">+ * in the wizard list returning wizard information</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.26.0</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 16.3.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param sorcery Pointer to a sorcery structure</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param object_type_name Name of the object type to apply to</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param module The name of the module, typically AST_MODULE</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param wizard_name Name of the wizard to use</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param wizard_args Opaque string to be passed to the wizard</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param caching Wizard should cache</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param read_only Wizard should be read-only</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param position An index to insert to or one of ast_sorcery_wizard_position</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[out] wizard A variable to receive a pointer to the ast_sorcery_wizard structure.</span><br><span style="color: hsl(120, 100%, 40%);">+ * May be NULL if not needed.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[out] wizard_data A variable to receive a pointer to the wizard's internal data.</span><br><span style="color: hsl(120, 100%, 40%);">+ * May be NULL if not needed.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return What occurred when applying the mapping</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note This should be called *after* applying default mappings</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+enum ast_sorcery_apply_result __ast_sorcery_object_type_insert_wizard(struct ast_sorcery *sorcery,</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *object_type_name, const char *module, const char *wizard_name,</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *wizard_args, unsigned int caching, unsigned int read_only, int position,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sorcery_wizard **wizard, void **wizard_data);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Apply additional object wizard mappings returning wizard information</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.26.0</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 16.3.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param sorcery Pointer to a sorcery structure</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param object_type_name Name of the object type to apply to</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param wizard_name Name of the wizard to use</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param wizard_args Opaque string to be passed to the wizard</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param caching Wizard should cache</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param read_only Wizard should be read-only</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[out] wizard A variable to receive a pointer to the ast_sorcery_wizard structure.</span><br><span style="color: hsl(120, 100%, 40%);">+ * May be NULL if not needed.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[out] wizard_data A variable to receive a pointer to the wizard's internal data.</span><br><span style="color: hsl(120, 100%, 40%);">+ * May be NULL if not needed.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return What occurred when applying the mapping</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note This should be called *after* applying default mappings</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+#define ast_sorcery_object_type_apply_wizard(sorcery, \</span><br><span style="color: hsl(120, 100%, 40%);">+ object_type_name, wizard_name, wizard_args, caching, read_only, \</span><br><span style="color: hsl(120, 100%, 40%);">+ wizard, wizard_data) \</span><br><span style="color: hsl(120, 100%, 40%);">+ __ast_sorcery_object_type_insert_wizard((sorcery), \</span><br><span style="color: hsl(120, 100%, 40%);">+ (object_type_name), AST_MODULE, (wizard_name), (wizard_args), (caching), (read_only), \</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_SORCERY_WIZARD_POSITION_LAST, (wizard), (wizard_data))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Remove an object wizard mapping</span><br><span> *</span><br><span> * \param sorcery Pointer to a sorcery structure</span><br><span>diff --git a/main/sorcery.c b/main/sorcery.c</span><br><span>index 3a43fa7..712ac80 100644</span><br><span>--- a/main/sorcery.c</span><br><span>+++ b/main/sorcery.c</span><br><span>@@ -111,6 +111,9 @@</span><br><span> </span><br><span> /*! \brief Wizard is acting as an object cache */</span><br><span> unsigned int caching:1;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! \brief Wizard is read_only */</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int read_only:1;</span><br><span> };</span><br><span> </span><br><span> /*! \brief Interface for a sorcery object type wizards */</span><br><span>@@ -812,26 +815,27 @@</span><br><span> return res;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/*! \brief Internal function which creates an object type and inserts a wizard mapping */</span><br><span style="color: hsl(0, 100%, 40%);">-enum ast_sorcery_apply_result __ast_sorcery_insert_wizard_mapping(struct ast_sorcery *sorcery,</span><br><span style="color: hsl(0, 100%, 40%);">- const char *type, const char *module, const char *name, const char *data,</span><br><span style="color: hsl(0, 100%, 40%);">- unsigned int caching, int position)</span><br><span style="color: hsl(120, 100%, 40%);">+enum ast_sorcery_apply_result __ast_sorcery_object_type_insert_wizard(struct ast_sorcery *sorcery,</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *object_type_name, const char *module, const char *wizard_name,</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *wizard_args, unsigned int caching, unsigned int read_only, int position,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sorcery_wizard **wizard, void **wizard_data)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup);</span><br><span style="color: hsl(0, 100%, 40%);">- RAII_VAR(struct ast_sorcery_internal_wizard *, wizard, ao2_find(wizards, name, OBJ_KEY), ao2_cleanup);</span><br><span style="color: hsl(120, 100%, 40%);">+ RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, object_type_name, OBJ_KEY), ao2_cleanup);</span><br><span style="color: hsl(120, 100%, 40%);">+ RAII_VAR(struct ast_sorcery_internal_wizard *, internal_wizard, ao2_find(wizards, wizard_name, OBJ_KEY), ao2_cleanup);</span><br><span> RAII_VAR(struct ast_sorcery_object_wizard *, object_wizard, ao2_alloc(sizeof(*object_wizard), sorcery_object_wizard_destructor), ao2_cleanup);</span><br><span> int created = 0;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (!wizard) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "Wizard '%s' could not be applied to object type '%s' as it was not found\n",</span><br><span style="color: hsl(0, 100%, 40%);">- name, type);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!internal_wizard) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">+ "Wizard '%s' could not be applied to object type '%s' as it was not found\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ wizard_name, object_type_name);</span><br><span> return AST_SORCERY_APPLY_FAIL;</span><br><span> } else if (!object_wizard) {</span><br><span> return AST_SORCERY_APPLY_FAIL;</span><br><span> }</span><br><span> </span><br><span> if (!object_type) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(object_type = sorcery_object_type_alloc(type, module))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(object_type = sorcery_object_type_alloc(object_type_name, module))) {</span><br><span> return AST_SORCERY_APPLY_FAIL;</span><br><span> }</span><br><span> created = 1;</span><br><span>@@ -842,29 +846,35 @@</span><br><span> struct ast_sorcery_object_wizard *found;</span><br><span> </span><br><span> #define WIZARD_COMPARE(a, b) ((a)->wizard == (b))</span><br><span style="color: hsl(0, 100%, 40%);">- found = AST_VECTOR_GET_CMP(&object_type->wizards, wizard, WIZARD_COMPARE);</span><br><span style="color: hsl(120, 100%, 40%);">+ found = AST_VECTOR_GET_CMP(&object_type->wizards, internal_wizard, WIZARD_COMPARE);</span><br><span> #undef WIZARD_COMPARE</span><br><span style="color: hsl(0, 100%, 40%);">- if (found) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * We will allow multiple memory wizards because they typically</span><br><span style="color: hsl(120, 100%, 40%);">+ * are written to only by the backend implementer and are</span><br><span style="color: hsl(120, 100%, 40%);">+ * usually inserted at the end of the wizard vector.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (found && strcmp("memory", wizard_name)) {</span><br><span> ast_debug(1, "Wizard %s already applied to object type %s\n",</span><br><span style="color: hsl(0, 100%, 40%);">- wizard->callbacks.name, object_type->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ internal_wizard->callbacks.name, object_type->name);</span><br><span> AST_VECTOR_RW_UNLOCK(&object_type->wizards);</span><br><span> return AST_SORCERY_APPLY_DUPLICATE;</span><br><span> }</span><br><span> }</span><br><span> </span><br><span> ast_debug(5, "Calling wizard %s open callback on object type %s\n",</span><br><span style="color: hsl(0, 100%, 40%);">- name, object_type->name);</span><br><span style="color: hsl(0, 100%, 40%);">- if (wizard->callbacks.open && !(object_wizard->data = wizard->callbacks.open(data))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ wizard_name, object_type->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (internal_wizard->callbacks.open && !(object_wizard->data = internal_wizard->callbacks.open(wizard_args))) {</span><br><span> ast_log(LOG_WARNING, "Wizard '%s' failed to open mapping for object type '%s' with data: %s\n",</span><br><span style="color: hsl(0, 100%, 40%);">- name, object_type->name, S_OR(data, ""));</span><br><span style="color: hsl(120, 100%, 40%);">+ wizard_name, object_type->name, S_OR(wizard_args, ""));</span><br><span> AST_VECTOR_RW_UNLOCK(&object_type->wizards);</span><br><span> return AST_SORCERY_APPLY_FAIL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_module_ref(wizard->callbacks.module);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_module_ref(internal_wizard->callbacks.module);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- object_wizard->wizard = ao2_bump(wizard);</span><br><span style="color: hsl(120, 100%, 40%);">+ object_wizard->wizard = ao2_bump(internal_wizard);</span><br><span> object_wizard->caching = caching;</span><br><span style="color: hsl(120, 100%, 40%);">+ object_wizard->read_only = read_only;</span><br><span> </span><br><span> if (position == AST_SORCERY_WIZARD_POSITION_LAST) {</span><br><span> position = AST_VECTOR_SIZE(&object_type->wizards);</span><br><span>@@ -882,11 +892,28 @@</span><br><span> }</span><br><span> </span><br><span> NOTIFY_INSTANCE_OBSERVERS(sorcery->observers, wizard_mapped,</span><br><span style="color: hsl(0, 100%, 40%);">- sorcery->module_name, sorcery, type, &wizard->callbacks, data, object_wizard->data);</span><br><span style="color: hsl(120, 100%, 40%);">+ sorcery->module_name, sorcery, object_type_name, &internal_wizard->callbacks, wizard_args,</span><br><span style="color: hsl(120, 100%, 40%);">+ object_wizard->data);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (wizard) {</span><br><span style="color: hsl(120, 100%, 40%);">+ *wizard = &internal_wizard->callbacks;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (wizard_data) {</span><br><span style="color: hsl(120, 100%, 40%);">+ *wizard_data = object_wizard->data;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> return AST_SORCERY_APPLY_SUCCESS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief Internal function which creates an object type and inserts a wizard mapping */</span><br><span style="color: hsl(120, 100%, 40%);">+enum ast_sorcery_apply_result __ast_sorcery_insert_wizard_mapping(struct ast_sorcery *sorcery,</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *type, const char *module, const char *name, const char *data,</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int caching, int position)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return __ast_sorcery_object_type_insert_wizard(sorcery, type, module, name,</span><br><span style="color: hsl(120, 100%, 40%);">+ data, caching, 0, position, NULL, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! \brief Internal function which creates an object type and adds a wizard mapping */</span><br><span> enum ast_sorcery_apply_result __ast_sorcery_apply_wizard_mapping(struct ast_sorcery *sorcery,</span><br><span> const char *type, const char *module, const char *name, const char *data, unsigned int caching)</span><br><span>@@ -1873,7 +1900,7 @@</span><br><span> /*! \brief Internal function which returns if the wizard has created the object */</span><br><span> static int sorcery_wizard_create(const struct ast_sorcery_object_wizard *object_wizard, const struct sorcery_details *details)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!object_wizard->wizard->callbacks.create) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!object_wizard->wizard->callbacks.create || object_wizard->read_only) {</span><br><span> ast_debug(5, "Sorcery wizard '%s' does not support creation\n", object_wizard->wizard->callbacks.name);</span><br><span> return 0;</span><br><span> }</span><br><span>@@ -1984,7 +2011,7 @@</span><br><span> /*! \brief Internal function which returns if a wizard has updated the object */</span><br><span> static int sorcery_wizard_update(const struct ast_sorcery_object_wizard *object_wizard, const struct sorcery_details *details)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!object_wizard->wizard->callbacks.update) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!object_wizard->wizard->callbacks.update || object_wizard->read_only) {</span><br><span> ast_debug(5, "Sorcery wizard '%s' does not support updating\n", object_wizard->wizard->callbacks.name);</span><br><span> return 0;</span><br><span> }</span><br><span>@@ -2072,7 +2099,7 @@</span><br><span> /*! \brief Internal function which returns if a wizard has deleted the object */</span><br><span> static int sorcery_wizard_delete(const struct ast_sorcery_object_wizard *object_wizard, const struct sorcery_details *details)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!object_wizard->wizard->callbacks.delete) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!object_wizard->wizard->callbacks.delete || object_wizard->read_only) {</span><br><span> ast_debug(5, "Sorcery wizard '%s' does not support deletion\n", object_wizard->wizard->callbacks.name);</span><br><span> return 0;</span><br><span> }</span><br><span>diff --git a/tests/test_sorcery.c b/tests/test_sorcery.c</span><br><span>index 521d6e8..0c6dfa2 100644</span><br><span>--- a/tests/test_sorcery.c</span><br><span>+++ b/tests/test_sorcery.c</span><br><span>@@ -3468,6 +3468,73 @@</span><br><span> return AST_TEST_PASS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_sorcery_wizard test_read_only_wizard = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .name = "test-read-only",</span><br><span style="color: hsl(120, 100%, 40%);">+ .retrieve_id = sorcery_test_retrieve_id,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+AST_TEST_DEFINE(wizard_read_only)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ RAII_VAR(struct ast_sorcery *, sorcery, NULL, ast_sorcery_unref);</span><br><span style="color: hsl(120, 100%, 40%);">+ RAII_VAR(struct ast_sorcery_wizard *, wizard_read_only, &test_read_only_wizard, ast_sorcery_wizard_unregister);</span><br><span style="color: hsl(120, 100%, 40%);">+ RAII_VAR(struct ast_sorcery_wizard *, wizard1, &test_wizard, ast_sorcery_wizard_unregister);</span><br><span style="color: hsl(120, 100%, 40%);">+ RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sorcery_wizard *wizard;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case TEST_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+ info->name = "wizard_read_only";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->category = "/main/sorcery/";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->summary = "sorcery wizard read-only test";</span><br><span style="color: hsl(120, 100%, 40%);">+ info->description =</span><br><span style="color: hsl(120, 100%, 40%);">+ "sorcery wizard read-only test";</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_NOT_RUN;</span><br><span style="color: hsl(120, 100%, 40%);">+ case TEST_EXECUTE:</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ wizard1->load = sorcery_test_load;</span><br><span style="color: hsl(120, 100%, 40%);">+ wizard1->reload = sorcery_test_load;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(sorcery = ast_sorcery_open())) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_status_update(test, "Failed to open a sorcery instance\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_FAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_wizard_register(wizard_read_only);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_wizard_register(wizard1);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((ast_sorcery_apply_default(sorcery, "test_object_type", "test-read-only", NULL) != AST_SORCERY_APPLY_SUCCESS) ||</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_internal_object_register(sorcery, "test_object_type", test_sorcery_object_alloc, NULL, NULL)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_status_update(test, "Failed to apply object defaults\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_FAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_get_wizard_mapping_count(sorcery, "test_object_type") == 1);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_object_type_apply_wizard(sorcery, "test_object_type",</span><br><span style="color: hsl(120, 100%, 40%);">+ "test", "test2data", 0, 1, &wizard, NULL) == 0);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test, strcmp(wizard->name, wizard1->name) == 0);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_validate(test,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_get_wizard_mapping_count(sorcery, "test_object_type") == 2);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(obj = ast_sorcery_alloc(sorcery, "test_object_type", "blah"))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_status_update(test, "Failed to allocate a known object type\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_FAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sorcery_create(sorcery, obj) == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_test_status_update(test, "Should not have created object using read-only wizard\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_FAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_TEST_PASS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int unload_module(void)</span><br><span> {</span><br><span> AST_TEST_UNREGISTER(wizard_registration);</span><br><span>@@ -3519,6 +3586,7 @@</span><br><span> AST_TEST_UNREGISTER(instance_observation);</span><br><span> AST_TEST_UNREGISTER(wizard_observation);</span><br><span> AST_TEST_UNREGISTER(wizard_apply_and_insert);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TEST_UNREGISTER(wizard_read_only);</span><br><span> </span><br><span> return 0;</span><br><span> }</span><br><span>@@ -3574,6 +3642,7 @@</span><br><span> AST_TEST_REGISTER(global_observation);</span><br><span> AST_TEST_REGISTER(instance_observation);</span><br><span> AST_TEST_REGISTER(wizard_observation);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TEST_REGISTER(wizard_read_only);</span><br><span> </span><br><span> return AST_MODULE_LOAD_SUCCESS;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/11154">change 11154</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/11154"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I40f35840252e4313d99e11dbd80e270a3aa10605 </div>
<div style="display:none"> Gerrit-Change-Number: 11154 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>