]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Slightly optimize ast_devstate_str and rename global functions devstate2str and confi...
authorTilghman Lesher <tilghman@meg.abyt.es>
Tue, 4 Nov 2008 18:47:20 +0000 (18:47 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Tue, 4 Nov 2008 18:47:20 +0000 (18:47 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@154260 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_page.c
apps/app_queue.c
apps/app_voicemail.c
include/asterisk/config.h
include/asterisk/devicestate.h
main/config.c
main/devicestate.c
main/features.c
main/manager.c

index 89559b1196f47051d0c4f372d28a080a84d48aff..ddebbf0ac8537597cc462fe051cba0b336b60c96 100644 (file)
@@ -178,9 +178,9 @@ static int page_exec(struct ast_channel *chan, void *data)
                if (ast_test_flag(&flags, PAGE_SKIP)) {
                        state = ast_device_state(tech);
                        if (state == AST_DEVICE_UNKNOWN) {
-                               ast_log(LOG_WARNING, "Destination '%s' has device state '%s'. Paging anyway.\n", tech, devstate2str(state));
+                               ast_log(LOG_WARNING, "Destination '%s' has device state '%s'. Paging anyway.\n", tech, ast_devstate2str(state));
                        } else if (state != AST_DEVICE_NOT_INUSE) {
-                               ast_log(LOG_WARNING, "Destination '%s' has device state '%s'.\n", tech, devstate2str(state));
+                               ast_log(LOG_WARNING, "Destination '%s' has device state '%s'.\n", tech, ast_devstate2str(state));
                                continue;
                        }
                }
index 81e82235533fb15d2f3553b3dabae13591999c7a..eef55f55b90a9cb65963fa3d4c52b69bdcfa8fc2 100644 (file)
@@ -1007,9 +1007,9 @@ static int handle_statechange(void *datap)
        }
 
        if (found)
-               ast_debug(1, "Device '%s' changed to state '%d' (%s)\n", sc->dev, sc->state, devstate2str(sc->state));
+               ast_debug(1, "Device '%s' changed to state '%d' (%s)\n", sc->dev, sc->state, ast_devstate2str(sc->state));
        else
-               ast_debug(3, "Device '%s' changed to state '%d' (%s) but we don't care because they're not a member of any queue.\n", sc->dev, sc->state, devstate2str(sc->state));
+               ast_debug(3, "Device '%s' changed to state '%d' (%s) but we don't care because they're not a member of any queue.\n", sc->dev, sc->state, ast_devstate2str(sc->state));
 
        ast_free(sc);
        return 0;
@@ -5692,7 +5692,7 @@ static char *__queues_show(struct mansession *s, int fd, int argc, char **argv)
                                        mem->dynamic ? " (dynamic)" : "",
                                        mem->realtime ? " (realtime)" : "",
                                        mem->paused ? " (paused)" : "",
-                                       devstate2str(mem->status));
+                                       ast_devstate2str(mem->status));
                                if (mem->calls)
                                        ast_str_append(&out, 0, " has taken %d calls (last was %ld secs ago)",
                                                mem->calls, (long) (time(NULL) - mem->lastcall));
index 3338de8ab0b90f4a6b3b9b7f9984961d3fd0a1a5..f888f3e67ee4a7a68363a5b4dc8078a7077ba722 100644 (file)
@@ -1177,7 +1177,7 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
                /* save the results */
                reset_user_pw(vmu->context, vmu->mailbox, newpassword);
                ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
-               config_text_file_save(VOICEMAIL_CONFIG, cfg, "AppVoicemail");
+               ast_config_text_file_save(VOICEMAIL_CONFIG, cfg, "AppVoicemail");
        }
        category = NULL;
        var = NULL;
@@ -1207,7 +1207,7 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
                /* save the results and clean things up */
                reset_user_pw(vmu->context, vmu->mailbox, newpassword); 
                ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
-               config_text_file_save("users.conf", cfg, "AppVoicemail");
+               ast_config_text_file_save("users.conf", cfg, "AppVoicemail");
        }
 }
 
@@ -5928,7 +5928,7 @@ static int vm_forwardoptions(struct ast_channel *chan, struct ast_vm_user *vmu,
                                msg_cat = ast_category_get(msg_cfg, "message");
                                snprintf(duration_buf, 11, "%ld", *duration);
                                if (!ast_variable_update(msg_cat, "duration", duration_buf, NULL, 0)) {
-                                       config_text_file_save(textfile, msg_cfg, "app_voicemail");
+                                       ast_config_text_file_save(textfile, msg_cfg, "app_voicemail");
                                }
                        }
 
index de42f25631226f9e4192113b5e339472a110e9a9..15157e2399de1a2307dead4db64e8ff3bc2c39eb 100644 (file)
@@ -388,7 +388,8 @@ int ast_variable_delete(struct ast_category *category, const char *variable, con
 int ast_variable_update(struct ast_category *category, const char *variable, 
                                                const char *value, const char *match, unsigned int object);
 
-int config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator);
+int ast_config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator);
+int config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator) __attribute__ ((deprecated));
 
 struct ast_config *ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked);
 
index b202d02a3b41ad018f08a4fb54c6f77ac183a323..bacf5464826956c8fd458bc057ac840a4eeb5130 100644 (file)
@@ -73,14 +73,15 @@ enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate);
  *
  * \param devstate Current device state 
  */
-const char *devstate2str(enum ast_device_state devstate);
+const char *devstate2str(enum ast_device_state devstate) attribute_pure __attribute__ ((deprecated));
+const char *ast_devstate2str(enum ast_device_state devstate) attribute_pure;
 
 /*! 
  * \brief Convert device state to text string that is easier to parse 
  *
  * \param devstate Current device state 
  */
-const char *ast_devstate_str(enum ast_device_state devstate);
+const char *ast_devstate_str(enum ast_device_state devstate) attribute_pure;
 
 /*! 
  * \brief Convert device state from text to integer value
index b3abe27301220145907bd1a4ab81da543433d728..c4d6e6f315e358d640bb9c84bb6d24a3523dfde5 100644 (file)
@@ -1559,6 +1559,11 @@ static void insert_leading_blank_lines(FILE *fp, struct inclfile *fi, struct ast
 }
 
 int config_text_file_save(const char *configfile, const struct ast_config *cfg, const char *generator)
+{
+       return ast_config_text_file_save(configfile, cfg, generator);
+}
+
+int ast_config_text_file_save(const char *configfile, const struct ast_config *cfg, const char *generator)
 {
        FILE *f;
        char fn[256];
index 1601ee12c37fa9e6917bba3840dfaa63bd81c50e..ca739cdfeea9f62686b324b7168251db33fe4738 100644 (file)
@@ -128,16 +128,16 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/event.h"
 
 /*! \brief Device state strings for printing */
-static const char *devstatestring[] = {
-       /* 0 AST_DEVICE_UNKNOWN */      "Unknown",      /*!< Valid, but unknown state */
-       /* 1 AST_DEVICE_NOT_INUSE */    "Not in use",   /*!< Not used */
-       /* 2 AST_DEVICE IN USE */       "In use",       /*!< In use */
-       /* 3 AST_DEVICE_BUSY */         "Busy",         /*!< Busy */
-       /* 4 AST_DEVICE_INVALID */      "Invalid",      /*!< Invalid - not known to Asterisk */
-       /* 5 AST_DEVICE_UNAVAILABLE */  "Unavailable",  /*!< Unavailable (not registred) */
-       /* 6 AST_DEVICE_RINGING */      "Ringing",      /*!< Ring, ring, ring */
-       /* 7 AST_DEVICE_RINGINUSE */    "Ring+Inuse",   /*!< Ring and in use */
-       /* 8 AST_DEVICE_ONHOLD */       "On Hold"       /*!< On Hold */
+static const char *devstatestring[][2] = {
+       { /* 0 AST_DEVICE_UNKNOWN */     "Unknown",     "UNKNOWN"     }, /*!< Valid, but unknown state */
+       { /* 1 AST_DEVICE_NOT_INUSE */   "Not in use",  "NOT_INUSE"   }, /*!< Not used */
+       { /* 2 AST_DEVICE IN USE */      "In use",      "INUSE"       }, /*!< In use */
+       { /* 3 AST_DEVICE_BUSY */        "Busy",        "BUSY"        }, /*!< Busy */
+       { /* 4 AST_DEVICE_INVALID */     "Invalid",     "INVALID"     }, /*!< Invalid - not known to Asterisk */
+       { /* 5 AST_DEVICE_UNAVAILABLE */ "Unavailable", "UNAVAILABLE" }, /*!< Unavailable (not registered) */
+       { /* 6 AST_DEVICE_RINGING */     "Ringing",     "RINGING"     }, /*!< Ring, ring, ring */
+       { /* 7 AST_DEVICE_RINGINUSE */   "Ring+Inuse",  "RINGINUSE"   }, /*!< Ring and in use */
+       { /* 8 AST_DEVICE_ONHOLD */      "On Hold"      "ONHOLD"      }, /*!< On Hold */
 };
 
 /*!\brief Mapping for channel states to device states */
@@ -204,9 +204,15 @@ struct {
 static int getproviderstate(const char *provider, const char *address);
 
 /*! \brief Find devicestate as text message for output */
+const char *ast_devstate2str(enum ast_device_state devstate) 
+{
+       return devstatestring[devstate][0];
+}
+
+/* Deprecated interface (not prefixed with ast_) */
 const char *devstate2str(enum ast_device_state devstate) 
 {
-       return devstatestring[devstate];
+       return devstatestring[devstate][0];
 }
 
 enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate)
@@ -221,40 +227,10 @@ enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate)
        return AST_DEVICE_UNKNOWN;
 }
 
+/* Parseable */
 const char *ast_devstate_str(enum ast_device_state state)
 {
-       const char *res = "UNKNOWN";
-
-       switch (state) {
-       case AST_DEVICE_UNKNOWN:
-               break;
-       case AST_DEVICE_NOT_INUSE:
-               res = "NOT_INUSE";
-               break;
-       case AST_DEVICE_INUSE:
-               res = "INUSE";
-               break;
-       case AST_DEVICE_BUSY:
-               res = "BUSY";
-               break;
-       case AST_DEVICE_INVALID:
-               res = "INVALID";
-               break;
-       case AST_DEVICE_UNAVAILABLE:
-               res = "UNAVAILABLE";
-               break;
-       case AST_DEVICE_RINGING:
-               res = "RINGING";
-               break;
-       case AST_DEVICE_RINGINUSE:
-               res = "RINGINUSE";
-               break;
-       case AST_DEVICE_ONHOLD:
-               res = "ONHOLD";
-               break;
-       }
-
-       return res;
+       return devstatestring[state][1];
 }
 
 enum ast_device_state ast_devstate_val(const char *val)
@@ -478,7 +454,7 @@ static void do_state_change(const char *device)
 
        state = _ast_device_state(device, 0);
 
-       ast_debug(3, "Changing state for %s - state %d (%s)\n", device, state, devstate2str(state));
+       ast_debug(3, "Changing state for %s - state %d (%s)\n", device, state, ast_devstate2str(state));
 
        devstate_event(device, state);
 }
@@ -623,7 +599,7 @@ static void process_collection(const char *device, struct change_collection *col
 
        for (i = 0; i < collection->num_states; i++) {
                ast_debug(1, "Adding per-server state of '%s' for '%s'\n", 
-                       devstate2str(collection->states[i].state), device);
+                       ast_devstate2str(collection->states[i].state), device);
                ast_devstate_aggregate_add(&agg, collection->states[i].state);
        }
 
@@ -645,13 +621,13 @@ static void process_collection(const char *device, struct change_collection *col
                if (state == old_state) {
                        /* No change since last reported device state */
                        ast_debug(1, "Aggregate state for device '%s' has not changed from '%s'\n",
-                               device, devstate2str(state));
+                               device, ast_devstate2str(state));
                        return;
                }
        }
 
        ast_debug(1, "Aggregate state for device '%s' has changed to '%s'\n",
-               device, devstate2str(state));
+               device, ast_devstate2str(state));
 
        event = ast_event_new(AST_EVENT_DEVICE_STATE,
                AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, device,
index adf5086aac2870cdb09d1e3819b6b44c47a8b7ce..cc43fad68232a3071f5150bae985bd72eba741de 100644 (file)
@@ -459,7 +459,7 @@ static const char *findparkinglotname(struct ast_channel *chan)
 static void notify_metermaids(const char *exten, char *context, enum ast_device_state state)
 {
        ast_debug(4, "Notification of state change to metermaids %s@%s\n to state '%s'", 
-               exten, context, devstate2str(state));
+               exten, context, ast_devstate2str(state));
 
        ast_devstate_changed(state, "park:%s@%s", exten, context);
 }
index e7fd926f0e0a9a700a9b9500a2a8d9ad27cc6c34..8f49173092b3458f14f5a75181978656e8a33e51 100644 (file)
@@ -1452,7 +1452,7 @@ static int action_updateconfig(struct mansession *s, const struct message *m)
        result = handle_updates(s, m, cfg, dfn);
        if (!result) {
                ast_include_rename(cfg, sfn, dfn); /* change the include references from dfn to sfn, so things match up */
-               res = config_text_file_save(dfn, cfg, "Manager");
+               res = ast_config_text_file_save(dfn, cfg, "Manager");
                ast_config_destroy(cfg);
                if (res) {
                        astman_send_error(s, m, "Save of config failed");