We’re experimenting with replacing some of the HINT functionality with “Custom” Device States.
It’s working great, however, I’m at a loss on how to set an initial state without the end-user having to place a call to invoke the DEVICE_STATE() function.
Is there a way to pre-set the Custom Device State to “NOT_INUSE”?
Thanks for the reply @BlazeStudios, I know how to do it manually, was wondering if I’m just overlooking a way to have a device state NOT_INUSE instead of UNKNOWN by default (so I don’t have to do it manually).
I think the reason there might not be a way to do this is that’s basically just making something up that can’t be verified. How do we actually know that all devices are not in use, as opposed to unavailable? If I powered off a bunch of SIP devices and restarted Asterisk, it would be wrong to deem them “not in use” initially. If there were such a capability, it seems like it would make it easy to mess up the correctness of device state and hence messing up other things internally.
Typically channel drivers will update the device state as they are able. I’ve noticed myself though that this can take arduously long. It certainly would be good to be able to speed this process up a bit, but that could be a channel driver issue as opposed to a device state issue.
Hacking around in devicestate.c (18.14.0) I can change the following to get the default device state to “NOT_INUSE”.
Wondering if this is a reasonable way to handle this, as my requirement is for all “UNKNOWN” device states to be treated as “NOT_INUSE”.
Not knowing what this may impact makes me hesitant to put this into production without someone who knows this subsystem’s blessing, any advice appreciated!
enum ast_device_state ast_devstate_val(const char *val)
{
if (!strcasecmp(val, "NOT_INUSE"))
return AST_DEVICE_NOT_INUSE;
else if (!strcasecmp(val, "INUSE"))
return AST_DEVICE_INUSE;
else if (!strcasecmp(val, "BUSY"))
return AST_DEVICE_BUSY;
else if (!strcasecmp(val, "INVALID"))
return AST_DEVICE_INVALID;
else if (!strcasecmp(val, "UNAVAILABLE"))
return AST_DEVICE_UNAVAILABLE;
else if (!strcasecmp(val, "RINGING"))
return AST_DEVICE_RINGING;
else if (!strcasecmp(val, "RINGINUSE"))
return AST_DEVICE_RINGINUSE;
else if (!strcasecmp(val, "ONHOLD"))
return AST_DEVICE_ONHOLD;
return AST_DEVICE_NOT_INUSE; // MY CHANGE
// return AST_DEVICE_UNKNOWN;
}
My thought is this is still wrong, for the reason I mentioned.
This would apply to ALL device states, not just custom ones. This very well may cause things to not function right since you are effectively treating unknown as not in use.
I think a better (safer) approach would be to add code to simply update all custom device states to a value so you could do that with a single operation.