Blame lib/test-class.c

Packit 8fb625
/*
Packit 8fb625
 *
Packit 8fb625
 *  BlueZ - Bluetooth protocol stack for Linux
Packit 8fb625
 *
Packit 8fb625
 *  Copyright (C) 2009  Bastien Nocera <hadess@hadess.net>
Packit 8fb625
 *
Packit 8fb625
 *
Packit 8fb625
 *  This program is free software; you can redistribute it and/or modify
Packit 8fb625
 *  it under the terms of the GNU General Public License as published by
Packit 8fb625
 *  the Free Software Foundation; either version 2 of the License, or
Packit 8fb625
 *  (at your option) any later version.
Packit 8fb625
 *
Packit 8fb625
 *  This program is distributed in the hope that it will be useful,
Packit 8fb625
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8fb625
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8fb625
 *  GNU General Public License for more details.
Packit 8fb625
 *
Packit 8fb625
 *  You should have received a copy of the GNU General Public License
Packit 8fb625
 *  along with this program; if not, write to the Free Software
Packit 8fb625
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
Packit 8fb625
 *
Packit 8fb625
 */
Packit 8fb625
Packit 8fb625
#ifdef HAVE_CONFIG_H
Packit 8fb625
#include <config.h>
Packit 8fb625
#endif
Packit 8fb625
Packit 8fb625
#include <string.h>
Packit 8fb625
#include <gtk/gtk.h>
Packit 8fb625
Packit 8fb625
#include "bluetooth-client.h"
Packit 8fb625
#include "bluetooth-client-private.h"
Packit 8fb625
#include "bluetooth-utils.h"
Packit 8fb625
Packit 8fb625
static const char *
Packit 8fb625
byte_to_binary (int x)
Packit 8fb625
{
Packit 8fb625
	static char b[9] = {0};
Packit 8fb625
Packit 8fb625
	int z;
Packit 8fb625
	for (z = 256; z > 0; z >>= 1) {
Packit 8fb625
		strcat(b, ((x & z) == z) ? "1" : "0");
Packit 8fb625
	}
Packit 8fb625
Packit 8fb625
	return b;
Packit 8fb625
}
Packit 8fb625
Packit 8fb625
int main(int argc, char *argv[])
Packit 8fb625
{
Packit 8fb625
	GLogLevelFlags fatal_mask;
Packit 8fb625
	guint class;
Packit 8fb625
Packit 8fb625
	gtk_init(&argc, &argv);
Packit 8fb625
Packit 8fb625
	fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
Packit 8fb625
	fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
Packit 8fb625
	g_log_set_always_fatal (fatal_mask);
Packit 8fb625
Packit 8fb625
	class = g_ascii_strtoull (argv[1], NULL, 0);
Packit 8fb625
Packit 8fb625
	g_message ("device class: 0x%X", class);
Packit 8fb625
	g_message ("major class: 0x%X %s", (class & 0x1f00) >> 8, byte_to_binary ((class & 0x1f00) >> 8));
Packit 8fb625
Packit 8fb625
	g_message ("%d %s", bluetooth_class_to_type (class), bluetooth_type_to_string (bluetooth_class_to_type (class)));
Packit 8fb625
Packit 8fb625
	return 0;
Packit 8fb625
}