os/ossrv/ofdbus/dbus-glib/tsrc/testapps/file-transfer-server/src/file-transfer-server.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ofdbus/dbus-glib/tsrc/testapps/file-transfer-server/src/file-transfer-server.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,175 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <string.h>
    1.23 +#include <sys/stat.h>
    1.24 +#include <stdio.h>
    1.25 +#include <stdlib.h>
    1.26 +#include "file-transfer-server.h"
    1.27 +#include "file_send-glue.h"
    1.28 +#include <dbus/dbus-glib-bindings.h>
    1.29 +#include <errno.h>
    1.30 +
    1.31 +
    1.32 +static GObjectClass *parent_class = ((void *)0);
    1.33 +static void some_object_init (SomeObject *self);
    1.34 +
    1.35 +char *FILENAME = "c:/bunbask1.jpg";
    1.36 +int SIZE = (4*1024);
    1.37 +
    1.38 +gboolean some_object_method1_impl (SomeObject *self, gint a, GArray *y,gint *z,GError **error)
    1.39 +{
    1.40 +	*z = a;
    1.41 +	
    1.42 +	return TRUE;
    1.43 +}
    1.44 +
    1.45 +void some_object_method2_impl (SomeObject *self, gchar* b)
    1.46 +{
    1.47 +	self->m_b = b;
    1.48 +	g_print ("Method2: %s\n", self->m_b);
    1.49 +}
    1.50 +
    1.51 +
    1.52 +/* Public methods. */
    1.53 +gboolean some_object_method1 (SomeObject *self, gint a,GArray *y,gint *z,GError **error)
    1.54 +{
    1.55 +	return SOME_OBJECT_GET_CLASS (self)->method1 (self, a,y,z,error);
    1.56 +}
    1.57 +
    1.58 +void	some_object_method2 (SomeObject *self, gchar* b)
    1.59 +{
    1.60 +	SOME_OBJECT_GET_CLASS (self)->method2 (self, b);
    1.61 +}
    1.62 +
    1.63 +void	some_object_method3 (SomeObject *self, gfloat c)
    1.64 +{
    1.65 +	self->m_c = c;
    1.66 +	g_print ("Method3: %f\n", self->m_c);
    1.67 +}
    1.68 +
    1.69 +
    1.70 +void	some_object_dispose (GObject *self)
    1.71 +{
    1.72 +	static gboolean first_run = TRUE;
    1.73 +
    1.74 +	if (first_run)
    1.75 +	{
    1.76 +		first_run = FALSE;
    1.77 +		
    1.78 +		/* Call g_object_unref on any GObjects that we hold, but don't break the object */
    1.79 +
    1.80 +		parent_class-> dispose (self);
    1.81 +	}
    1.82 +}
    1.83 +
    1.84 +void	some_object_finalize (GObject *self)
    1.85 +{
    1.86 +	parent_class-> finalize (self);
    1.87 +}
    1.88 +
    1.89 +/* Here is where we override any functions. Since we have no properties or even fields, none of the below are needed. */
    1.90 +void	some_object_class_init		(gpointer g_class, gpointer class_data)
    1.91 +{
    1.92 +	GObjectClass	*object_class	= G_OBJECT_CLASS (g_class);
    1.93 +	SomeObjectClass	*this_class	= SOME_OBJECT_CLASS (g_class);
    1.94 +	
    1.95 +	//assign value to parent class
    1.96 +	parent_class = g_type_class_peek_parent (g_class);
    1.97 +	
    1.98 +	//assing pointer values to the base class members
    1.99 +	object_class-> dispose = &some_object_dispose;
   1.100 +	object_class-> finalize = &some_object_finalize;
   1.101 +	
   1.102 +	//assign value to derived class members
   1.103 +	this_class->method1 = &some_object_method1_impl;
   1.104 +	this_class->method2 = &some_object_method2_impl;
   1.105 +
   1.106 +	dbus_g_object_type_install_info(G_TYPE_FROM_CLASS(this_class),&dbus_glib__object_info);
   1.107 +}
   1.108 +
   1.109 +void some_object_init (SomeObject *self)
   1.110 +{
   1.111 +	self->m_a = 1;
   1.112 +	self->m_c = 1.03f;
   1.113 +	self->m_b = "sumit";
   1.114 +}
   1.115 +
   1.116 +GType some_object_get_type () 
   1.117 +{
   1.118 +	static GType g_define_type_id = 0; 
   1.119 +	if ((g_define_type_id == 0)) 
   1.120 +	{ 
   1.121 +		static const GTypeInfo g_define_type_info = 
   1.122 +		{ 
   1.123 +			sizeof (SomeObjectClass), 
   1.124 +			(GBaseInitFunc) ((void *)0), 
   1.125 +			(GBaseFinalizeFunc) ((void *)0), 
   1.126 +			(GClassInitFunc) some_object_class_init, 
   1.127 +			(GClassFinalizeFunc) ((void *)0), 
   1.128 +			((void *)0), 
   1.129 +			sizeof (SomeObject), 
   1.130 +			0, 
   1.131 +			(GInstanceInitFunc) some_object_init, 
   1.132 +		}; 
   1.133 +
   1.134 +		g_define_type_id = g_type_register_static 
   1.135 +		(
   1.136 +			G_TYPE_OBJECT, 
   1.137 +			"SomeObject", 
   1.138 +			&g_define_type_info, 
   1.139 +			(GTypeFlags) 0
   1.140 +		);
   1.141 +		
   1.142 +	} 
   1.143 +
   1.144 +	return g_define_type_id; 
   1.145 +}
   1.146 +
   1.147 +int main()
   1.148 +{
   1.149 +	SomeObject *so = NULL;
   1.150 +	DBusGConnection *bus;
   1.151 +	GMainLoop *mainLoop = NULL;
   1.152 +	unsigned int request_ret;
   1.153 +	GError *error = NULL;
   1.154 +
   1.155 +	DBusGProxy *proxy = NULL;
   1.156 +	
   1.157 +	g_type_init();
   1.158 +
   1.159 +	so = g_object_new(SOME_OBJECT_TYPE,NULL);
   1.160 +
   1.161 +	bus = dbus_g_bus_get(DBUS_BUS_SESSION,NULL);
   1.162 +
   1.163 +	proxy = dbus_g_proxy_new_for_name(bus,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS);
   1.164 +
   1.165 +	dbus_g_connection_register_g_object(bus,"/com/example/SomeObject",G_OBJECT(so));
   1.166 +
   1.167 +	if(!org_freedesktop_DBus_request_name(proxy,"com.example.SomeObject",0,&request_ret,&error))
   1.168 +	{
   1.169 +		g_print("Unable to register service\n");
   1.170 +		return 1;
   1.171 +	}
   1.172 +
   1.173 +	mainLoop = g_main_loop_new(NULL,FALSE);
   1.174 +	g_main_loop_run(mainLoop);
   1.175 +	
   1.176 +	return 0;
   1.177 +}
   1.178 +