Now automatically initialize the plug-in

This commit is contained in:
Pierre Pronchery 2014-08-28 03:36:15 +02:00
parent 070b77cf77
commit 1cf903eb45

View File

@ -57,8 +57,19 @@ static int _helper_trigger(Phone * phone, ModemEventType event);
/* phone_init */ /* phone_init */
static int _phone_init(Phone * phone, PhonePluginDefinition * plugind) static int _phone_init(Phone * phone, PhonePluginDefinition * plugind)
{ {
char const * homedir;
String * path;
if((phone->config = config_new()) == NULL) if((phone->config = config_new()) == NULL)
return -1; return -1;
if((homedir = g_getenv("HOME")) == NULL)
homedir = g_get_home_dir();
if((path = string_new_append(homedir, "/.phone", NULL)) != 0)
{
if(config_load(phone->config, path) != 0)
error_print(PROGNAME);
string_delete(path);
}
memset(&phone->helper, 0, sizeof(phone->helper)); memset(&phone->helper, 0, sizeof(phone->helper));
phone->helper.phone = phone; phone->helper.phone = phone;
phone->helper.config_get = _helper_config_get; phone->helper.config_get = _helper_config_get;
@ -72,6 +83,11 @@ static int _phone_init(Phone * phone, PhonePluginDefinition * plugind)
phone->password = NULL; phone->password = NULL;
phone->fd = -1; phone->fd = -1;
phone->source = 0; phone->source = 0;
if((phone->plugin = plugind->init(&phone->helper)) == NULL)
{
_phone_destroy(phone);
return -1;
}
return 0; return 0;
} }