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