Mercurial > projects > dbus-d
comparison dbus-d/dsrc/org/freedesktop/dbus/DBus.d @ 11:44c987465a20
fixed assertion error for open_container
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 09 Nov 2007 16:17:32 +0100 |
parents | 963d271f7c25 |
children |
comparison
equal
deleted
inserted
replaced
10:19117ffaee67 | 11:44c987465a20 |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007 Frank Benoit | 2 * Copyright (C) 2007 Frank Benoit |
3 * | 3 * |
4 * Licensed under the Academic Free License version 2.1 | 4 * Licensed under the Academic Free License version 2.1 |
5 * | 5 * |
6 * This program is free software; you can redistribute it and/or modify | 6 * This program is free software; you can redistribute it and/or modify |
7 * it under the terms of the GNU General Public License as published by | 7 * it under the terms of the GNU General Public License as published by |
8 * the Free Software Foundation; either version 2 of the License, or | 8 * the Free Software Foundation; either version 2 of the License, or |
9 * (at your option) any later version. | 9 * (at your option) any later version. |
10 * | 10 * |
11 * This program is distributed in the hope that it will be useful, | 11 * This program is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 * GNU General Public License for more details. | 14 * GNU General Public License for more details. |
15 * | 15 * |
16 * You should have received a copy of the GNU General Public License | 16 * You should have received a copy of the GNU General Public License |
17 * along with this program; if not, write to the Free Software | 17 * along with this program; if not, write to the Free Software |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 * | 19 * |
20 */ | 20 */ |
198 bool[ DBusObjectImpl ] objectLocker; | 198 bool[ DBusObjectImpl ] objectLocker; |
199 | 199 |
200 | 200 |
201 class DBusConnectionImpl { | 201 class DBusConnectionImpl { |
202 DBusConnection* conn; | 202 DBusConnection* conn; |
203 | 203 |
204 public this( char[] addr ){ | 204 public this( char[] addr ){ |
205 DBusError err; | 205 DBusError err; |
206 int trial = 0; | 206 int trial = 0; |
207 while( true ){ | 207 while( true ){ |
208 trial++; | 208 trial++; |
209 dbus_error_init(&err); | 209 dbus_error_init(&err); |
210 | 210 |
211 scope(exit) | 211 scope(exit) |
212 if( dbus_error_is_set(&err) ){ | 212 if( dbus_error_is_set(&err) ){ |
213 dbus_error_free(&err); | 213 dbus_error_free(&err); |
214 } | 214 } |
215 | 215 |
216 conn = dbus_connection_open_private( XtoUtf8z(addr), & err ); | 216 conn = dbus_connection_open_private( XtoUtf8z(addr), & err ); |
217 | 217 |
218 if( !dbus_error_is_set(&err) && conn !is null ){ | 218 if( !dbus_error_is_set(&err) && conn !is null ){ |
219 return; | 219 return; |
220 } | 220 } |
221 if( trial > 10 ){ | 221 if( trial > 10 ){ |
222 if( dbus_error_is_set(&err) ){ | 222 if( dbus_error_is_set(&err) ){ |
223 Stdout.formatln( "Connect Error ({})\n", fromUtf8z( err.message)); | 223 Stdout.formatln( "Connect Error ({})\n", fromUtf8z( err.message)); |
224 throw new Exception(""); | 224 throw new Exception(""); |
225 } | 225 } |
226 if( conn is null ){ | 226 if( conn is null ){ |
227 throw new IOException("connecting not successful"); | 227 throw new IOException("connecting not successful"); |
228 } | 228 } |
230 else{ | 230 else{ |
231 Thread.sleep( 0.1 ); | 231 Thread.sleep( 0.1 ); |
232 } | 232 } |
233 } | 233 } |
234 } | 234 } |
235 | 235 |
236 /+ public DBusInterface getRemoteObject( char[] path ){ | 236 /+ public DBusInterface getRemoteObject( char[] path ){ |
237 return null; | 237 return null; |
238 }+/ | 238 }+/ |
239 public void mainLoop(){ | 239 public void mainLoop(){ |
240 //Stdout.formatln( " D mainloop starting" ); | 240 //Stdout.formatln( " D mainloop starting" ); |
247 | 247 |
248 DBusError err; | 248 DBusError err; |
249 dbus_error_init(&err); | 249 dbus_error_init(&err); |
250 //CBus.dbus_bus_request_name(conn, XtoUtf8z("test.method.caller"), DBUS_NAME_FLAG_REPLACE_EXISTING , &err); | 250 //CBus.dbus_bus_request_name(conn, XtoUtf8z("test.method.caller"), DBUS_NAME_FLAG_REPLACE_EXISTING , &err); |
251 if( dbus_error_is_set(&err) ){ | 251 if( dbus_error_is_set(&err) ){ |
252 Stdout.formatln( "Name Error ({})\n", fromUtf8z( err.message)); | 252 Stdout.formatln( "Name Error ({})\n", fromUtf8z( err.message)); |
253 dbus_error_free(&err); | 253 dbus_error_free(&err); |
254 throw new Exception(""); | 254 throw new Exception(""); |
255 } | 255 } |
256 } | 256 } |
257 public void disconnect(){ | 257 public void disconnect(){ |
510 appendMsgParam( conn, &sub, v.value ); | 510 appendMsgParam( conn, &sub, v.value ); |
511 } | 511 } |
512 | 512 |
513 else if( DBusVariantStruct v = cast(DBusVariantStruct)value ){ | 513 else if( DBusVariantStruct v = cast(DBusVariantStruct)value ){ |
514 DBusMessageIter sub2; | 514 DBusMessageIter sub2; |
515 ensureDBus( dbus_message_iter_open_container( &sub, DBUS_TYPE_STRUCT, XtoUtf8z( v.getSig() ), &sub2 )); | 515 // open_cont: if type=STRUCT => sig shall be null |
516 ensureDBus( dbus_message_iter_open_container( &sub, DBUS_TYPE_STRUCT, null/*XtoUtf8z( v.getSig() )*/, &sub2 )); | |
516 foreach( el; v.values ){ | 517 foreach( el; v.values ){ |
517 appendMsgParamVariant( conn, &sub2, el ); | 518 appendMsgParamVariant( conn, &sub2, el ); |
518 } | 519 } |
519 ensureDBus( dbus_message_iter_close_container( &sub, &sub2 )); | 520 ensureDBus( dbus_message_iter_close_container( &sub, &sub2 )); |
520 } | 521 } |
537 ensureDBus( dbus_message_iter_close_container( &sub2, &el )); | 538 ensureDBus( dbus_message_iter_close_container( &sub2, &el )); |
538 } | 539 } |
539 ensureDBus( dbus_message_iter_close_container( &sub, &sub2 )); | 540 ensureDBus( dbus_message_iter_close_container( &sub, &sub2 )); |
540 } | 541 } |
541 else{ | 542 else{ |
542 Stdout.formatln( "appendMsgParamVariant not handled case for sig: {}", value.getSig() ).flush(); | 543 Stdout.formatln( "appendMsgParamVariant not handled case for sig: {}", value.getSig() ).flush(); |
543 ensure( false, "appendMsgParamVariant not handled case for sig: %0", value.getSig() ); | 544 ensure( false, "appendMsgParamVariant not handled case for sig: %0", value.getSig() ); |
544 } | 545 } |
545 ensureDBus( dbus_message_iter_close_container( iter, &sub )); | 546 ensureDBus( dbus_message_iter_close_container( iter, &sub )); |
546 } | 547 } |
547 | 548 |
557 } | 558 } |
558 | 559 |
559 void appendMsgParamStruct( T... )( DBusConnection* conn, DBusMessageIter* iter, T t ){ | 560 void appendMsgParamStruct( T... )( DBusConnection* conn, DBusMessageIter* iter, T t ){ |
560 //pragma( msg, "appendMsgParamStruct: "~typeof(T).stringof ); | 561 //pragma( msg, "appendMsgParamStruct: "~typeof(T).stringof ); |
561 DBusMessageIter sub; | 562 DBusMessageIter sub; |
562 ensureDBus( dbus_message_iter_open_container( iter, DBUS_TYPE_STRUCT, XtoUtf8z( createDBusSignature!(T)), &sub )); | 563 // open_cont: if type=STRUCT => sig shall be null |
564 ensureDBus( dbus_message_iter_open_container( iter, DBUS_TYPE_STRUCT, null, &sub )); | |
563 foreach( item; t ){ | 565 foreach( item; t ){ |
564 appendItem( conn, &sub, item ); | 566 appendItem( conn, &sub, item ); |
565 } | 567 } |
566 ensureDBus( dbus_message_iter_close_container( iter, &sub )); | 568 ensureDBus( dbus_message_iter_close_container( iter, &sub )); |
567 } | 569 } |
798 char[] name = fromUtf8z( dbus_message_get_member(message)); | 800 char[] name = fromUtf8z( dbus_message_get_member(message)); |
799 if( buf.length < name.length ){ | 801 if( buf.length < name.length ){ |
800 buf.length = name.length; | 802 buf.length = name.length; |
801 } | 803 } |
802 buf[ 0 .. name.length ] = name; | 804 buf[ 0 .. name.length ] = name; |
803 | 805 |
804 char[] sig = fromUtf8z( dbus_message_get_signature(message)); | 806 char[] sig = fromUtf8z( dbus_message_get_signature(message)); |
805 int sz = name.length+sig.length+1; | 807 int sz = name.length+sig.length+1; |
806 if( buf.length < sz ){ | 808 if( buf.length < sz ){ |
807 buf.length= sz; | 809 buf.length= sz; |
808 } | 810 } |
1103 getVariantAsKnownType!( DBusVariant[ DBusVariant ] )( null ); | 1105 getVariantAsKnownType!( DBusVariant[ DBusVariant ] )( null ); |
1104 getVariantAsKnownType!( Struct!( int[], long, char[], Struct!( bool ) ) )( null ); | 1106 getVariantAsKnownType!( Struct!( int[], long, char[], Struct!( bool ) ) )( null ); |
1105 } | 1107 } |
1106 | 1108 |
1107 | 1109 |
1108 /** | 1110 /** |
1109 * this function shall be used like so: | 1111 * this function shall be used like so: |
1110 * --- | 1112 * --- |
1111 * mixin( createJavaImplementation( "MyClass", ["I1", "I2" ] )); | 1113 * mixin( createJavaImplementation( "MyClass", ["I1", "I2" ] )); |
1112 * --- | 1114 * --- |
1113 * This creates a simple standard implementation by generating code in this form: | 1115 * This creates a simple standard implementation by generating code in this form: |