public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [Bluez-users] Cant receive signals from Adapter (low-level dbus API)
@ 2008-05-20  8:04 Fritz Code
  2008-05-20 11:28 ` Fritz Code
  0 siblings, 1 reply; 3+ messages in thread
From: Fritz Code @ 2008-05-20  8:04 UTC (permalink / raw)
  To: bluez-users


[-- Attachment #1.1: Type: text/plain, Size: 679 bytes --]

Hi,

attached is a small test application.
With this application I want to test the handling of signals from bluez
Adapter.
Therefore I always change the name of my bluetooth device, in order to make
the adapter to
generate a signal.
Unfortunately I cant receive this signal.
I can set and get the name correctly.
BUt it seems I receive at least some signals:
When I start the application I get a signal with value :1.20
If I remove my usb bluetooth dongle I get a signal with value off.




In another application I had the same problem (receiving not the expected
signals: e.g.: DiscoveryStarted() ... )
 when I sent signal DiscoverDevices.


thanks.

-- 
Regards,
--Codefritz

[-- Attachment #1.2: Type: text/html, Size: 773 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test.c --]
[-- Type: text/x-csrc; name=test.c, Size: 4586 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <dbus/dbus.h>


int main(int argc, char **argv)
{
    DBusConnection *conn;
    DBusMessage *msg, *reply;
    DBusError err;
    DBusMessageIter args;
    const char *addr;
    const char *name;
    const char *manuf;
    void *sigvalue;

    char dispMsg[10];
    char *names[5] = { "test1", "test2", "test3", "test4", "test5"};

    int i=0;

    dbus_error_init(&err);

    printf("Connecting to the bus ...\n");
    conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
    if (dbus_error_is_set(&err)) { 
      fprintf(stderr, "Connection Error (%s)\n", err.message);
      dbus_error_free(&err); 
   }
    if (NULL == conn) { 
      exit(1);
    }
    
    

    // add a rule for which messages we want to see    
    dbus_bus_add_match(conn, 
 	 	       "type='signal',interface='org.bluez.Adapter'", 
	   	       &err); // see signals from the given interface
    dbus_connection_flush(conn);
    if (dbus_error_is_set(&err)) { 
      fprintf(stderr, "Match Error (%s)\n", err.message);
      exit(1); 
    }    
    
    i=0;

    while (1) {      
      dbus_connection_read_write(conn, 0);
      msg = dbus_connection_pop_message(conn);      

      if (NULL == msg) { 
	printf("GetName():");
	msg = dbus_message_new_method_call("org.bluez", "/org/bluez/hci0",
					   "org.bluez.Adapter", "GetName");
	reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, NULL);
	dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
	printf(" %s\n", name);
	dbus_message_unref(msg);
	dbus_message_unref(reply); 

	if (i==4)
	  i=0;
	  
	printf("SetName(): %s\n", names[i++]);
	msg = dbus_message_new_method_call("org.bluez", "/org/bluez/hci0",
					   "org.bluez.Adapter", "SetName");
	if (!dbus_message_append_args(msg,
				      DBUS_TYPE_STRING, &names[i],				      
				      DBUS_TYPE_INVALID)) {
	  fprintf(stderr, "Ran out of memory while constructing args\n");
	  exit(EXIT_FAILURE);
	}
	dbus_message_set_no_reply(msg, TRUE);	
	if (!dbus_connection_send(conn, msg, NULL)) {
	  fprintf(stderr, "Ran out of memory while queueing message\n");
	  exit(EXIT_FAILURE);
	}
	
	dbus_connection_flush(conn);	
	dbus_message_unref(msg);	
	
	sleep(1);
	continue;
      }
      
      printf("!!got a message!!\n");
      // check if the message is a signal from the correct interface
      // and with the correct name
      //    if (dbus_message_is_signal(msg, "org.bluez.Adapter", "NameChanged")) {
	// read the parameters
	if (!dbus_message_iter_init(msg, &args))
	  fprintf(stderr, "Message has no arguments!\n"); 
	else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
	  fprintf(stderr, "Argument is not string!\n"); 
	else {
	  dbus_message_iter_get_basic(&args, &sigvalue);
	  printf("Got Signal with value %s\n", (char*)sigvalue);
	}
	//      }
      
      // free the message
      dbus_message_unref(msg);
    }      




      return 0;







    /*
    printf("DiscoverDevices():\n");
    msg = dbus_message_new_method_call("org.bluez", "/org/bluez/hci0",
				       "org.bluez.Adapter", "DiscoverDevices");
    if (!dbus_connection_send (conn, msg, NULL))
        fprintf (stderr, "error sending message\n");
    dbus_message_unref(msg);
    dbus_connection_flush(conn);
    */



      /*

    printf("GetAddress():");
    msg = dbus_message_new_method_call("org.bluez", "/org/bluez/hci0",
				       "org.bluez.Adapter", "GetAddress");
    reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, NULL);
    dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &addr, DBUS_TYPE_INVALID);
    printf(" %s\n", addr);
    dbus_message_unref(msg);
    dbus_message_unref(reply); 



    printf("GetManufacturer():");
    msg = dbus_message_new_method_call("org.bluez", "/org/bluez/hci0",
				       "org.bluez.Adapter", "GetManufacturer");
    reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, NULL);
    dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &manuf, DBUS_TYPE_INVALID);
    printf(" %s\n", manuf);
    dbus_message_unref(msg);
    dbus_message_unref(reply); 





    printf("GetName():");
    msg = dbus_message_new_method_call("org.bluez", "/org/bluez/hci0",
                                                   "org.bluez.Adapter", "GetName");
    reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, NULL);
    dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
    printf(" %s\n", name);
    dbus_message_unref(msg);
    dbus_message_unref(reply); 




    dbus_connection_close(conn);

    return 0;*/
}

[-- Attachment #3: Type: text/plain, Size: 230 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

[-- Attachment #4: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-users mailing list
Bluez-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-users

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-05-20 16:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-20  8:04 [Bluez-users] Cant receive signals from Adapter (low-level dbus API) Fritz Code
2008-05-20 11:28 ` Fritz Code
2008-05-20 16:52   ` Fritz Code

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox