summaryrefslogtreecommitdiff
path: root/include/gammu-smsd.h
blob: eed56892566f3647b482bfcb0cfbfe10638dd9fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
 * \file gammu-smsd.h
 * \author Michal Čihař
 *
 * SMSD interaction
 */
#ifndef __gammu_smsd_h
#define __gammu_smsd_h

#ifdef	__cplusplus
extern "C" {
#endif

#include <gammu-error.h>
#include <gammu-message.h>
#include <gammu-misc.h>

/**
 * \defgroup SMSD SMSD
 * SMS daemon manipulations
 */

/**
 * SMSD configuration data, these are not expected to be manipulated
 * directly by application.
 *
 * \ingroup SMSD
 */
typedef struct _GSM_SMSDConfig GSM_SMSDConfig;

/**
 * Length of texts in GSM_SMSDStatus structure.
 */
#define SMSD_TEXT_LENGTH 255

/**
 * Status structure, which can be found in shared memory (if supported
 * on platform).
 *
 * \ingroup SMSD
 */
typedef struct {
	/**
	 * Version of this structure (1 for now).
	 */
	int Version;
	/**
	 * PhoneID from configuration.
	 */
	char PhoneID[SMSD_TEXT_LENGTH + 1];
	/**
	 * Client software name.
	 */
	char Client[SMSD_TEXT_LENGTH + 1];
	/**
	 * Current phone battery state.
	 */
	GSM_BatteryCharge Charge;
	/**
	 * Current network state.
	 */
	GSM_SignalQuality Network;
	/**
	 * Number of received messages.
	 */
	int Received;
	/**
	 * Number of sent messages.
	 */
	int Sent;
	/**
	 * Number of messages which failed to be send.
	 */
	int Failed;
	/**
	 * Phone IMEI.
	 */
	char IMEI[GSM_MAX_IMEI_LENGTH + 1];
} GSM_SMSDStatus;

/**
 * Enqueues SMS message in SMS daemon queue.
 *
 * \param Config SMSD configuration pointer.
 * \param sms Message data to send.
 * \param NewID Pointer to string where ID of new message will be
 * written. Can be NULL and then it is ignored.
 *
 * \return Error code
 *
 * \ingroup SMSD
 */
GSM_Error SMSD_InjectSMS(GSM_SMSDConfig * Config, GSM_MultiSMSMessage * sms, char *NewID);

/**
 * Gets SMSD status via shared memory.
 *
 * \param Config SMSD configuration pointer.
 * \param status pointer where status will be copied
 *
 * \return Error code
 *
 * \ingroup SMSD
 */
GSM_Error SMSD_GetStatus(GSM_SMSDConfig * Config, GSM_SMSDStatus * status);

/**
 * Flags SMSD daemon to terminate itself gracefully.
 *
 * \param Config Pointer to SMSD configuration data.
 *
 * \return Error code
 *
 * \ingroup SMSD
 */
GSM_Error SMSD_Shutdown(GSM_SMSDConfig * Config);

/**
 * Reads SMSD configuration.
 *
 * \param filename File name of configuration.
 * \param Config Pointer to SMSD configuration data.
 * \param uselog Whether to log errors to configured log.
 *
 * \return Error code
 *
 * \ingroup SMSD
 */
GSM_Error SMSD_ReadConfig(const char *filename, GSM_SMSDConfig * Config,
			  gboolean uselog);

/**
 * Forces using global debug for smsd.
 *
 * This should be used only in case SMSD is not used in a library.
 */
void SMSD_EnableGlobalDebug(GSM_SMSDConfig *Config);

/**
 * Main SMS daemon loop. It connects to phone, scans for messages and
 * sends messages from inbox. Can be interrupted by SMSD_Shutdown.
 *
 * \see SMSD_Shutdown
 *
 * \param Config Pointer to SMSD configuration data.
 * \param exit_on_failure Whether failure should lead to terminaton of
 * program.
 * \param max_failures Maximal number of failures after which SMSD will
 * terminate. Use 0 to not terminate on failures.
 *
 * \return Error code
 *
 * \ingroup SMSD
 */
GSM_Error SMSD_MainLoop(GSM_SMSDConfig * Config, gboolean exit_on_failure, int max_failures);

/**
 * Creates new SMSD configuration.
 *
 * \param name Name of process, will be used for logging. If NULL,
 * gammu-smsd text is used.
 *
 * \return Pointer to SMSD configuration data block.
 *
 * \ingroup SMSD
 */
GSM_SMSDConfig *SMSD_NewConfig(const char *name);

/**
 * Frees SMSD configuration.
 *
 * \param config Pointer to SMSD configuration data.
 *
 * \ingroup SMSD
 */
void SMSD_FreeConfig(GSM_SMSDConfig * config);
#ifdef	__cplusplus
}
#endif
#endif

/* Editor configuration
 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72:
 */