gst: check non-null before dereference
[platform/upstream/gstreamer.git] / gst / gstdatetime.h
1 /* GStreamer
2  * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef __GST_DATE_TIME_H__
21 #define __GST_DATE_TIME_H__
22
23 #include <gst/gstconfig.h>
24
25 #include <time.h>
26 #include <glib.h>
27 #include <glib-object.h>
28
29 G_BEGIN_DECLS
30
31 /**
32  * GstDateTime:
33  *
34  * Opaque, immutable, refcounted struct that stores date, time and timezone
35  * information. It currently supports ranges from 0001-01-01 to
36  * 9999-12-31 in the Gregorian proleptic calendar.
37  *
38  * Use the accessor functions to get the stored values.
39  */
40 typedef struct _GstDateTime GstDateTime;
41
42 GST_EXPORT GType _gst_date_time_type;
43
44 /**
45  * GST_TYPE_DATE_TIME:
46  *
47  * a boxed #GValue type for #GstDateTime that represents a date and time.
48  *
49  * Returns: the #GType of GstDateTime
50  */
51
52 #define GST_TYPE_DATE_TIME (_gst_date_time_type)
53
54 GType           gst_date_time_get_type (void);
55
56 /* query which fields are set */
57
58 gboolean        gst_date_time_has_year                (const GstDateTime * datetime);
59 gboolean        gst_date_time_has_month               (const GstDateTime * datetime);
60 gboolean        gst_date_time_has_day                 (const GstDateTime * datetime);
61 gboolean        gst_date_time_has_time                (const GstDateTime * datetime);
62 gboolean        gst_date_time_has_second              (const GstDateTime * datetime);
63
64 /* field getters */
65
66 gint            gst_date_time_get_year                (const GstDateTime * datetime);
67 gint            gst_date_time_get_month               (const GstDateTime * datetime);
68 gint            gst_date_time_get_day                 (const GstDateTime * datetime);
69 gint            gst_date_time_get_hour                (const GstDateTime * datetime);
70 gint            gst_date_time_get_minute              (const GstDateTime * datetime);
71 gint            gst_date_time_get_second              (const GstDateTime * datetime);
72 gint            gst_date_time_get_microsecond         (const GstDateTime * datetime);
73 gfloat          gst_date_time_get_time_zone_offset    (const GstDateTime * datetime);
74
75 /* constructors */
76
77 GstDateTime *   gst_date_time_new_from_unix_epoch_local_time (gint64 secs) G_GNUC_MALLOC;
78
79 GstDateTime *   gst_date_time_new_from_unix_epoch_utc   (gint64 secs) G_GNUC_MALLOC;
80
81 GstDateTime *   gst_date_time_new_local_time            (gint year,
82                                                          gint month,
83                                                          gint day,
84                                                          gint hour,
85                                                          gint minute,
86                                                          gdouble seconds) G_GNUC_MALLOC;
87
88 GstDateTime *   gst_date_time_new_y                     (gint year) G_GNUC_MALLOC;
89
90 GstDateTime *   gst_date_time_new_ym                    (gint year,
91                                                          gint month) G_GNUC_MALLOC;
92
93 GstDateTime *   gst_date_time_new_ymd                   (gint year,
94                                                          gint month,
95                                                          gint day) G_GNUC_MALLOC;
96
97 GstDateTime *   gst_date_time_new                       (gfloat tzoffset,
98                                                          gint year, gint month,
99                                                          gint day, gint hour,
100                                                          gint minute,
101                                                          gdouble seconds) G_GNUC_MALLOC;
102
103 GstDateTime *   gst_date_time_new_now_local_time (void) G_GNUC_MALLOC;
104
105 GstDateTime *   gst_date_time_new_now_utc        (void) G_GNUC_MALLOC;
106
107
108 gchar *         gst_date_time_to_iso8601_string  (GstDateTime * datetime) G_GNUC_MALLOC;
109 GstDateTime *   gst_date_time_new_from_iso8601_string  (const gchar * string) G_GNUC_MALLOC;
110
111 GDateTime *     gst_date_time_to_g_date_time       (GstDateTime * datetime);
112
113 GstDateTime *   gst_date_time_new_from_g_date_time (GDateTime * dt);
114
115 /* refcounting */
116
117 GstDateTime *   gst_date_time_ref                (GstDateTime * datetime);
118
119 void            gst_date_time_unref              (GstDateTime * datetime);
120
121 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
122 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstDateTime, gst_date_time_unref)
123 #endif
124
125 G_END_DECLS
126
127 #endif /* __GST_DATE_TIME_H__ */