3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
24 #include "../include/alarm-engine.h"
26 void usage(char *name)
29 "Usage: %s [-l] [-L author] [-a add] [-d id] [-s id] [-e id] [-v id]\n",
31 fprintf(stderr, "\t -l, --datalist list alarm data\n");
32 fprintf(stderr, "\t -L, --author author list alarm data\n");
33 fprintf(stderr, "\t -a, --add add alarm data\n");
34 fprintf(stderr, "\t -d, --del delete alarm data\n");
35 fprintf(stderr, "\t -s, --snooze set alarm enable \n");
36 fprintf(stderr, "\t -e, --enable set alarm snooze\n");
37 fprintf(stderr, "\t -v, --view view alarm data\n");
41 void prt_data_list(void)
43 printf("%s is called\n", __func__);
44 struct alarm_data_list *adl = NULL;
45 struct alarm_data_list *t = NULL;
47 adl = alarmdb_get_data_list_all();
53 printf("[%d] %d| %d| %d| %s| %d| %d| %d| %d|"
54 "%d| %d| %d| [%d] %d| %d| %d|"
56 t->ad.id, t->ad.alarm_mgr_id, t->ad.enable, t->ad.author,
57 t->ad.name, (int)t->ad.stime, (int)t->ad.etime,
58 (int)t->ad.sdate, (int)t->ad.edate, t->ad.repeat_once,
59 t->ad.repeat_every, t->ad.repeat_weekly,
60 t->ad.snooze_enable, t->ad.snooze_min,
61 t->ad.snooze_times, t->ad.count, t->ad.type, t->ad.tone,
65 alarmdb_free_data_list(adl);
68 void prt_data_list_by_author(char author)
70 printf("%s is called\n", __func__);
71 struct alarm_data_list *adl = NULL;
72 struct alarm_data_list *t = NULL;
74 adl = alarmdb_get_data_list_by_author(author);
80 printf("[%d] %d| %d| %d| %s| %d| %d| %d| %d|"
81 "%d| %d| %d| [%d] %d| %d| %d|"
83 t->ad.id, t->ad.alarm_mgr_id, t->ad.enable, t->ad.author,
84 t->ad.name, (int)t->ad.stime, (int)t->ad.etime,
85 (int)t->ad.sdate, (int)t->ad.edate, t->ad.repeat_once,
86 t->ad.repeat_every, t->ad.repeat_weekly,
87 t->ad.snooze_enable, t->ad.snooze_min,
88 t->ad.snooze_times, t->ad.count, t->ad.type, t->ad.tone,
92 alarmdb_free_data_list(adl);
95 void prt_data(struct alarm_data *ad)
97 printf("id: [%d]\n", ad->id);
98 printf("alarm manager id: [%d]\n", ad->alarm_mgr_id);
99 printf("enable: [%d]\n", ad->enable);
100 printf("author: [%d]\n", ad->author);
101 printf("name: [%s]\n", ad->name);
102 printf("stime: [%d]\n", (int)ad->stime);
103 printf("etime: [%d]\n", (int)ad->etime);
104 printf("sdate: [%d]\n", (int)ad->sdate);
105 printf("edate: [%d]\n", (int)ad->edate);
106 printf("repeat_once: [%d]\n", ad->repeat_once);
107 printf("repeat_every: [%d]\n", ad->repeat_every);
108 printf("repeat_weekly: [%d]\n", ad->repeat_weekly);
109 printf("snooze_enable: [%d]\n", ad->snooze_enable);
110 printf("snooze_min: [%d]\n", ad->snooze_min);
111 printf("snooze_times: [%d]\n", ad->snooze_times);
112 printf("count: [%d]\n", ad->count);
113 printf("type: [%d]\n", ad->type);
114 printf("tone: [%s]\n", ad->tone);
115 printf("volume: [%d]\n", ad->volume);
118 void add_data(time_t tm)
120 struct alarm_data *ad = NULL;
121 ad = alarmdb_create_data();
128 snprintf(ad->name, sizeof(ad->name), "%s", "New name");
130 ad->etime = tm + 100;
134 ad->repeat_every = 1;
135 ad->repeat_weekly = 0;
136 ad->snooze_enable = 0;
138 ad->snooze_times = 2;
141 snprintf(ad->tone, sizeof(ad->tone), "%s", "/opt/x1");
144 alarmdb_add_data(ad);
145 alarmdb_free_data(ad);
148 void set_snooze(int id)
150 alarmdb_set_snooze(id, 1);
153 void set_enable(int id)
155 alarmdb_set_enable(id, 1);
158 void del_data(int id)
160 alarmdb_del_data(id);
163 void view_data(int id)
165 struct alarm_data *ad = NULL;
167 ad = alarmdb_create_data();
171 printf("Not found %d data\n", id);
173 alarmdb_free_data(ad);
176 int main(int argc, char *argv[])
179 // struct alarm_data ad = {0, };
181 r = alarmdb_init(NULL);
187 static struct option long_options[] = {
188 {"datalist", no_argument, NULL, 'l'},
189 {"author", no_argument, NULL, 'L'},
190 {"add", no_argument, NULL, 'a'},
191 {"delete", no_argument, NULL, 'd'},
192 {"enable", no_argument, NULL, 'e'},
193 {"snooze", no_argument, NULL, 's'},
194 {"view", no_argument, NULL, 'v'},
198 c = getopt_long(argc, argv, "lL:a:d:e:s:v:c:", long_options,
208 prt_data_list_by_author(atoi(optarg));
211 add_data(atoi(optarg));
214 del_data(atoi(optarg));
217 set_enable(atoi(optarg));
220 set_snooze(atoi(optarg));
223 view_data(atoi(optarg));