/* diversity-world.h - DiversityWorld * * Copyright 2007-2008 OpenMoko, Inc. * Authored by Chia-I Wu * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _DIVERSITY_WORLD_H_ #define _DIVERSITY_WORLD_H_ #define G_DISABLE_CAST_CHECKS #include #include #include #include #include G_BEGIN_DECLS #define DIVERSITY_TYPE_WORLD (diversity_world_get_type()) #define DIVERSITY_WORLD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), DIVERSITY_TYPE_WORLD, DiversityWorld)) #define DIVERSITY_WORLD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), DIVERSITY_TYPE_WORLD, DiversityWorldClass)) #define DIVERSITY_IS_WORLD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), DIVERSITY_TYPE_WORLD)) #define DIVERSITY_IS_WORLD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), DIVERSITY_TYPE_WORLD)) #define DIVERSITY_WORLD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), DIVERSITY_TYPE_WORLD, DiversityWorldClass)) typedef struct _DiversityWorld DiversityWorld; typedef struct _DiversityWorldClass DiversityWorldClass; struct _DiversityWorld { GObject parent_object; }; struct _DiversityWorldClass { GObjectClass parent_class; void (*state_changed)(DiversityWorld *world, gint state); void (*object_added)(DiversityWorld *world, DiversityObject *obj); void (*object_removed)(DiversityWorld *world, DiversityObject *obj); void (*viewport_added)(DiversityWorld *world, DiversityViewport *view); void (*viewport_removed)(DiversityWorld *world, DiversityViewport *view); void (*tunneled_changed)(DiversityWorld *world, gboolean tunneled); }; GType diversity_world_get_type(void) G_GNUC_CONST; void diversity_world_add_object(DiversityWorld *world, DiversityObject *obj); void diversity_world_remove_object(DiversityWorld *world, DiversityObject *obj); DiversityObject *diversity_world_lookup_object(DiversityWorld *world, DiversityObjectType type, const gchar *id); void diversity_world_add_viewport(DiversityWorld *world, DiversityViewport *view); void diversity_world_remove_viewport(DiversityWorld *world, DiversityViewport *view); DiversityBard *diversity_world_get_self(DiversityWorld *world); void diversity_world_get_position(DiversityWorld *world, gdouble *lon, gdouble *lat); void diversity_world_set_tunnel(DiversityWorld *world, const gchar *tunnel); const gchar *diversity_world_get_tunnel(DiversityWorld *world); void diversity_world_set_tunneled(DiversityWorld *world, gboolean tunneled); gboolean diversity_world_get_tunneled(DiversityWorld *world); void diversity_world_connect_ap(DiversityWorld *world, DiversityAp *ap); void diversity_world_connect_wired(DiversityWorld *world); void diversity_world_sleep(DiversityWorld *world, gboolean sleep); /* ugly stuff */ typedef struct _DiversityNetwork DiversityNetwork; typedef enum _DiversityNetworkState DiversityNetworkState; enum _DiversityNetworkState { DIVERSITY_NETWORK_STATE_UNKNOWN, DIVERSITY_NETWORK_STATE_DISCONNECTED, DIVERSITY_NETWORK_STATE_CONNECTED, DIVERSITY_NETWORK_STATE_CONNECTING, DIVERSITY_NETWORK_STATE_ASLEEP, }; typedef enum _DiveristyNetworkDetail DiversityNetworkDetail; enum _DiveristyNetworkDetail { DIVERSITY_NETWORK_DETAIL_UNKNOWN, DIVERSITY_NETWORK_DETAIL_DOWN, DIVERSITY_NETWORK_DETAIL_DISCONNECTED, DIVERSITY_NETWORK_DETAIL_PREPARE, DIVERSITY_NETWORK_DETAIL_CONFIG, DIVERSITY_NETWORK_DETAIL_NEED_AUTH, DIVERSITY_NETWORK_DETAIL_IP_CONFIG, DIVERSITY_NETWORK_DETAIL_ACTIVATED, DIVERSITY_NETWORK_DETAIL_FAILED, DIVERSITY_NETWORK_DETAIL_CANCELLED, }; #define DIVERSITY_NETWORK_WIRED(net) \ (((net)->state == DIVERSITY_NETWORK_STATE_CONNECTED || \ (net)->state == DIVERSITY_NETWORK_STATE_CONNECTING) && \ !(net)->ap) struct _DiversityNetwork { gboolean has_wired; gboolean has_wireless; DiversityNetworkState state; DiversityNetworkDetail detail; DiversityAp *ap; void (*connect_ap)(DiversityNetwork *network, DiversityAp *ap); void (*connect_wired)(DiversityNetwork *network); void (*sleep)(DiversityNetwork *network, gboolean s); gpointer data; }; const DiversityNetwork *diversity_world_network_get(DiversityWorld *world); void diversity_world_network_set_capabilities(DiversityWorld *world, gboolean has_wired, gboolean has_wireless); void diversity_world_network_set_state(DiversityWorld *world, DiversityNetworkState state); void diversity_world_network_set_detail(DiversityWorld *world, DiversityNetworkDetail detail); void diversity_world_network_set_ap(DiversityWorld *world, DiversityAp *ap); void diversity_world_network_set_interface(DiversityWorld *world, gpointer connect_ap, gpointer connect_wired, gpointer sleep, gpointer data); G_END_DECLS #endif /* _DIVERSITY_WORLD_H_ */