summaryrefslogtreecommitdiff
path: root/include/alarm.h
blob: 3c5e29a801e1d725252b4fc4abe95c95f81ee78d (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
/*
 * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

/**
 * @open
 * @addtogroup APPLICATION_FRAMEWORK
 * @{
 *
 * @defgroup AlarmManager
 * @version 0.4.2
 *
 *
 * Alarm  supports APIs that add, delete, and update an alarm.
 * @n An application can use alarm APIs by including @c alarm.h. The definitions
 * of APIs are defined as follows:
 *
 * @li @c #alarmmgr_init initialize alarm library
 * @li @c #alarmmgr_set_cb set the callback for an alarm event
 * @li @c #alarmmgr_create_alarm create an alarm entry
 * @li @c #alarmmgr_free_alarm free an alarm entry
 * @li @c #alarmmgr_set_time set a time will be expired
 * @li @c #alarmmgr_get_time get a time will be expired
 * @li @c #alarmmgr_set_repeat_mode set repeat mode
 * @li @c #alarmmgr_get_repeat_mode get repeat mode
 * @li @c #alarmmgr_set_type set type
 * @li @c #alarmmgr_get_type get type
 * @li @c #alarmmgr_add_alarm_with_localtime add an alarm with localtime
 * @li @c #alarmmgr_add_alarm add an alarm
 * @li @c #alarmmgr_remove_alarm remove an alarm from alarm server
 * @li @c #alarmmgr_enum_alarm_ids get the list of alarm ids
 * @li @c #alarmmgr_get_info get the information of an alarm
 * @li @c #alarmmgr_fini de-initialize alarm library
 *
 *
 * The following code shows how to initialize alarm library, how to register the alarm handler, and how to add an alarm. It first calls alarm_init to initialize the alarm library and sets the callback to handle an alarm event it received. In create_test fucnction, the application add an alarm which will be expired in one minute from it execute and will expire everyday at same time.
 *
 *
 * @code
#include<stdio.h>
#include<stdlib.h>
#include<glib.h>

#include "alarm.h"

int callback(alarm_id_t alarm_id, void *user_param)
{
	int error;
	time_t current_time;
	time(&current_time);

	printf("Alarm[%d] has expired at %s\n", alarm_id, ctime(&current_time));
	return 0;
}

void create_test()
{
	time_t current_time;
	struct tm current_tm;
	alarm_entry_t* alarm_info;
	alarm_id_t alarm_id;
	int result;
	alarm_date_t test_time;

	time(&current_time);

	printf("current time: %s\n", ctime(&current_time));
	localtime_r(&current_time, &current_tm);

	alarm_info = alarmmgr_create_alarm();

	test_time.year = current_tm.tm_year+1900;
	test_time.month = current_tm.tm_mon+1;
	test_time.day = current_tm.tm_mday;
	test_time.hour = current_tm.tm_hour;
	test_time.min = current_tm.tm_min+1;
	test_time.sec = 0;

	alarmmgr_set_time(alarm_info,test_time);
	alarmmgr_set_repeat_mode(alarm_info,ALARM_REPEAT_MODE_WEEKLY,
	ALARM_WDAY_MONDAY| \
	ALARM_WDAY_TUESDAY|ALARM_WDAY_WEDNESDAY| \
	ALARM_WDAY_THURSDAY|ALARM_WDAY_FRIDAY );

	alarmmgr_set_type(alarm_info,ALARM_TYPE_VOLATILE);
	alarmmgr_add_alarm_with_localtime(alarm_info,NULL,&alarm_id);

	if(result != ALARMMGR_RESULT_SUCCESS)
		printf("fail to alarmmgr_create : error_code : %d\n",result);

}

int main(int argc, char** argv)
{
	int error_code;
	GMainLoop *mainloop;
	int result;
	g_type_init();

	mainloop = g_main_loop_new(NULL, FALSE);
	result = alarmmgr_init("org.tizen.test");

	if(result != ALARMMGR_RESULT_SUCCESS) {
		printf("fail to alarmmgr_init : error_code : %d\n",result);
	}
	else {
		result = alarmmgr_set_cb(callback,NULL);
		if(result != ALARMMGR_RESULT_SUCCESS) {
			printf("fail to alarmmgr_set_cb : error_code :
							%d\n",result);
		}
		else {
			create_test();
		}
	}
	g_main_loop_run(mainloop);
}

* @endcode
*
*/

/**
 * @addtogroup AlarmManager
 * @{
 */

#include <sys/types.h>
#include <stdbool.h>
#include <time.h>
#include <notification.h>
#include <gio/gio.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* Type of an alarm id
*/
typedef int alarm_id_t;
/**
* The prototype of alarm handler.
* param [in]	alarm_id the id of expired alarm
*/
typedef int (*alarm_set_time_cb_t) (int result, void *user_param);

typedef int (*alarm_cb_t) (alarm_id_t alarm_id, void *user_param);

typedef int (*alarm_enum_fn_t) (alarm_id_t alarm_id, void *user_param);

/**
* This enumeration has day of a week of alarm
*/
typedef enum {
	ALARM_WDAY_SUNDAY = 0x01, /**< enalbe alarm on Sunday*/
	ALARM_WDAY_MONDAY = 0x02, /**< enalbe alarm on Monday*/
	ALARM_WDAY_TUESDAY = 0x04, /**< enable alarm on Tuesday*/
	ALARM_WDAY_WEDNESDAY = 0x08, /**< enalbe alarm on Wednesday*/
	ALARM_WDAY_THURSDAY = 0x10, /**< enable alarm on Thursday*/
	ALARM_WDAY_FRIDAY = 0x20,  /**< enable alarm on Friday*/
	ALARM_WDAY_SATURDAY = 0x40,/**< enable alarm on Saturday*/
} alarm_day_of_week_t;

/**
* This enumeration has error codes of alarm
*/
	typedef enum {
		ERR_ALARM_NOT_PERMITTED_APP = -11,
		ERR_ALARM_INVALID_PARAM = -10,
				     /**<Invalid parameter*/
		ERR_ALARM_INVALID_ID,	/**<Invalid id*/
		ERR_ALARM_INVALID_REPEAT,
					/**<Invalid repeat mode*/
		ERR_ALARM_INVALID_TIME,	/**<Invalid time. */
		ERR_ALARM_INVALID_DATE,	/**<Invalid date. */
		ERR_ALARM_NO_SERVICE_NAME,
				    /**<there is no alarm service
					for this applicaation. */
		ERR_ALARM_INVALID_TYPE,  /*Invalid type*/
		ERR_ALARM_NO_PERMISSION, /*No permission*/
		ERR_ALARM_SYSTEM_FAIL = -1,
		ALARMMGR_RESULT_SUCCESS = 0,
	} alarm_error_t;

/**
*  This enumeration has repeat mode of alarm
*/
typedef enum {
	ALARM_REPEAT_MODE_ONCE = 0,	/**<once : the alarm will be expired
					only one time. */
	ALARM_REPEAT_MODE_REPEAT,	/**<repeat : the alarm will be expired
					repeatly*/
	ALARM_REPEAT_MODE_WEEKLY,	/**<weekly*/
	ALARM_REPEAT_MODE_MONTHLY,	/**< monthly*/
	ALARM_REPEAT_MODE_ANNUALLY,	/**< annually*/
	ALARM_REPEAT_MODE_MAX,
} alarm_repeat_mode_t;


typedef enum {
	QUANTUMIZE = 0,
	CUT_OFF,
} periodic_method_e;


#define ALARM_TYPE_DEFAULT	0x0	/*< non volatile */
#define ALARM_TYPE_VOLATILE	0x02	/*< volatile */
#define ALARM_TYPE_NOLAUNCH 0x04	/*<without launch */
#define ALARM_TYPE_INEXACT 0x08	/*<inexact alarm */
#define ALARM_TYPE_EXACT_SERVICE_APP 0x10	/*<exact alarm for in-house service app*/


/**
* This struct has date information
*/
typedef struct {
	int year;		/**< specifies the year */
	int month;		/**< specifies the month */
	int day;		/**< specifies the day */
	int hour;		/**< specifies the hour */
	int min;		/**< specifies the minute*/
	int sec;		/**< specifies the second*/
} alarm_date_t;

enum {
	ALARM_UPDATE_FLAG_TIME,
	ALARM_UPDATE_FLAG_PERIOD,
	ALARM_UPDATE_FLAG_WEEK,
	ALARM_UPDATE_FLAG_CLEAR_PERIOD,
	ALARM_UPDATE_FLAG_CLEAR_WEEK_FLAG,
};

typedef union {
	int day_of_week;			/**< days of a week */
	time_t interval;
} alarm_interval_u;

/**
* This struct has mode of an alarm
*/
typedef struct {
	alarm_interval_u u_interval;
	alarm_repeat_mode_t repeat;	/**< repeat mode */
} alarm_mode_t;

typedef struct {
	alarm_set_time_cb_t callback;
	void *user_data;
	GDBusProxy *proxy;
} alarm_set_time_data_t;

typedef struct {
	alarm_date_t start; /**< start time of the alarm */
	alarm_date_t end;   /**< end time of the alarm */
	alarm_mode_t mode;	/**< mode of alarm */
	int msec;
	int alarm_type;	    /**< alarm type*/
	time_t reserved_info;	/** 1st duetime(UTC epochtime) */
} alarm_info_t;

#define alarm_entry_t alarm_info_t

/**
 *
 * This function initializes alarm library. It connects to system bus and registers the application's service name.
 *
 * @param	[in]	pkg_name	a package of application
 *
 * @return On success, ALARMMGR_RESULT_SUCCESS is returned. On error, a negative number is returned
 *
 * @pre None.
 * @post None.
 * @see None.
 * @remark An application must call this function before using other alarm APIs.
 * @par Sample code:
 * @code
#include <alarm.h>

...
{
	int ret_val = ALARMMGR_RESULT_SUCCESS;
	const char* pkg_name = "org.tizen.test";

	g_type_init();

	ret_val =alarmmgr_init(pkg_name) ;
	if(ret_val == ALARMMGR_RESULT_SUCCESS)
	{
		 //alarmmgr_init() is successful
	}
	else
	{
		 //alarmmgr_init () failed
	}
}
 * @endcode
 */
int alarmmgr_init(const char *appid);

/**
 *
 * This function de-initializes alarm library. It un-registers the application's service name and dis-connects from system bus.
 *
 * @param       None
 *
 * @return	None
 *
 * @pre		Alarm manager is initialized
 * @post	Alarm manager is de-initialized
 * @remark An application must call this function once it is done with alarmmanger usage
 * @par Sample code:
 * @code
#include <alarm.h>

...
{
	// Initialize alarmmanager
	// Set alarm

	alarmmgr_fini() ;
}
 * @endcode
 */

void alarmmgr_fini();


/**
 * This function registers handler which handles an alarm event. An application should register the alarm handler
 * before it enters mainloop.
 *
 * @param	[in]	handler	Callback function
 * @param	[in]	user_param	User Parameter
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre alarmmgr_init().
 * @post None.
 * @see None.
 * @remark	An application can have only one alarm handler. If an application
 *          calls this function more than one times, the handler regitered during  the
 *          last call of this funiction will be called when an alarm event has occured.
 * @par Sample code:
 * @code
#include <alarm.h>
...

// Call back function
int callback(alarm_id_t alarm_id,void* user_param)
{
	time_t current_time;
	time(&current_time);

	printf("Alarm[%d] has expired at %s\n", alarm_id, ctime(&current_time));

	return 0;
}

...
{
	int ret_val = ALARMMGR_RESULT_SUCCESS;
	void *user_param = NULL;

	ret_val = alarmmgr_set_cb( callback, user_param);
	if(ret_val == ALARMMGR_RESULT_SUCCESS)
	{
		//alarmmgr_set_cb() is successful
	}
	else
	{
		 //alarmmgr_set_cb () failed
	}
}

 * @endcode
 */
int alarmmgr_set_cb(alarm_cb_t handler, void *user_param);


/**
 * This function creates a new alarm entry, will not be known to the server until alarmmgr_add_alarm is called.
 *
 * @return	This function returns the pointer of alarm_entry_t
 *
 * @pre None.
 * @post None.
 * @see None.
 * @remark	After an application use this object, an application free this pointer through alarmmgr_free_alarm
 *
 * @par Sample code:
 * @code
#include <alarm.h>

...
{
	alarm_entry_t* alarm;

	alarm = alarmmgr_create_alarm() ;
	if(alarm != NULL)
	{
		 //alarmmgr_create_alarm() is successful
	}
	else
	{
		 //alarmmgr_create_alarm () failed
	}
}


 * @endcode
 */
alarm_entry_t *alarmmgr_create_alarm(void);


/**
 * This function frees an alarm entry.
 *
 * @param	[in]	alarm	alarm entry
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see None.
 * @remark	None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

...
 {
	 int ret_val = ALARMMGR_RESULT_SUCCESS;
	 alarm_entry_t* alarm;

	 alarm = alarmmgr_create_alarm() ;
	 if(alarm == NULL)
	 {
		  //alarmmgr_create_alarm () failed
	 }
	 else
		 {

			 ret_val = alarmmgr_free_alarm( alarm) ;
			 if(ret_val == ALARMMGR_RESULT_SUCCESS)
			 {
				  //alarmmgr_free_alarm() is successful
			 }
			 else
			 {
				 //alarmmgr_free_alarm() failed
			 }
		 }
 }

 * @endcode
 */
int alarmmgr_free_alarm(alarm_entry_t *alarm);


/**
 * This function sets time that alarm should be expried.
 *
 * @param	[in]	alarm	alarm entry
 * @param	[in]	time		time the alarm should first go off
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see None.
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

 ...
  {
	  int ret_val = ALARMMGR_RESULT_SUCCESS;
	  alarm_entry_t* alarm;
	  time_t current_time;
	  struct tm current_tm;
	  alarm_date_t test_time;


	 time(&current_time);
	 localtime_r(&current_time, &current_tm);

	 alarm = alarmmgr_create_alarm();
	  if(alarm == NULL)
	  {
		   //alarmmgr_create_alarm () failed
	  }
	  else {
		test_time.year = current_tm.tm_year;
		test_time.month = current_tm.tm_mon;
		test_time.day = current_tm.tm_mday;

		test_time.hour = current_tm.tm_hour;
		test_time.min = current_tm.tm_min+1;
		test_time.sec = 0;

		ret_val=alarmmgr_set_time(alarm,test_time);
		if(ret_val == ALARMMGR_RESULT_SUCCESS)
		{
			//alarmmgr_set_time() is successful
		}
		else
		{
			//alarmmgr_set_time() failed
		}
			  alarmmgr_free_alarm( alarm) ;
	  }
 }

 * @endcode
 */
int alarmmgr_set_time(alarm_entry_t *alarm, alarm_date_t time);

/**
 * This function gives an application time that alarm should be expried.
 *
 * @param	[in]		alarm	alarm entry
 * @param	[out]	time		time the alarm should first go off
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see None.
 * @remark	But an application does not need to specify year, month, and day field of alarm_info. If an application sets
 *			those fields with zero, the function sets them with proper values.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

 ...
 {
	 int ret_val = ALARMMGR_RESULT_SUCCESS;
	 alarm_entry_t* alarm;

	 time_t current_time;
		struct tm current_tm;
	 alarm_date_t test_time;
	 alarm_date_t new_time;


		time(&current_time);
		localtime_r(&current_time, &current_tm);

		alarm = alarmmgr_create_alarm();
	 if(alarm == NULL) {
		  //alarmmgr_create_alarm () failed
	 }
	 else {
		test_time.year = current_tm.tm_year;
		test_time.month = current_tm.tm_mon;
		test_time.day = current_tm.tm_mday;

		test_time.hour = current_tm.tm_hour;
		test_time.min = current_tm.tm_min+1;
		test_time.sec = 0;

		ret_val = alarmmgr_set_time(alarm,test_time);
		if(ret_val == ALARMMGR_RESULT_SUCCESS) {
			//alarmmgr_set_time() is successful
		}
		else {
			//alarmmgr_set_time() failed
		}

		ret_val = alarmmgr_get_time(alarm, &new_time);
		if(ret_val == ALARMMGR_RESULT_SUCCESS) {
			//alarmmgr_get_time() is successful
		}
		else {
			//alarmmgr_get_time() failed
		}
		alarmmgr_free_alarm( alarm) ;
	}
 }

 * @endcode
 */
int alarmmgr_get_time(const alarm_entry_t *alarm, alarm_date_t *time);

/**
 * This function sets an alarm repeat mode
 *
 * @param	[in]	alarm	alarm entry
 * @param	[in]	repeat_mode	one of ALARM_REPEAT_MODE_ONCE, ALARM_REPEAT_MODE_REPEAT,
 *								ALARM_REPEAT_MODE_WEEKLY, ALARM_REPEAT_MODE_MONTHLY or ALARM_REPEAT_MODE_ANNUALLY.
 * @param	[in]	repeat_value	the ALARM_REPEAT_MODE_REPEAT mode : interval between subsequent repeats of the alarm.
 *								the ALARM_REPEAT_MODE_WEEKLY mode : days of a week
 *								(ALARM_WDAY_SUNDAY, ALARM_WDAY_MONDAY, ALARM_WDAY_TUESDAY, ALARM_WDAY_WEDNESDAY,
 *								ALARM_WDAY_THURSDAY, ALARM_WDAY_FRIDAY, ALARM_WDAY_SATURDAY)
 *								the others : this parameter is ignored.
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see None.
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

  ...
 {
	 int ret_val = ALARMMGR_RESULT_SUCCESS;
	 alarm_entry_t* alarm;
	 alarm_repeat_mode_t repeat_mode =ALARM_REPEAT_MODE_WEEKLY;
	 int interval = ALARM_WDAY_MONDAY; //| ALARM_WDAY_TUESDAY|
		ALARM_WDAY_WEDNESDAY| ALARM_WDAY_THURSDAY|ALARM_WDAY_FRIDAY ;


	 alarm = alarmmgr_create_alarm();
	 if(alarm == NULL)
	 {
		  //alarmmgr_create_alarm () failed
	 }
	 else
		 {
			   ret_val = alarmmgr_set_repeat_mode
					(alarm, repeat_mode,interval);

			 if(ret_val == ALARMMGR_RESULT_SUCCESS)
			 {
				  //alarmmgr_set_repeat_mode() is successful
			 }
			 else
			 {
				 //alarmmgr_set_repeat_mode() failed
			 }
			 alarmmgr_free_alarm( alarm) ;
		 }
 }

 * @endcode
 */
int alarmmgr_set_repeat_mode(alarm_entry_t *alarm,
				     alarm_repeat_mode_t repeat_mode,
				     int repeat_value);

/**
 * This function gives an application an alarm mode
 *
 * @param	[in]		alarm	alarm entry
 * @param	[out]	repeat_mode	one of ALARM_REPEAT_MODE_ONCE, ALARM_REPEAT_MODE_REPEAT,
 *									ALARM_REPEAT_MODE_WEEKLY, ALARM_REPEAT_MODE_MONTHLY or ALARM_REPEAT_MODE_ANNUALLY.
 * @param	[out]	repeat_value	the ALARM_REPEAT_MODE_REPEAT mode : interval between subsequent repeats of the alarm.
 *									the ALARM_REPEAT_MODE_WEEKLY mode : days of a week
 *									(ALARM_WDAY_SUNDAY, ALARM_WDAY_MONDAY, ALARM_WDAY_TUESDAY, ALARM_WDAY_WEDNESDAY,
 *									ALARM_WDAY_THURSDAY, ALARM_WDAY_FRIDAY, ALARM_WDAY_SATURDAY)
 *									the others : this parameter is ignored.
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see None.
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

   ...
 {
	 int ret_val = ALARMMGR_RESULT_SUCCESS;
	 alarm_entry_t* alarm;
	 alarm_repeat_mode_t repeat;
	 int interval;

	 alarm = alarmmgr_create_alarm();
	 if(alarm == NULL)
	 {
		 //alarmmgr_create_alarm () failed
	 }
	 else {
		ret_val =alarmmgr_get_repeat_mode
					(alarm, &repeat, &interval) ;
			 if(ret_val == ALARMMGR_RESULT_SUCCESS
			&& repeat == ALARM_REPEAT_MODE_ONCE) {
				//alarmmgr_get_repeat_mode() is successful
			}
			else {
				//alarmmgr_get_repeat_mode() failed
			}
			alarmmgr_free_alarm(alarm) ;
	}
 }

 * @endcode
 */
int alarmmgr_get_repeat_mode(const alarm_entry_t *alarm,
				     alarm_repeat_mode_t *repeat_mode,
				     int *repeat_value);

/**
 * This function sets an alarm mode
 *
 * @param	[in]	alarm	alarm entry
 * @param	[in]	alarm_type	one of ALARM_TYPE_DEFAULT : After the device reboot, the alarm still works.
 *							ALARM_TYPE_VOLATILE : After the device reboot, the alarm does not work.
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see None.
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

   ...
 {
	 int ret_val = ALARMMGR_RESULT_SUCCESS;
	 alarm_entry_t* alarm;
	 int alarm_type = ALARM_TYPE_VOLATILE;

	 alarm = alarmmgr_create_alarm();
	 if(alarm == NULL)
	 {
		  //alarmmgr_create_alarm () failed
	 }
	 else
		 {
			 ret_val = alarmmgr_set_type(alarm,  alarm_type);
			 if(ret_val == ALARMMGR_RESULT_SUCCESS)
			 {
				  //alarmmgr_set_type() is successful
			 }
			 else
			 {
				  //alarmmgr_set_type() failed
			 }
			 alarmmgr_free_alarm( alarm) ;
		 }
 }

 * @endcode
 */
int alarmmgr_set_type(alarm_entry_t *alarm, int alarm_type);

/**
 * This function gives an application an alarm mode
 *
 * @param	[in]		alarm	alarm entry
 * @param	[out]	alarm_type	one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see None.
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

   ...
 {
	int ret_val = ALARMMGR_RESULT_SUCCESS;
	alarm_entry_t* alarm;
	int alarm_type;

	alarm = alarmmgr_create_alarm();
	if(alarm == NULL) {
		//alarmmgr_create_alarm () failed
	}
	else {
		ret_val = alarmmgr_get_type(  alarm, &alarm_type);
		if(ret_val == ALARMMGR_RESULT_SUCCESS && alarm_type
						== ALARM_TYPE_DEFAULT ) {
			//alarmmgr_get_type() is successful
		}
		else {
			//alarmmgr_get_type() failed
		}
		alarmmgr_free_alarm( alarm) ;
	}
 }

 * @endcode
 */
int alarmmgr_get_type(const alarm_entry_t *alarm, int *alarm_type);

/**
 * This function adds an alarm entry to the server.
 * Server will remember this entry, and generate alarm events for it when necessary.
 * Server will call app-svc interface to sent notification to destination application. Destination information
 * should be available in the input bundle.
 * Alarm entries registered with the server cannot be changed.
 * Remove from server before changing.
 * Before the application calls alarmmgr_add_alarm_appsvc_with_localtime(), the application have to call alarmmgr_set_time().
 * The time set is localtime.
 * If the application does not call alarmmgr_set_repeat_mode, the default repeat_mode is ALARM_REPEAT_MODE_ONCE.
 * If the application does not call alarmmgr_set_type, the default alarm_type is ALARM_TYPE_DEFAULT.
 * The id of the new alarm will be copied to  alarm_id if the fuction successes to create an alarm.
 *
 * @param	[in]		alarm		the entry of an alarm to be created.
 * @param	[in]		bundle_data	bundle which contains information about the destination.
 * @param	[out]		alarm_id	the id of the alarm added.
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see alarmmgr_add_alarm
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

   ...
{
    time_t current_time;
    struct tm current_tm;
    alarm_entry_t* alarm_info;
    alarm_id_t alarm_id;
    int result;
    alarm_date_t test_time;


	bundle *b=NULL;

	b=bundle_create();

	if (NULL == b)
	{
		printf("Unable to create bundle!!!\n");
		return;
	}

	appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
	appsvc_set_pkgname(b,"org.tizen.alarm-test");

    time(&current_time);

    printf("current time: %s\n", ctime(&current_time));
    localtime_r(&current_time, &current_tm);

    alarm_info = alarmmgr_create_alarm();

    test_time.year = current_tm.tm_year;
			test_time.month = current_tm.tm_mon;
			test_time.day = current_tm.tm_mday;

			test_time.hour = current_tm.tm_hour;
			test_time.min = current_tm.tm_min+1;
			test_time.sec = 5;


    alarmmgr_set_time(alarm_info,test_time);
    alarmmgr_set_repeat_mode(alarm_info,ALARM_REPEAT_MODE_WEEKLY,ALARM_WDAY_MONDAY| \
		ALARM_WDAY_TUESDAY|ALARM_WDAY_WEDNESDAY| \
		ALARM_WDAY_THURSDAY|ALARM_WDAY_FRIDAY );

    alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
    //alarmmgr_set_type(alarm_info,ALARM_TYPE_VOLATILE);
    if ((result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info,(void *)b,&alarm_id)) < 0)
	{
		printf("Alarm creation failed!!! Alrmgr error code is %d\n",result);
	}
	else
	{
		printf("Alarm created succesfully with alarm id %d\n",alarm_id);
	}

}
 * @endcode
 */
int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm, void *bundle_data, alarm_id_t *alarm_id);

/**
 * This function adds an alarm entry to the server.
 * Server will remember this entry, and generate alarm events for it when necessary.
 * Server will post notification
 * Alarm entries registered with the server cannot be changed.
 * Remove from server before changing.
 * Before the application calls alarmmgr_add_alarm_noti_with_localtime(), the application have to call alarmmgr_set_time().
 * The time set is localtime.
 * If the application does not call alarmmgr_set_repeat_mode, the default repeat_mode is ALARM_REPEAT_MODE_ONCE.
 * If the application does not call alarmmgr_set_type, the default alarm_type is ALARM_TYPE_DEFAULT.
 * The id of the new alarm will be copied to  alarm_id if the fuction successes to create an alarm.
 *
 * @param	[in]		alarm		the entry of an alarm to be created.
 * @param	[in]		noti			notification handle to be posted when the alarm is expired
 * @param	[out]	alarm_id		the id of the alarm added.
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see alarmmgr_add_alarm
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

   ...
{
	time_t current_time;
	struct tm current_tm;
	alarm_entry_t* alarm_info;
	alarm_id_t alarm_id;
	int result;
	alarm_date_t test_time;

	noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
	result = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE,
			"Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);

	time(&current_time);

	printf("current time: %s\n", ctime(&current_time));
	localtime_r(&current_time, &current_tm);

	alarm_info = alarmmgr_create_alarm();

	test_time.year = current_tm.tm_year;
	test_time.month = current_tm.tm_mon;
	test_time.day = current_tm.tm_mday;

	test_time.hour = current_tm.tm_hour;
	test_time.min = current_tm.tm_min+1;
	test_time.sec = 5;

	alarmmgr_set_time(alarm_info,test_time);
	alarmmgr_set_repeat_mode(alarm_info,ALARM_REPEAT_MODE_WEEKLY,ALARM_WDAY_MONDAY| \
			ALARM_WDAY_TUESDAY|ALARM_WDAY_WEDNESDAY| \
			ALARM_WDAY_THURSDAY|ALARM_WDAY_FRIDAY );

	alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
	if ((result = alarmmgr_add_alarm_noti_with_localtime(alarm_info, noti, &alarm_id)) < 0)
		printf("Alarm creation failed!!! Alrmgr error code is %d\n",result);
	else
		printf("Alarm created succesfully with alarm id %d\n",alarm_id);

}
* @endcode
*/
int alarmmgr_add_alarm_noti_with_localtime(alarm_entry_t *alarm, notification_h noti, alarm_id_t *alarm_id);

/**
 * This function adds an alarm entry to the server.
 * Server will remember this entry, and generate alarm events for it when necessary.
 * Alarm entries registered with the server cannot be changed.
 * Remove from server before changing.
 * Before the application calls alarmmgr_add_alarm_with_localtime(), the application have to call alarmmgr_set_time().
 * The time set is localtime.
 * If the application does not call alarmmgr_set_repeat_mode, the default repeat_mode is ALARM_REPEAT_MODE_ONCE.
 * If the application does not call alarmmgr_set_type, the default alarm_type is ALARM_TYPE_DEFAULT.
 * The id of the new alarm will be copied to  alarm_id if the fuction successes to create an alarm.
 *
 * @param	[in]		alarm		the entry of an alarm to be created.
 * @param	[in]		destination	the packname of application that the alarm will be expired.
 * @param	[out]	alarm_id		the id of the alarm added.
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see alarmmgr_add_alarm
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

   ...
{
	int ret_val = ALARMMGR_RESULT_SUCCESS;
	alarm_entry_t* alarm;
	const char* destination = NULL;
	alarm_id_t alarm_id;

	time_t current_time;
	struct tm current_tm;
	alarm_date_t test_time;

	const char* pkg_name = "org.tizen.test";

	g_type_init();

	ret_val =alarmmgr_init(pkg_name) ;
	if(ret_val != ALARMMGR_RESULT_SUCCESS) {
		//alarmmgr_init () failed
		return;
	}

	time(&current_time);

	printf("current time: %s\n", ctime(&current_time));
	localtime_r(&current_time, &current_tm);

	alarm = alarmmgr_create_alarm();

	test_time.year = 0;
	test_time.month = 0;test_time.day = 0;

	test_time.hour = current_tm.tm_hour;
	test_time.min = current_tm.tm_min+1;
	test_time.sec = 0;


	 alarmmgr_set_time(alarm,test_time);
	 alarmmgr_set_repeat_mode(alarm,ALARM_REPEAT_MODE_WEEKLY, \
					ALARM_WDAY_MONDAY);
	 alarmmgr_set_type(alarm,ALARM_TYPE_VOLATILE);


	ret_val=alarmmgr_add_alarm_with_localtime(alarm,destination,&alarm_id);

	 if(ret_val == ALARMMGR_RESULT_SUCCESS)
	 {
		  //alarmmgr_add_alarm_with_localtime() is successful
	 }
	 else
	 {
		  //alarmmgr_add_alarm_with_localtime() failed
	 }
	 alarmmgr_free_alarm( alarm) ;
 }
 * @endcode
 */
int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
					      const char *destination,
					      alarm_id_t *alarm_id);


/**
 * This function adds an alarm entry to the server.
 * Server will remember this entry, and generate alarm events for it when necessary.
 * Server will call app-svc interface to sent notification to destination application. Destination information
 * should be available in the input bundle.
 * Alarm entries registered with the server cannot be changed.
 * Remove from server before changing.
 * After the trigger_at_time seconds from now, the alarm will be expired.
 * If the interval is zero, the repeat_mode is ALARM_REPEAT_MODE_ONCE.
 * If the interval is >0, the repeat_mode is ALARM_REPEAT_MODE_REPEAT.
 * The id of the new alarm will be copied to  alarm_id if the fuction successes to create an alarm.
 *
 * @param	[in]		alarm_type		one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
 * @param	[in]		trigger_at_time	time interval to be triggered from now(sec). an alarm also will be expired at triggering time.
 * @param	[in]		interval		Interval between subsequent repeats of the alarm
 * @param	[in]		bundle_data		bundle which contains information about the destination.
 * @param	[out]	alarm_id			the id of the alarm added.
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see alarmmgr_add_alarm_with_localtime alarmmgr_remove_alarm
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

 ...
 {
		int result;
		alarm_id_t alarm_id;

		bundle *b=NULL;

		b=bundle_create();

		if (NULL == b)
		{
			printf("Unable to create bundle!!!\n");
			return;
		}

		appsvc_set_pkgname(b,"org.tizen.alarm-test");
		//appsvc_set_operation(b,APPSVC_OPERATION_SEND_TEXT);
		appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);

		if ((result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, 10, 0, (void *)b ,&alarm_id)))
			printf("Unable to add alarm. Alarmmgr alarm no is %d\n", result);
		else
			printf("Alarm added successfully. Alarm Id is %d\n", alarm_id);
		return;

 }

 * @endcode
 */
int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
			       time_t interval, void *bundle_data,
			       alarm_id_t *alarm_id);

/*
 * This function adds an alarm entry to the server.
 * Server will remember this entry, and generate alarm events for it when necessary.
 * Server will post notification
 * Alarm entries registered with the server cannot be changed.
 * Remove from server before changing.
 * After the trigger_at_time seconds from now, the alarm will be expired.
 * If the interval is zero, the repeat_mode is ALARM_REPEAT_MODE_ONCE.
 * If the interval is >0, the repeat_mode is ALARM_REPEAT_MODE_REPEAT.
 * The id of the new alarm will be copied to  alarm_id if the fuction successes to create an alarm.
 *
 * @param	[in]		alarm_type		one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
 * @param	[in]		trigger_at_time	time interval to be triggered from now(sec). an alarm also will be expired at triggering time.
 * @param	[in]		interval		Interval between subsequent repeats of the alarm
 * @param	[in]		noti			notification handle to be posted when the alarm is expired
 * @param	[out]	alarm_id		the id of the alarm added.
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see alarmmgr_add_alarm_with_localtime alarmmgr_remove_alarm
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

 ...
{
	int result;
	alarm_id_t alarm_id;
	notification_h noti_handle;

	noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
	result = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE,
			"Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);

	if ((result = alarmmgr_add_alarm_noti(ALARM_TYPE_DEFAULT, 10, 0, noti_handle, &alarm_id)))
		printf("Unable to add alarm. Alarmmgr alarm no is %d\n", result);
	else
		printf("Alarm added successfully. Alarm Id is %d\n", alarm_id);
	return;

}

 * @endcode
 */
int alarmmgr_add_alarm_noti(int alarm_type, time_t trigger_at_time,
			       time_t interval, notification_h noti,
			       alarm_id_t *alarm_id);


/**
 * This function adds an alarm entry to the server.
 * Server will remember this entry, and generate alarm events for it when necessary.
 * Alarm entries registered with the server cannot be changed.
 * Remove from server before changing.
 * After the trigger_at_time seconds from now, the alarm will be expired.
 * If the interval is zero, the repeat_mode is ALARM_REPEAT_MODE_ONCE.
 * If the interval is >0, the repeat_mode is ALARM_REPEAT_MODE_REPEAT.
 * The id of the new alarm will be copied to  alarm_id if the fuction successes to create an alarm.
 *
 * @param	[in]		alarm_type		one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
 * @param	[in]		trigger_at_time	time interval to be triggered from now(sec). an alarm also will be expired at triggering time.
 * @param	[in]		interval			Interval between subsequent repeats of the alarm
 * @param	[in]		destination		the packname of application that the alarm will be expired.
 * @param	[out]	alarm_id			the id of the alarm added.
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see alarmmgr_add_alarm_with_localtime alarmmgr_remove_alarm
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

 ...
 {
	 int ret_val = ALARMMGR_RESULT_SUCCESS;

	 int alarm_type = ALARM_TYPE_VOLATILE;
	 time_t trigger_at_time = 10;
	 time_t interval = 10;
	 const char* destination = NULL;
	 alarm_id_t alarm_id;

	 const char* pkg_name = "org.tizen.test";

	 g_type_init();

	 ret_val =alarmmgr_init(pkg_name) ;
	 if(ret_val != ALARMMGR_RESULT_SUCCESS)
	 {
		  //alarmmgr_init () failed
		  return;
	 }

	 ret_val = alarmmgr_add_alarm( alarm_type, trigger_at_time, interval,
					destination, &alarm_id);
	 if(ret_val == ALARMMGR_RESULT_SUCCESS)
	 {
		  //alarmmgr_add_alarm() is successful
	 }
	 else
	 {
		   //alarmmgr_add_alarm() failed
	 }
	 alarmmgr_remove_alarm( alarm_id) ;
 }

 * @endcode
 */
int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
			       time_t interval, const char *destination,
			       alarm_id_t *alarm_id);


/**
 * This function adds an alarm entry to the server with milliseconds precision.
 * Server will remember this entry, and generate alarm events for it when necessary.
 * Alarm entries registered with the server cannot be changed.
 * Remove from server before changing.
 * After the trigger_at_time seconds from now, the alarm will be expired.
 * If the interval is zero, the repeat_mode is ALARM_REPEAT_MODE_ONCE.
 * If the interval is >0, the repeat_mode is ALARM_REPEAT_MODE_REPEAT.
 * The id of the new alarm will be copied to  alarm_id if the fuction successes to create an alarm.
 *
 * @param	[in]		alarm_type		one of ALARM_TYPE_DEFAULT, ALARM_TYPE_VOLATILE
 * @param	[in]		trigger_at_time	time interval to be triggered from now(sec). an alarm also will be expired at triggering time.
 * @param	[in]		interval			Interval between subsequent repeats of the alarm
 * @param	[in]		destination		the packname of application that the alarm will be expired.
 * @param	[out]	alarm_id			the id of the alarm added.
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see alarmmgr_add_alarm_with_localtime alarmmgr_remove_alarm
 * @remark When a process which registered an alarm is killed, the callback @c handler will not be used.
 *         In this case, calling the @c alarmmgr_set_cb() can register a callback again.
 *         The callback function may be delayed, due to the processing of other event.
 *         This function corrects the delay as much as possible.
 */
int alarmmgr_add_alarm_precision(int alarm_type, time_t trigger_at_time,
			       time_t interval, const char *destination,
			       alarm_id_t *alarm_id);

/**
 * This function deletes the alarm associated with the given alarm_id.
 *
 * @param	[in]	alarm_id	Specifies the ID of the alarm to be deleted.
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see alarmmgr_add_alarm_with_localtime alarmmgr_add_alarm
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

 ...
 {
	int ret_val = ALARMMGR_RESULT_SUCCESS;
	int alarm_type = ALARM_TYPE_VOLATILE;
	time_t trigger_at_time = 10;
	time_t interval = 10;
	const char* destination = NULL;
	alarm_id_t alarm_id;

	const char* pkg_name = "org.tizen.test";

	g_type_init();

	ret_val =alarmmgr_init(pkg_name) ;
	if(ret_val != ALARMMGR_RESULT_SUCCESS) {
		//alarmmgr_init () failed
		return;
	}

	alarmmgr_add_alarm( alarm_type,  trigger_at_time, interval,
						destination, &alarm_id);

	ret_val =alarmmgr_remove_alarm( alarm_id) ;
	if(ret_val == ALARMMGR_RESULT_SUCCESS) {
		/alarmmgr_remove_alarm() is successful
	}
	else {
		//alarmmgr_remove_alarm() failed
	}
 }

 * @endcode
 */
int alarmmgr_remove_alarm(alarm_id_t alarm_id);

/**
 * This function deletes all registered alarms
 *
 * @return	This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 */
int alarmmgr_remove_all(void);

/**
 * This function gives a list of alarm ids that the application adds to the server.
 *
 * @param	[in]	fn			a user callback function
 * @param	[in]	user_param	user parameter
 *
 * @return			This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see alarm_get_info
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

 int callback_2(alarm_id_t id, void* user_param)
 {
	 int* n = (int*)user_param;
	 printf("[%d]alarm id : %d\n",*n,id);
	 (*n)++;
	 return 0;
 }

...
 {
	 int ret_val = ALARMMGR_RESULT_SUCCESS;
	 int n = 1;

	 const char* pkg_name = "org.tizen.test";

	 g_type_init();

	 ret_val =alarmmgr_init(pkg_name) ;
	 if(ret_val != ALARMMGR_RESULT_SUCCESS)
	 {
		  //alarmmgr_init() failed
		  return;
	 }

	 ret_val = alarmmgr_enum_alarm_ids( callback_2, (void*)&n) ;
	 if(ret_val == ALARMMGR_RESULT_SUCCESS)
	 {
		   //alarmmgr_enum_alarm_ids() is successful
	 }
	 else
	 {
		 //alarmmgr_enum_alarm_ids() failed
	 }
 }

 * @endcode
 */
int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param);


/**
 * This function gets the information of the alarm assosiated with alarm_id to alarm_info. The application
 * must allocate alarm_info before calling this function.
 *
 * @param	[in]	alarm_id		the id of the alarm
 * @param	[out]	alarm	the buffer alarm informaiton will be copied to
 *
 * @return			This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see alarmmgr_enum_alarm_ids
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

...
 {
	int ret_val = ALARMMGR_RESULT_SUCCESS;
	int alarm_type = ALARM_TYPE_VOLATILE;
	time_t trigger_at_time = 10;
	time_t interval = ALARM_WDAY_SUNDAY;
	const char* destination = NULL;
	alarm_id_t alarm_id;

	alarm_entry_t *alarm;

	const char* pkg_name = "org.tizen.test_get_info1";

	g_type_init();

	ret_val =alarmmgr_init(pkg_name) ;
	if(ret_val != ALARMMGR_RESULT_SUCCESS) {
		//alarmmgr_init() failed
		return;
	}
	ret_val = alarmmgr_add_alarm( alarm_type,trigger_at_time,interval,
			destination, &alarm_id);

	if(ret_val != ALARMMGR_RESULT_SUCCESS) {
		//alarmmgr_add_alarm() failed
		return;
	}
	ret_val = alarmmgr_get_info(alarm_id, alarm);
	if(ret_val == ALARMMGR_RESULT_SUCCESS) {
		//alarmmgr_get_info() is successful
	}
	else {
		//alarmmgr_get_info() failed
	}
	alarmmgr_remove_alarm( alarm_id) ;
 }
 * @endcode
 */
int alarmmgr_get_info(alarm_id_t alarm_id, alarm_entry_t *alarm);


/**
 * This function retrieves bundle associated with alarm.
 * Server will remember this entry, and pass the bundle information upon alarm expiry.
 * Server will call app-svc interface to sent notification to destination application. Destination information
 * should be available in the input bundle.
 * @param	[in]		alarm_id		alarm id
 * @param	[out]		ALARMMGR_RESULT_SUCCESS on success or negative number on failure.
 *
 * @return	This function returns bundle on success or NULL on failure.
 *
 * @pre None.
 * @post None.
 * @see None
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

 ...

alarm_id_t alarm_id;

register_alarm(){
	int result;
	bundle *b=NULL;
	b=bundle_create();

	if (NULL == b)
	{
		printf("Unable to create bundle!!!\n");
		return;
	}

	appsvc_set_pkgname(b,"org.tizen.alarm-test");
	appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);

	if ((result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, 10, 0, (void *)b ,&alarm_id)))
		printf("Unable to add alarm. Alarmmgr alarm no is %d\n", result);
	else
		printf("Alarm added successfully. Alarm Id is %d\n", alarm_id);
}
int main(int argc,char **argv {
	register_alarm();

	int return_code = 0;
	bundle *b = NULL;
	b = alarmmgr_get_alarm_appsvc_info(alarm_id, &return_code);
	if (b){
		const char *pkgname = appsvc_get_pkgname(b);
		if (pkgname){
			printf("Package name is %s\n",pkgname);
		}
	}

	return 0;

 }
 * @endcode
 */
void *alarmmgr_get_alarm_appsvc_info(alarm_id_t alarm_id, int *return_code);

int alarmmgr_get_alarm_noti_info(alarm_id_t alarm_id, notification_h *noti);

/**
 * This function gets the scheduled time of the alarm assosiated with alarm_id.
 *
 * @param	[in]	alarm_id		the id of the alarm
 * @param	[out]	duetime	the scheduled time of the alarm
 *
 * @return			This function returns ALARMMGR_RESULT_SUCCESS on success or a negative number on failure.
 *
 * @pre None.
 * @post None.
 * @see None
 * @remark  None.
 */
int alarmmgr_get_next_duetime(alarm_id_t alarm_id, time_t *duetime);

/**
 * This function sets power RTC (which can power on the system).
 * @param	[in]		alarm_date_t		time
 *
 * @return	This function returns the result. On success, ALARMMGR_RESULT_SUCCESS will be returned
 *		else, appropriate error no will be returned.
 * @pre None.
 * @post None.
 * @see None
 * @remark  None.
 *
 * @par Sample code:
 * @code
#include <alarm.h>

 ...

alarm_date_t alarm_date={2012,04,05,10,10,00};

int main(int argc,char **argv {
	int return_code = 0;
	return_code = alarmmgr_set_rtc_time(&alarm_date);
	if (return_code != ALARMMGR_RESULT_SUCCESS){
		printf("Error returned is %d\n",return_code);
	}
	return 0;

 }
 * @endcode
 */
int alarmmgr_set_rtc_time(alarm_date_t *time);

/**
 * This function changes the system time which tranferred by other module
 * @param	[in]		new_time		epoch time to be set
 *
 * @return	@c ALARMMGR_RESULT_SUCCESS on success,
 *			otherwise a negative error value
 * @retval	#ALARMMGR_RESULT_SUCCESS	Successful
 * @retval	#ERR_ALARM_SYSTEM_FAIL		System failure
 */
int alarmmgr_set_systime(int new_time);
int alarmmgr_set_systime64(time_t new_time);

/**
 * This function asynchronously changes the system time which tranferred by other module
 * @param	[in]		new_time		epoch time to be set
 * @param [in]		result_cb		The asynchronous callback function to get the result
 * @param [in]		user_param	User parameter to be passed to the callback function
 *
 * @return	@c ALARMMGR_RESULT_SUCCESS on success,
 *			otherwise a negative error value
 * @retval	#ALARMMGR_RESULT_SUCCESS	Successful
 * @retval	#ERR_ALARM_SYSTEM_FAIL		System failure
 */
int alarmmgr_set_systime_async(int new_time, alarm_set_time_cb_t result_cb, void *user_param);
int alarmmgr_set_systime64_async(time_t new_time, alarm_set_time_cb_t result_cb, void *user_param);

/**
 * This function changes the system time and compensates the time using propagation delay.
 * @param	[in]		new_time		system time to be set (seconds, nanoseconds)
 * @param	[in]		req_time		time to request to change the system time (seconds, nanoseconds)
 *
 * @return	@c ALARMMGR_RESULT_SUCCESS on success,
 *			otherwise a negative error value
 * @retval	#ALARMMGR_RESULT_SUCCESS	Successful
 * @retval	#ERR_ALARM_SYSTEM_FAIL		System failure
 * @retval	#ERR_ALARM_INVALID_PARAM	invalid parameter
 */
int alarmmgr_set_systime_with_propagation_delay(struct timespec new_time, struct timespec req_time);

/**
 * This function asynchronously changes the system time and compensates the time using propagation delay.
 * @param	[in]		new_time		system time to be set (seconds, nanoseconds)
 * @param	[in]		req_time		time to request to change the system time (seconds, nanoseconds)
 * @param [in]		result_cb		The asynchronous callback function to get the result
 * @param [in]		user_param	User parameter to be passed to the callback function
 *
 * @return	@c ALARMMGR_RESULT_SUCCESS on success,
 *			otherwise a negative error value
 * @retval	#ALARMMGR_RESULT_SUCCESS	Successful
 * @retval	#ERR_ALARM_SYSTEM_FAIL		System failure
 * @retval	#ERR_ALARM_INVALID_PARAM	invalid parameter
 */
int alarmmgr_set_systime_with_propagation_delay_async(struct timespec new_time, struct timespec req_time, alarm_set_time_cb_t result_cb, void *user_param);

/**
 * This function changes the timezone which tranferred by other module
 * @param	[in]		tzpath_str	the path to timezone definition file
 *
 * @return	@c ALARMMGR_RESULT_SUCCESS on success,
 *			otherwise a negative error value
 * @retval	#ALARMMGR_RESULT_SUCCESS	Successful
 * @retval	#ERR_ALARM_INVALID_PARAM	Invalid parameter
 * @retval	#ERR_ALARM_SYSTEM_FAIL		System failure
 */
int alarmmgr_set_timezone(char *tzpath_str);

/**
 * This function sets global
 * @remarks The @a alarm_id must be id of alarm which will launch global application.
 *          The function returns an error (error code #ERR_ALARM_INVALID_ID) if it is not.
 * @param	[in]	alarm_id		the id of the alarm
 * @param	[in]	global		value to set global or not
 *
 * @return	@c ALARMMGR_RESULT_SUCCESS on success,
 *			otherwise a negative error value
 * @retval	#ALARMMGR_RESULT_SUCCESS	Successful
 * @retval	#ERR_ALARM_INVALID_PARAM	Invalid parameter
 * @retval	#ERR_ALARM_INVALID_ID	Invaild id of the alarm
 * @retval	#ERR_ALARM_SYSTEM_FAIL		System failure
 */
int alarmmgr_set_global(alarm_id_t alarm_id, bool global);

/**
 * This function gets global
 * @param	[in]	alarm_id		the id of the alarm
 * @param	[out]	global	Whether the alarm is global or not
 *
 * @return	@c ALARMMGR_RESULT_SUCCESS on success,
 *			otherwise a negative error value
 * @retval	#ALARMMGR_RESULT_SUCCESS	Successful
 * @retval	#ERR_ALARM_INVALID_PARAM	Invalid parameter
 * @retval	#ERR_ALARM_INVALID_ID	Invaild id of the alarm
 * @retval	#ERR_ALARM_SYSTEM_FAIL		System failure
 */
int alarmmgr_get_global(const alarm_id_t alarm_id, bool *global);

/**
 * This function adds an alarm and registers a callback function per an alarm.
 * @param	[in]		alarm_type		ALARM_TYPE_DEFAULT or ALARM_TYPE_VOLATILE
 * @param	[in]		trigger_at_time	Time interval to be triggered from now(sec). an alarm also will be expired at triggering time
 * @param	[in]		interval			Interval between subsequent repeats of the alarm
 * @param	[in]		handler			The callback function invoked when the alarm is expired
 * @param	[in]		user_param		Parameters of callback function
 * @param	[out]	alarm_id			The id of the alarm added
 *
 * @return	@c ALARMMGR_RESULT_SUCCESS on success,
 *			otherwise a negative error value
 * @retval	#ALARMMGR_RESULT_SUCCESS	Successful
 * @retval	#ERR_ALARM_INVALID_PARAM	Invalid parameter
 * @retval	#ERR_ALARM_SYSTEM_FAIL	System failure
 * @retval	#ERR_ALARM_NO_PERMISSION	Permission error
 * @remark	When a process which registered an alarm is killed, the callback @c handler will not be used.
 *			In this case, calling the @c alarmmgr_set_cb() can register a callback again.
 */
int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time,
				  time_t interval, alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id);

/**
 * This function adds an alarm with milliseconds precision and registers a callback function per an alarm.
 * @param	[in]		alarm_type		ALARM_TYPE_DEFAULT or ALARM_TYPE_VOLATILE
 * @param	[in]		trigger_at_time	Time interval to be triggered from now(sec, with accuracy in milliseconds). an alarm also will be expired at triggering time
 * @param	[in]		interval			Interval between subsequent repeats of the alarm
 * @param	[in]		handler			The callback function invoked when the alarm is expired
 * @param	[in]		user_param		Parameters of callback function
 * @param	[out]	alarm_id			The id of the alarm added
 *
 * @return	@c ALARMMGR_RESULT_SUCCESS on success,
 *			otherwise a negative error value
 * @retval	#ALARMMGR_RESULT_SUCCESS	Successful
 * @retval	#ERR_ALARM_INVALID_PARAM	Invalid parameter
 * @retval	#ERR_ALARM_SYSTEM_FAIL	System failure
 * @retval	#ERR_ALARM_NO_PERMISSION	Permission error
 * @remark	When a process which registered an alarm is killed, the callback @c handler will not be used.
 *			In this case, calling the @c alarmmgr_set_cb() can register a callback again.
 *			The callback function may be delayed, due to the processing of other event.
 *			This function corrects the delay as much as possible.
 *
 */
int alarmmgr_add_alarm_withcb_precision(int alarm_type, time_t trigger_at_time,
				  time_t interval, alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id);

int alarmmgr_add_periodic_alarm_withcb(int interval, periodic_method_e method, alarm_cb_t handler,
		void *user_param, alarm_id_t *alarm_id);

int alarmmgr_add_reference_periodic_alarm_withcb(int interval, alarm_cb_t handler,
		void *user_param, alarm_id_t *alarm_id);

int alarmmgr_update_alarm(alarm_id_t alarm_id,
		alarm_entry_t *alarm, int update_flag);

int alarmmgr_add_alarm_withcb_with_localtime(alarm_entry_t *alarm,
		 alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id);

#ifdef __cplusplus
}
#endif