res_ari: Add "module loaded" check to ari stubs
[asterisk/asterisk.git] / res / res_ari_sounds.c
index fe0692f..8d5928a 100644 (file)
@@ -209,19 +209,28 @@ static struct stasis_rest_handlers sounds = {
        .children = { &sounds_soundId, }
 };
 
+static int unload_module(void)
+{
+       ast_ari_remove_handler(&sounds);
+       stasis_app_unref();
+       return 0;
+}
+
 static int load_module(void)
 {
        int res = 0;
+
+       CHECK_ARI_MODULE_LOADED();
+
+
        stasis_app_ref();
        res |= ast_ari_add_handler(&sounds);
-       return res;
-}
+       if (res) {
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
+       }
 
-static int unload_module(void)
-{
-       ast_ari_remove_handler(&sounds);
-       stasis_app_unref();
-       return 0;
+       return AST_MODULE_LOAD_SUCCESS;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Sound resources",