mce-lib.h 2.76 KB
Newer Older
1 2 3 4 5
/**
 * @file mce-lib.h
 * Headers for various helper functions
 * for the Mode Control Entity
 * <p>
Santtu Lakkala's avatar
Santtu Lakkala committed
6
 * Copyright © 2004-2011 Nokia Corporation and/or its subsidiary(-ies).
7
 * Copyright (C) 2014-2019 Jolla Ltd.
8 9
 * <p>
 * @author David Weinehall <david.weinehall@nokia.com>
10 11 12
 * @author Tapio Rantala <ext-tapio.rantala@nokia.com>
 * @author Santtu Lakkala <ext-santtu.1.lakkala@nokia.com>
 * @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * mce is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * mce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with mce.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef _MCE_LIB_H_
#define _MCE_LIB_H_

29 30
#include <stdint.h>

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
#include <glib.h>

/** Find the number of bits of a type */
#define bitsize_of(__x)			(guint)(sizeof (__x) * 8)

/** translation structure */
typedef struct {
	const gint number;		/**< Number representation */
	const gchar *const string;	/**< String representation */
} mce_translation_t;

void set_bit(guint bit, gulong **bitfield);
void clear_bit(guint bit, gulong **bitfield);
gboolean test_bit(guint bit, const gulong *bitfield);

gboolean string_to_bitfield(const gchar *string,
			    gulong **bitfield, gsize bitfieldsize);
char *bitfield_to_string(const gulong *bitfield, gsize bitfieldsize);

const gchar *bin_to_string(guint bin);

const gchar *mce_translate_int_to_string_with_default(const mce_translation_t translation[], gint number, const gchar *default_string);
const gchar *mce_translate_int_to_string(const mce_translation_t translation[],
					 gint number);

gint mce_translate_string_to_int_with_default(const mce_translation_t translation[], const gchar *const string, gint default_number);
gint mce_translate_string_to_int(const mce_translation_t translation[],
				 const gchar *const string);

gchar *strstr_delim(const gchar *const haystack, const char *needle,
		    const char *const delimiter);
Tapio Rantala's avatar
Tapio Rantala committed
62
gboolean strmemcmp(guint8 *mem, const gchar *str, gulong len);
63

64 65 66 67
int64_t mce_lib_get_boot_tick(void);
int64_t mce_lib_get_mono_tick(void);
int64_t mce_lib_get_real_tick(void);

68 69 70 71 72 73 74
guint mce_wakelocked_timeout_add_full(gint priority, guint interval,
				      GSourceFunc function,
				      gpointer data, GDestroyNotify notify);
guint mce_wakelocked_timeout_add(guint interval, GSourceFunc function,
				 gpointer data);
guint mce_wakelocked_idle_add(GSourceFunc function, gpointer data);

75
#endif /* _MCE_LIB_H_ */