/** * @name gammu_create: */ gammu_state_t *gammu_create(const char *config_path) { gammu_state_t *s = allocate(sizeof(*s)); INI_Section *ini; GSM_InitLocales(NULL); if ((s->err = GSM_FindGammuRC(&ini, config_path)) != ERR_NONE) { goto cleanup; } s->sm = GSM_AllocStateMachine(); GSM_Config *cfg = GSM_GetConfig(s->sm, 0); if ((s->err = GSM_ReadConfig(ini, cfg, 0)) != ERR_NONE) { goto cleanup_state; } INI_Free(ini); GSM_SetConfigNum(s->sm, 1); if ((s->err = GSM_InitConnection(s->sm, 1)) != ERR_NONE) { goto cleanup_state; } /* Success */ return s; cleanup_state: GSM_FreeStateMachine(s->sm); cleanup: free(s); return NULL; }
void single_check(const char *device, const char *connection, const char *model, GSM_Error expected) { GSM_Config *smcfg; GSM_Error error; GSM_Debug_Info *debug_info; /* Allocates state machine */ s = GSM_AllocStateMachine(); test_result(s != NULL); debug_info = GSM_GetDebug(s); GSM_SetDebugGlobal(TRUE, debug_info); smcfg = GSM_GetConfig(s, 0); strcpy(smcfg->Model, model); smcfg->Device = strdup(device); smcfg->UseGlobalDebugFile = TRUE; smcfg->Connection = strdup(connection); smcfg->PhoneFeatures[0] = F_PBK_ENCODENUMBER; smcfg->PhoneFeatures[1] = 0; GSM_SetConfigNum(s, 1); error = GSM_InitConnection(s, 1); test_result(error == expected); /* Free state machine */ GSM_FreeStateMachine(s); }
THREAD_RETURN SearchPhoneThread(void * arg) { int j; OneDeviceInfo *Info = arg; GSM_Error error; GSM_StateMachine *search_gsm; GSM_Config *smcfg; GSM_Config *globalcfg; /* Iterate over all connections */ for (j = 0; strlen(Info->Connections[j].Connection) != 0; j++) { /* Allocate state machine */ search_gsm = GSM_AllocStateMachine(); if (search_gsm == NULL) return THREAD_RETURN_VAL; /* Get configuration pointers */ smcfg = GSM_GetConfig(search_gsm, 0); globalcfg = GSM_GetConfig(gsm, 0); /* We share some configuration with global one */ smcfg->UseGlobalDebugFile = globalcfg->UseGlobalDebugFile; smcfg->DebugFile = strdup(globalcfg->DebugFile); strcpy(smcfg->DebugLevel, globalcfg->DebugLevel); /* Configure the tested state machine */ smcfg->Device = strdup(Info->Device); smcfg->Connection = strdup(Info->Connections[j].Connection); smcfg->SyncTime = FALSE; smcfg->Model[0] = 0; smcfg->LockDevice = FALSE; smcfg->StartInfo = FALSE; /* We have only one configured connection */ GSM_SetConfigNum(search_gsm, 1); /* Let's connect */ error = GSM_InitConnection(search_gsm, 1); printf(_("Connection \"%s\" on device \"%s\"\n"), Info->Connections[j].Connection, Info->Device); /* Did we succeed? Show info */ if (error == ERR_NONE) { SearchPrintPhoneInfo(search_gsm); } else { SearchPrintf("\t%s\n", GSM_ErrorString(error)); } if (error != ERR_DEVICEOPENERROR) { GSM_TerminateConnection(search_gsm); } if (error == ERR_DEVICEOPENERROR) break; /* Free allocated buffer */ GSM_FreeStateMachine(search_gsm); } return THREAD_RETURN_VAL; }