[asterisk-addons-commits] tilghman: trunk r483 - /trunk/chan_mobile.c
SVN commits to the Asterisk addons project
asterisk-addons-commits at lists.digium.com
Sun Nov 11 10:36:50 CST 2007
Author: tilghman
Date: Sun Nov 11 10:36:49 2007
New Revision: 483
URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=483
Log:
A few coding guidelines fixes:
- Extraneous tabs
- Change free() to ast_free()
- Change ast_malloc() to ast_calloc() where a large portion of parameters are subsequently initialized to 0.
- Remove reload_module() routine, as its existence suggests that the module can sustain a reload event (when in fact the reload did nothing).
Reported by: Laureano
Patch by: Laureano,tilghman
Closes issue #11213
Modified:
trunk/chan_mobile.c
Modified: trunk/chan_mobile.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/chan_mobile.c?view=diff&rev=483&r1=482&r2=483
==============================================================================
--- trunk/chan_mobile.c (original)
+++ trunk/chan_mobile.c Sun Nov 11 10:36:49 2007
@@ -144,7 +144,7 @@
int io_save_len;
int io_pipe[2];
int sco_socket; /* sco socket descriptor */
- pthread_t sco_listener_thread; /* inbound sco listener for this device */
+ pthread_t sco_listener_thread; /* inbound sco listener for this device */
enum mbl_state state; /* monitor thread current state */
pthread_t monitor_thread; /* monitor thread handle */
char dial_number[AST_MAX_EXTENSION]; /* number for the monitor thread to dial */
@@ -478,22 +478,22 @@
ast_log(LOG_ERROR,"Bluetooth device %s wasn't found in the list -- SMS will not be sent.\n", args.device);
return -1;
}
-
+
if (!pvt->connected) {
ast_log(LOG_ERROR,"Bluetooth device %s wasn't connected -- SMS will not be sent.\n", args.device);
return -1;
}
-
+
if (!pvt->has_sms) {
ast_log(LOG_ERROR,"Bluetooth device %s doesn't handle SMS -- SMS will not be sent.\n", args.device);
return -1;
}
-
+
if (pvt->state != MBL_STATE_IDLE) {
ast_log(LOG_ERROR,"Bluetooth device %s isn't IDLE -- SMS will not be sent.\n", args.device);
return -1;
}
-
+
ast_copy_string(pvt->dial_number, args.dest, sizeof(pvt->dial_number));
ast_copy_string(pvt->sms_txt, args.message, sizeof(pvt->sms_txt));
pvt->state = MBL_STATE_OUTSMS;
@@ -560,7 +560,7 @@
char *dest_dev = NULL;
char *dest_num = NULL;
int oldformat, group;
-
+
if (!data) {
ast_log(LOG_WARNING, "Channel requested with no data\n");
*cause = AST_CAUSE_INCOMPATIBLE_DESTINATION;
@@ -620,7 +620,7 @@
struct mbl_pvt *pvt;
char *dest_dev = NULL;
char *dest_num = NULL;
-
+
dest_dev = ast_strdupa((char *)dest);
pvt = ast->tech_pvt;
@@ -648,7 +648,7 @@
} else {
pvt->state = MBL_STATE_RING;
}
-
+
return 0;
}
@@ -657,7 +657,7 @@
{
struct mbl_pvt *pvt;
-
+
if (!ast->tech_pvt) {
ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
return 0;
@@ -696,7 +696,7 @@
{
struct mbl_pvt *pvt;
-
+
pvt = ast->tech_pvt;
rfcomm_write(pvt, "ATA\r");
@@ -721,7 +721,7 @@
struct mbl_pvt *pvt;
char buf[11];
-
+
pvt = ast->tech_pvt;
if (pvt->type == MBL_TYPE_HEADSET)
@@ -822,7 +822,7 @@
sco_write(pvt->io_pipe[1], buf, r);
}
}
-
+
num_frames = (frame->datalen - io_need) / DEVICE_FRAME_SIZE;
pfr = frame->data + io_need;
@@ -849,7 +849,7 @@
{
struct mbl_pvt *pvt = oldchan->tech_pvt;
-
+
if (pvt && pvt->owner == oldchan)
pvt->owner = newchan;
@@ -863,7 +863,7 @@
char *device;
int res = AST_DEVICE_INVALID;
struct mbl_pvt *pvt;
-
+
device = ast_strdupa(S_OR(data, ""));
ast_debug(1, "Checking device state for device %s\n", device);
@@ -962,7 +962,7 @@
struct sockaddr_rc addr;
int s;
-
+
if ((s = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) {
ast_debug(1, "socket() failed (%d).\n", errno);
return -1;
@@ -1092,7 +1092,7 @@
struct sockaddr_sco addr;
int s;
-
+
if ((s = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO)) < 0) {
ast_debug(1, "socket() failed (%d).\n", errno);
return -1;
@@ -1138,7 +1138,7 @@
ast_debug(2, "sco write error %d\n", errno);
return 0;
}
-
+
return 1;
}
@@ -1147,7 +1147,7 @@
{
int r;
-
+
if (s == -1) {
ast_debug(2, "sco_read() not ready\n");
return 0;
@@ -1162,7 +1162,7 @@
}
return r;
-
+
}
/*
@@ -1350,7 +1350,7 @@
group2++;
}
if (strstr(buf+i, "\"call\""))
- callp = group2;
+ callp = group2;
if (strstr(buf+i, "\"call_setup\""))
callsetupp = group2;
if (strstr(buf+i, "\"callsetup\""))
@@ -1635,13 +1635,13 @@
pvt->sco_socket = -1;
pvt->connected = 0;
pvt->monitor_thread = AST_PTHREADT_NULL;
-
+
pthread_cancel(pvt->sco_listener_thread);
pthread_join(pvt->sco_listener_thread, NULL);
pvt->sco_listener_thread = AST_PTHREADT_NULL;
-
+
close(pvt->adapter->sco_socket);
-
+
manager_event(EVENT_FLAG_SYSTEM, "MobileStatus", "Status: Disconnect\r\nDevice: %s\r\n", pvt->id);
pvt->adapter->inuse = 0;
@@ -1724,11 +1724,11 @@
pvt->sco_socket = -1;
pvt->connected = 0;
pvt->monitor_thread = AST_PTHREADT_NULL;
-
+
manager_event(EVENT_FLAG_SYSTEM, "MobileStatus", "Status: Disconnect\r\nDevice: %s\r\n", pvt->id);
pvt->adapter->inuse = 0;
-
+
return NULL;
}
@@ -1745,7 +1745,7 @@
if (ast_pthread_create_background(&pvt->sco_listener_thread, NULL, do_sco_listen, pvt->adapter) < 0) {
ast_log(LOG_ERROR, "Unable to create sco listener thread for device %s.\n", pvt->id);
}
-
+
} else {
if (ast_pthread_create_background(&pvt->monitor_thread, NULL, do_monitor_headset, pvt) < 0) {
pvt->monitor_thread = AST_PTHREADT_NULL;
@@ -1871,9 +1871,9 @@
struct mbl_pvt *pvt;
struct adapter_pvt *adapter;
uint16_t vs;
- struct hci_dev_req dr;
+ struct hci_dev_req dr;
char nadapters = 0;
- struct ast_flags config_flags = { 0 };
+ struct ast_flags config_flags = { 0 };
cfg = ast_config_load(MBL_CONFIG, config_flags);
if (!cfg)
@@ -1894,11 +1894,9 @@
aligndetect = ast_variable_retrieve(cfg, cat, "alignmentdetection");
ast_debug(1, "Loading adapter %s %s.\n", id, address);
if (!ast_strlen_zero(id) && !ast_strlen_zero(address)) {
- if ((adapter = ast_malloc(sizeof(struct adapter_pvt)))) {
+ if ((adapter = ast_calloc(1, sizeof(*adapter)))) {
ast_copy_string(adapter->id, id, sizeof(adapter->id));
str2ba(address, &adapter->addr);
- adapter->inuse = 0;
- adapter->alignment_detection = 0;
if (!ast_strlen_zero(aligndetect)) {
if (*aligndetect == 'Y' || *aligndetect == 'y')
adapter->alignment_detection = 1;
@@ -1906,8 +1904,8 @@
adapter->dev_id = hci_devid(address);
adapter->hci_socket = hci_open_dev(adapter->dev_id);
if (adapter->dev_id < 0 || adapter->hci_socket < 0) {
- ast_log(LOG_ERROR, "Unable to open adapter %s. It wont be enabled.\n", adapter->id);
- free(adapter);
+ ast_log(LOG_ERROR, "Unable to open adapter %s. It won't be enabled.\n", adapter->id);
+ ast_free(adapter);
} else {
if ((master) && (*master)) {
dr.dev_id = adapter->dev_id;
@@ -1922,7 +1920,7 @@
if (vs != 0x0060) {
ast_log(LOG_ERROR, "Incorrect voice setting for adapter %s, it must be 0x0060 - see 'man hciconfig' for details.\n", adapter->id);
hci_close_dev(adapter->hci_socket);
- free(adapter);
+ ast_free(adapter);
} else {
AST_LIST_INSERT_HEAD(&adapters, adapter, entry);
nadapters++;
@@ -1930,17 +1928,17 @@
}
}
} else
- ast_log(LOG_ERROR, "id/address missing for adapter %s. It wont be enabled.\n", cat);
- }
- cat = ast_category_browse(cfg, cat);
- }
-
+ ast_log(LOG_ERROR, "id/address missing for adapter %s. It won't be enabled.\n", cat);
+ }
+ cat = ast_category_browse(cfg, cat);
+ }
+
if (!nadapters) {
ast_log(LOG_WARNING, "***********************************************************************\n");
ast_log(LOG_WARNING, "No Adapters defined. Please review mobile.conf. See sample for details.\n");
ast_log(LOG_WARNING, "***********************************************************************\n");
}
-
+
/* now load devices */
cat = ast_category_browse(cfg, NULL);
while (cat) {
@@ -1961,10 +1959,10 @@
break;
}
if (!adapter) {
- ast_log(LOG_ERROR, "Device %s configured to use unknown adapter %s. It wont be enabled.\n", cat, useadapter);
+ ast_log(LOG_ERROR, "Device %s configured to use unknown adapter %s. It won't be enabled.\n", cat, useadapter);
break;
}
- if ((pvt = ast_malloc(sizeof(struct mbl_pvt)))) {
+ if ((pvt = ast_calloc(1, sizeof(*pvt)))) {
if (type && !strcmp(type, "headset"))
pvt->type = MBL_TYPE_HEADSET;
else
@@ -1974,39 +1972,31 @@
ast_copy_string(pvt->context, S_OR(context, "default"), sizeof(pvt->context));
if (group)
pvt->group = atoi(group); /* group 0 if invalid */
- else
- pvt->group = 0;
- pvt->connected = 0;
pvt->state = MBL_STATE_INIT;
pvt->rfcomm_socket = -1;
pvt->rfcomm_port = atoi(port);
- pvt->rfcomm_buf[0] = 0x00;
pvt->sco_socket = -1;
pvt->monitor_thread = AST_PTHREADT_NULL;
pvt->sco_listener_thread = AST_PTHREADT_NULL;
- pvt->owner = NULL;
- pvt->no_callsetup = 0;
if (!ast_strlen_zero(nocallsetup)) {
if ((*nocallsetup == 'y') || (*nocallsetup == 'Y')) {
pvt->no_callsetup = 1;
ast_debug(1, "Setting nocallsetup mode for device %s.\n", pvt->id);
}
}
- pvt->has_sms = 0;
pvt->dsp = ast_dsp_new();
if (skip) {
if ((pvt->dtmf_skip = atoi(skip)) == 0)
pvt->dtmf_skip = 200;
} else
pvt->dtmf_skip = 200;
- pvt->skip_frames = 0;
ast_dsp_set_features(pvt->dsp, DSP_FEATURE_DTMF_DETECT);
ast_dsp_digitmode(pvt->dsp, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF);
pvt->adapter = adapter;
AST_LIST_INSERT_HEAD(&devices, pvt, entry);
}
} else {
- ast_log(LOG_ERROR, "Device %s has no address/port/adapter configured. It wont be enabled.\n", cat);
+ ast_log(LOG_ERROR, "Device %s has no address/port/adapter configured. It won't be enabled.\n", cat);
}
}
cat = ast_category_browse(cfg, cat);
@@ -2015,13 +2005,6 @@
ast_config_destroy(cfg);
return 1;
-
-}
-
-static int reload_module(void)
-{
-
- return 0;
}
@@ -2039,7 +2022,7 @@
pthread_cancel(discovery_thread);
pthread_join(discovery_thread, NULL);
}
-
+
/* Destroy the device list */
while ((pvt = AST_LIST_REMOVE_HEAD(&devices, entry))) {
if (pvt->monitor_thread != AST_PTHREADT_NULL) {
@@ -2060,13 +2043,13 @@
close(pvt->rfcomm_socket);
}
ast_dsp_free(pvt->dsp);
- free(pvt);
- }
-
+ ast_free(pvt);
+ }
+
/* Destroy the adapter list */
while ((adapter = AST_LIST_REMOVE_HEAD(&adapters, entry))) {
hci_close_dev(adapter->hci_socket);
- free(adapter);
+ ast_free(adapter);
}
if (sdp_session)
@@ -2108,7 +2091,7 @@
ast_log(LOG_ERROR, "Unable to create discovery thread.\n");
return AST_MODULE_LOAD_DECLINE;
}
-
+
ast_cli_register_multiple(mbl_cli, sizeof(mbl_cli) / sizeof(mbl_cli[0]));
ast_register_application(app_mblstatus, mbl_status_exec, mblstatus_synopsis, mblstatus_desc);
ast_register_application(app_mblsendsms, mbl_sendsms_exec, mblsendsms_synopsis, mblsendsms_desc);
@@ -2125,5 +2108,4 @@
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Bluetooth Mobile Device Channel Driver",
.load = load_module,
.unload = unload_module,
- .reload = reload_module
);
More information about the asterisk-addons-commits
mailing list