os/ossrv/ofdbus/dbus-glib/tsrc/testapps/file-transfer-server/src/file-transfer-server.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <string.h>
sl@0
    20
#include <sys/stat.h>
sl@0
    21
#include <stdio.h>
sl@0
    22
#include <stdlib.h>
sl@0
    23
#include "file-transfer-server.h"
sl@0
    24
#include "file_send-glue.h"
sl@0
    25
#include <dbus/dbus-glib-bindings.h>
sl@0
    26
#include <errno.h>
sl@0
    27
sl@0
    28
sl@0
    29
static GObjectClass *parent_class = ((void *)0);
sl@0
    30
static void some_object_init (SomeObject *self);
sl@0
    31
sl@0
    32
char *FILENAME = "c:/bunbask1.jpg";
sl@0
    33
int SIZE = (4*1024);
sl@0
    34
sl@0
    35
gboolean some_object_method1_impl (SomeObject *self, gint a, GArray *y,gint *z,GError **error)
sl@0
    36
{
sl@0
    37
	*z = a;
sl@0
    38
	
sl@0
    39
	return TRUE;
sl@0
    40
}
sl@0
    41
sl@0
    42
void some_object_method2_impl (SomeObject *self, gchar* b)
sl@0
    43
{
sl@0
    44
	self->m_b = b;
sl@0
    45
	g_print ("Method2: %s\n", self->m_b);
sl@0
    46
}
sl@0
    47
sl@0
    48
sl@0
    49
/* Public methods. */
sl@0
    50
gboolean some_object_method1 (SomeObject *self, gint a,GArray *y,gint *z,GError **error)
sl@0
    51
{
sl@0
    52
	return SOME_OBJECT_GET_CLASS (self)->method1 (self, a,y,z,error);
sl@0
    53
}
sl@0
    54
sl@0
    55
void	some_object_method2 (SomeObject *self, gchar* b)
sl@0
    56
{
sl@0
    57
	SOME_OBJECT_GET_CLASS (self)->method2 (self, b);
sl@0
    58
}
sl@0
    59
sl@0
    60
void	some_object_method3 (SomeObject *self, gfloat c)
sl@0
    61
{
sl@0
    62
	self->m_c = c;
sl@0
    63
	g_print ("Method3: %f\n", self->m_c);
sl@0
    64
}
sl@0
    65
sl@0
    66
sl@0
    67
void	some_object_dispose (GObject *self)
sl@0
    68
{
sl@0
    69
	static gboolean first_run = TRUE;
sl@0
    70
sl@0
    71
	if (first_run)
sl@0
    72
	{
sl@0
    73
		first_run = FALSE;
sl@0
    74
		
sl@0
    75
		/* Call g_object_unref on any GObjects that we hold, but don't break the object */
sl@0
    76
sl@0
    77
		parent_class-> dispose (self);
sl@0
    78
	}
sl@0
    79
}
sl@0
    80
sl@0
    81
void	some_object_finalize (GObject *self)
sl@0
    82
{
sl@0
    83
	parent_class-> finalize (self);
sl@0
    84
}
sl@0
    85
sl@0
    86
/* Here is where we override any functions. Since we have no properties or even fields, none of the below are needed. */
sl@0
    87
void	some_object_class_init		(gpointer g_class, gpointer class_data)
sl@0
    88
{
sl@0
    89
	GObjectClass	*object_class	= G_OBJECT_CLASS (g_class);
sl@0
    90
	SomeObjectClass	*this_class	= SOME_OBJECT_CLASS (g_class);
sl@0
    91
	
sl@0
    92
	//assign value to parent class
sl@0
    93
	parent_class = g_type_class_peek_parent (g_class);
sl@0
    94
	
sl@0
    95
	//assing pointer values to the base class members
sl@0
    96
	object_class-> dispose = &some_object_dispose;
sl@0
    97
	object_class-> finalize = &some_object_finalize;
sl@0
    98
	
sl@0
    99
	//assign value to derived class members
sl@0
   100
	this_class->method1 = &some_object_method1_impl;
sl@0
   101
	this_class->method2 = &some_object_method2_impl;
sl@0
   102
sl@0
   103
	dbus_g_object_type_install_info(G_TYPE_FROM_CLASS(this_class),&dbus_glib__object_info);
sl@0
   104
}
sl@0
   105
sl@0
   106
void some_object_init (SomeObject *self)
sl@0
   107
{
sl@0
   108
	self->m_a = 1;
sl@0
   109
	self->m_c = 1.03f;
sl@0
   110
	self->m_b = "sumit";
sl@0
   111
}
sl@0
   112
sl@0
   113
GType some_object_get_type () 
sl@0
   114
{
sl@0
   115
	static GType g_define_type_id = 0; 
sl@0
   116
	if ((g_define_type_id == 0)) 
sl@0
   117
	{ 
sl@0
   118
		static const GTypeInfo g_define_type_info = 
sl@0
   119
		{ 
sl@0
   120
			sizeof (SomeObjectClass), 
sl@0
   121
			(GBaseInitFunc) ((void *)0), 
sl@0
   122
			(GBaseFinalizeFunc) ((void *)0), 
sl@0
   123
			(GClassInitFunc) some_object_class_init, 
sl@0
   124
			(GClassFinalizeFunc) ((void *)0), 
sl@0
   125
			((void *)0), 
sl@0
   126
			sizeof (SomeObject), 
sl@0
   127
			0, 
sl@0
   128
			(GInstanceInitFunc) some_object_init, 
sl@0
   129
		}; 
sl@0
   130
sl@0
   131
		g_define_type_id = g_type_register_static 
sl@0
   132
		(
sl@0
   133
			G_TYPE_OBJECT, 
sl@0
   134
			"SomeObject", 
sl@0
   135
			&g_define_type_info, 
sl@0
   136
			(GTypeFlags) 0
sl@0
   137
		);
sl@0
   138
		
sl@0
   139
	} 
sl@0
   140
sl@0
   141
	return g_define_type_id; 
sl@0
   142
}
sl@0
   143
sl@0
   144
int main()
sl@0
   145
{
sl@0
   146
	SomeObject *so = NULL;
sl@0
   147
	DBusGConnection *bus;
sl@0
   148
	GMainLoop *mainLoop = NULL;
sl@0
   149
	unsigned int request_ret;
sl@0
   150
	GError *error = NULL;
sl@0
   151
sl@0
   152
	DBusGProxy *proxy = NULL;
sl@0
   153
	
sl@0
   154
	g_type_init();
sl@0
   155
sl@0
   156
	so = g_object_new(SOME_OBJECT_TYPE,NULL);
sl@0
   157
sl@0
   158
	bus = dbus_g_bus_get(DBUS_BUS_SESSION,NULL);
sl@0
   159
sl@0
   160
	proxy = dbus_g_proxy_new_for_name(bus,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS);
sl@0
   161
sl@0
   162
	dbus_g_connection_register_g_object(bus,"/com/example/SomeObject",G_OBJECT(so));
sl@0
   163
sl@0
   164
	if(!org_freedesktop_DBus_request_name(proxy,"com.example.SomeObject",0,&request_ret,&error))
sl@0
   165
	{
sl@0
   166
		g_print("Unable to register service\n");
sl@0
   167
		return 1;
sl@0
   168
	}
sl@0
   169
sl@0
   170
	mainLoop = g_main_loop_new(NULL,FALSE);
sl@0
   171
	g_main_loop_run(mainLoop);
sl@0
   172
	
sl@0
   173
	return 0;
sl@0
   174
}
sl@0
   175