add gammu initialization code
This commit is contained in:
		
							
								
								
									
										32
									
								
								yasnd.c
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								yasnd.c
									
									
									
									
									
								
							| @@ -10,7 +10,7 @@ | ||||
| #include <signal.h> | ||||
| #include <string.h> | ||||
| #include <confuse.h> | ||||
| #include <gammu/gammu.h> | ||||
| #include <gammu.h> | ||||
|  | ||||
| // Debug verbosity | ||||
| #define DEBUG_BASE 1 | ||||
| @@ -26,6 +26,7 @@ cfg_t *cfg; // pointer to configuration structure | ||||
| host_decl* hosts=NULL; // structure with hosts' definitions | ||||
| int hosts_count=0; // count of hosts | ||||
| int debug_flag=0; | ||||
| GSM_StateMachine *state_machine=NULL; // structure to interact with mobile phones | ||||
|  | ||||
| void log_debug(const char *message,int verbosity) | ||||
| { | ||||
| @@ -48,6 +49,17 @@ void* allocate_memory(int bytes) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void check_gammu_error(GSM_Error err) | ||||
| { | ||||
| 	if (err == ERR_NONE) { | ||||
| 		return; | ||||
| 	} | ||||
| 	char tmp[150]; | ||||
| 	sprintf(tmp,"gammu failure: %s\n", GSM_ErrorString(err)); | ||||
| 	log_event(tmp); | ||||
| 	exit(EXIT_FAILURE); | ||||
| } | ||||
|  | ||||
| void init() | ||||
| { | ||||
| 	// Initialize config parsing library | ||||
| @@ -78,6 +90,22 @@ void init() | ||||
| 		hosts[i].hostname=cfg_getnstr(cfg,"hosts",i); | ||||
| 		hosts[i].fail_count=0; | ||||
| 	} | ||||
| 	// initialize gammu structures | ||||
| 	GSM_InitLocales(NULL); | ||||
| 	state_machine = GSM_AllocStateMachine(); | ||||
| 	// read gammu config | ||||
| 	INI_Section *gammu_cfg; | ||||
| 	GSM_Error error; | ||||
| 	/* Find it */ | ||||
| 	error = GSM_FindGammuRC(&gammu_cfg, NULL); | ||||
| 	check_gammu_error(error); | ||||
| 	/* Read it */ | ||||
| 	error = GSM_ReadConfig(gammu_cfg, GSM_GetConfig(state_machine, 0), 0); | ||||
| 	check_gammu_error(error); | ||||
| 	/* Free allocated memory */ | ||||
| 	INI_Free(gammu_cfg); | ||||
| 	/* We care only about first configuration */ | ||||
| 	GSM_SetConfigNum(state_machine, 1); | ||||
| } | ||||
|  | ||||
| void check_host(int num,host_decl* host) | ||||
| @@ -134,6 +162,8 @@ void termination_handler(int signum) | ||||
| 	closelog(); | ||||
| 	// free config structure | ||||
| 	cfg_free(cfg); | ||||
| 	// free gammu structure | ||||
| 	GSM_FreeStateMachine(state_machine); | ||||
| 	// free hosts structures memory | ||||
| 	if (hosts!=NULL) | ||||
| 		free(hosts); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user