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.
18 #include "list-data.h"
19 #include "list-comparator.h"
22 calendar_list_h list1;
23 calendar_list_h list2;
24 calendar_list_h list3;
25 unsigned int time_property_id1;
26 unsigned int time_property_id2;
27 unsigned int time_property_id3;
28 struct tm current_day;
31 static calendar_list_h __cal_list_data_retreive_list(calendar_query_h query)
33 c_retv_if(query == NULL, NULL);
35 calendar_list_h list = NULL;
36 calendar_error_e error = calendar_db_get_records_with_query(query, 0, 0, &list);
37 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_db_get_records_with_query() has failed(%x)", error);
39 error = calendar_list_first(list);
40 c_retvm_if(error != CALENDAR_ERROR_NONE, NULL, "calendar_list_first() has failed(%x)", error);
47 calendar_query_h query1, calendar_query_h query2, calendar_query_h query3,
48 unsigned int time_property_id1, unsigned int time_property_id2, unsigned int time_property_id3)
50 cal_list_data_s* p = (cal_list_data_s*)calloc(1, sizeof(cal_list_data_s));
52 p->list1 = __cal_list_data_retreive_list(query1);
53 p->list2 = __cal_list_data_retreive_list(query2);
54 p->list3 = __cal_list_data_retreive_list(query3);
56 p->time_property_id1 = time_property_id1;
57 p->time_property_id2 = time_property_id2;
58 p->time_property_id3 = time_property_id3;
63 static calendar_record_h __cal_list_data_get_next(calendar_list_h list)
65 calendar_record_h record = NULL;
66 calendar_error_e error = calendar_list_get_current_record_p(list, &record);
67 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() has failed(%x)", error);
71 calendar_record_h cal_list_data_get_next(cal_list_data_h cursor, bool* day_has_changed)
73 c_retv_if(cursor == NULL, NULL);
74 cal_list_data_s* p = (cal_list_data_s*)cursor;
76 // Peak foremost record of each run.
77 // NULL record means there is no more!
78 calendar_record_h record1 = __cal_list_data_get_next(p->list1);
79 calendar_record_h record2 = __cal_list_data_get_next(p->list2);
80 calendar_record_h record3 = __cal_list_data_get_next(p->list3);
82 int winner = cal_list_comparator_determine_next(
83 record1, record2, record3,
84 p->time_property_id1, p->time_property_id2, p->time_property_id3,
85 1, &p->current_day, day_has_changed);
90 calendar_list_next(p->list1);
94 calendar_list_next(p->list2);
98 calendar_list_next(p->list3);
101 DBG("Winner: All records have been processed!");
109 void cal_list_data_destroy(cal_list_data_h cursor, bool delete_records)
111 c_ret_if(cursor == NULL);
112 cal_list_data_s* p = (cal_list_data_s*)cursor;
114 if (p->list1 != NULL)
115 calendar_list_destroy(p->list1, delete_records);
116 if (p->list2 != NULL)
117 calendar_list_destroy(p->list2, delete_records);
118 if (p->list3 != NULL)
119 calendar_list_destroy(p->list3, delete_records);