Hello community,

here is the log from the commit of package littleb for openSUSE:Factory checked 
in at 2017-08-28 15:33:18
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/littleb (Old)
 and      /work/SRC/openSUSE:Factory/.littleb.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "littleb"

Mon Aug 28 15:33:18 2017 rev:3 rq:519095 version:0.1.2

Changes:
--------
--- /work/SRC/openSUSE:Factory/littleb/littleb.changes  2017-02-05 
18:37:41.807588751 +0100
+++ /work/SRC/openSUSE:Factory/.littleb.new/littleb.changes     2017-08-28 
15:33:25.931540506 +0200
@@ -1,0 +2,6 @@
+Mon Aug 28 10:38:48 UTC 2017 - [email protected]
+
+- Update to version 0.1.2:
+  * Misc small fixes
+
+-------------------------------------------------------------------

Old:
----
  littleb-0.1.1.tar.gz

New:
----
  littleb-0.1.2.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ littleb.spec ++++++
--- /var/tmp/diff_new_pack.XQegGh/_old  2017-08-28 15:33:26.743426360 +0200
+++ /var/tmp/diff_new_pack.XQegGh/_new  2017-08-28 15:33:26.747425798 +0200
@@ -18,7 +18,7 @@
 
 %define         sover 0
 Name:           littleb
-Version:        0.1.1
+Version:        0.1.2
 Release:        0
 Summary:        Bluetooth Low Energy Library
 License:        MIT
@@ -27,7 +27,7 @@
 Source:         
https://github.com/intel-iot-devkit/littleb/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
 BuildRequires:  cmake
 BuildRequires:  gcc-c++
-BuildRequires:  pkg-config
+BuildRequires:  pkgconfig
 BuildRequires:  pkgconfig(libsystemd) >= 221
 
 %description
@@ -80,18 +80,15 @@
 %postun -n lib%{name}%{sover} -p /sbin/ldconfig
 
 %files -n lib%{name}%{sover}
-%defattr(-,root,root)
 %doc COPYING
 %{_libdir}/lib%{name}.so.%{sover}*
 
 %files devel
-%defattr(-,root,root)
 %{_libdir}/lib%{name}.so
 %{_includedir}/%{name}.h
 %{_libdir}/pkgconfig/%{name}.pc
 
 %files examples
-%defattr(-,root,root)
 %doc COPYING
 %{_datadir}/%{name}
 

++++++ littleb-0.1.1.tar.gz -> littleb-0.1.2.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/littleb-0.1.1/CMakeLists.txt 
new/littleb-0.1.2/CMakeLists.txt
--- old/littleb-0.1.1/CMakeLists.txt    2016-08-24 21:35:01.000000000 +0200
+++ new/littleb-0.1.2/CMakeLists.txt    2017-08-08 15:49:35.000000000 +0200
@@ -31,7 +31,7 @@
 git_describe (VERSION "--tags")
 if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL 
"x_HEAD-HASH-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
   message (WARNING " - Install git to compile a production liblittleb!")
-  set (VERSION "v0.1.0")
+  set (VERSION "v0.1.2")
 endif ()
 
 message (STATUS "INFO - liblittleb Version ${VERSION}")
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/littleb-0.1.1/api/littleb.h 
new/littleb-0.1.2/api/littleb.h
--- old/littleb-0.1.1/api/littleb.h     2016-08-24 21:35:01.000000000 +0200
+++ new/littleb-0.1.2/api/littleb.h     2017-08-08 15:49:35.000000000 +0200
@@ -74,7 +74,6 @@
     int services_size;         /**< count of services in the device */
 } lb_bl_device;
 
-typedef struct bl_context* lb_context;
 
 /**
  * Initialize littleb.
@@ -93,169 +92,135 @@
 lb_result_t lb_destroy();
 
 /**
- * Create new littleb context to contain devices found
- *
- * @param ADD
- * @return new lb_context or NULL if failed
- */
-lb_context lb_context_new();
-
-/**
- * Free littleb context created with lb_context_new
- *
- * @param lb_context to be freed
- * @return Result of operation
- */
-lb_result_t lb_context_free(lb_context lb_ctx);
-
-/**
  * Populate internal list of bl devices found in a scan of specified length
  *
- * @param lb_context to use
  * @param seconds to perform device scan
  * @return Result of operation
  */
-lb_result_t lb_get_bl_devices(lb_context lb_ctx, int seconds);
+lb_result_t lb_get_bl_devices(int seconds);
 
 /**
  * Connect to a specific bluetooth device
  *
  * lb_bl_device can be found by name, path or address using lb_get_device 
functions
  *
- * @param lb_context to use
  * @param lb_bl_device to connect to
  * @return Result of operation
  */
-lb_result_t lb_connect_device(lb_context lb_ctx, lb_bl_device* dev);
+lb_result_t lb_connect_device(lb_bl_device* dev);
 
 /**
  * Disconnect from a specific bluetooth device
  *
- * @param lb_context to use
  * @param lb_bl_device to disconnect from
  * @return Result of operation
  */
-lb_result_t lb_disconnect_device(lb_context lb_ctx, lb_bl_device* dev);
+lb_result_t lb_disconnect_device(lb_bl_device* dev);
 
 /**
  * Pair with specific bluetooth device
  *
- * @param lb_context to use
  * @param lb_bl_device to pair with
  * @return Result of operation
  */
-lb_result_t lb_pair_device(lb_context lb_ctx, lb_bl_device* dev);
+lb_result_t lb_pair_device(lb_bl_device* dev);
 
 /**
  * Cancel pairing with specific bluetooth device
  *
- * @param lb_context to use
  * @param lb_bl_device to cancel pair with
  * @return Result of operation
  */
-lb_result_t lb_unpair_device(lb_context lb_ctx, lb_bl_device* dev);
+lb_result_t lb_unpair_device(lb_bl_device* dev);
 
 /**
  * Populate ble_char with characteristic found by using it's device path under 
dbus
  *
- * @param lb_context to use
  * @param bl_dev to search the characteristic in
  * @param characteristic_path to search for
  * @param ble_char to populate with characteristic found
  * @return Result of operation
  */
-lb_result_t lb_get_ble_characteristic_by_characteristic_path(lb_context lb_ctx,
-                                                             lb_bl_device* dev,
+lb_result_t lb_get_ble_characteristic_by_characteristic_path(lb_bl_device* dev,
                                                              const char* 
characteristic_path,
                                                              lb_ble_char** 
ble_characteristic_ret);
 
 /**
  * Populate ble_char with characteristic found by using it's uuid
  *
- * @param lb_context to use
  * @param bl_dev to search the characteristic in
  * @param uuid to search for
  * @param ble_char to populate with characteristic found
  * @return Result of operation
  */
-lb_result_t lb_get_ble_characteristic_by_uuid(lb_context lb_ctx,
-                                              lb_bl_device* dev,
+lb_result_t lb_get_ble_characteristic_by_uuid(lb_bl_device* dev,
                                               const char* uuid,
                                               lb_ble_char** 
ble_characteristic_ret);
 
 /**
  * Populate ble_service with service found by using it's device path under dbus
  *
- * @param lb_context to use
  * @param bl_dev to search the service in
  * @param service_path to search for
  * @param ble_service to populate with service found
  * @return Result of operation
  */
-lb_result_t lb_get_ble_service_by_service_path(lb_context lb_ctx,
-                                               lb_bl_device* dev,
+lb_result_t lb_get_ble_service_by_service_path(lb_bl_device* dev,
                                                const char* service_path,
                                                lb_ble_service** 
ble_service_ret);
 
 /**
  * Populate ble_service with service found by using it's uuid
  *
- * @param lb_context to use
  * @param bl_dev to search the service in
  * @param uuid to search for
  * @param ble_service to populate with service found
  * @return Result of operation
  */
-lb_result_t lb_get_ble_service_by_uuid(lb_context lb_ctx,
-                                       lb_bl_device* dev,
+lb_result_t lb_get_ble_service_by_uuid(lb_bl_device* dev,
                                        const char* uuid,
                                        lb_ble_service** ble_service_ret);
 
 /**
  * Populate the BLE device with it's services
  *
- * @param lb_context to use
  * @param bl_dev to scan services
  * @return Result of operation
  */
-lb_result_t lb_get_ble_device_services(lb_context lb_ctx, lb_bl_device* dev);
+lb_result_t lb_get_ble_device_services(lb_bl_device* dev);
 
 /**
  * Get bluetooth device by using it's device path under dbus
  *
- * @param lb_context to use
  * @param device_path to search for
  * @param lb_bl_device_ret to populate with the found device
  * @return Result of operation
  */
-lb_result_t lb_get_device_by_device_path(lb_context lb_ctx, const char* 
device_path, lb_bl_device** bl_device_ret);
+lb_result_t lb_get_device_by_device_path(const char* device_path, 
lb_bl_device** bl_device_ret);
 
 /**
  * Get bluetooth device by searching for specific name
  *
  * Will return the first found device with the name specified
  *
- * @param lb_context to use
  * @param name to search for
  * @param lb_bl_device_ret to populate with the found device
  * @return Result of operation
  */
-lb_result_t lb_get_device_by_device_name(lb_context lb_ctx, const char* name, 
lb_bl_device** bl_device_ret);
+lb_result_t lb_get_device_by_device_name(const char* name, lb_bl_device** 
bl_device_ret);
 
 /**
  * Get bluetooth device by searching for specific address
  *
- * @param lb_context to use
  * @param address to search for
  * @param lb_bl_device_ret to populate with the found device
  * @return Result of operation
  */
-lb_result_t lb_get_device_by_device_address(lb_context lb_ctx, const char* 
address, lb_bl_device** bl_device_ret);
+lb_result_t lb_get_device_by_device_address(const char* address, 
lb_bl_device** bl_device_ret);
 
 /**
  * Write to a specific BLE device characteristic using it's uuid
  *
- * @param lb_context to use
  * @param dev BLE device to search the characteristic in
  * @param uuid of the characteristic to write to
  * @param size of the uint8 array to be written
@@ -263,12 +228,11 @@
  * @return Result of operation
  */
 lb_result_t
-lb_write_to_characteristic(lb_context lb_ctx, lb_bl_device* dev, const char* 
uuid, int size, uint8_t* value);
+lb_write_to_characteristic(lb_bl_device* dev, const char* uuid, int size, 
uint8_t* value);
 
 /**
  * Read from a specific BLE device characteristic using it's uuid
  *
- * @param lb_context to use
  * @param dev BLE device to search the characteristic in
  * @param uuid of the characteristic to read from
  * @param size of the uint8 array that was read
@@ -276,20 +240,18 @@
  * @return Result of operation
  */
 lb_result_t
-lb_read_from_characteristic(lb_context lb_ctx, lb_bl_device* dev, const char* 
uuid, size_t* size, uint8_t** result);
+lb_read_from_characteristic(lb_bl_device* dev, const char* uuid, size_t* size, 
uint8_t** result);
 
 /**
  * Register a callback function for an event of characteristic value change
  *
- * @param lb_context to use
  * @param dev BLE device to search the characteristic in
  * @param uuid of the characteristic to read from
  * @param callback function to be called when char value changed
  * @param userdata to pass in the callback function
  * @return Result of operation
  */
-lb_result_t lb_register_characteristic_read_event(lb_context lb_ctx,
-                                                  lb_bl_device* dev,
+lb_result_t lb_register_characteristic_read_event(lb_bl_device* dev,
                                                   const char* uuid,
                                                   sd_bus_message_handler_t 
callback,
                                                   void* userdata);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/littleb-0.1.1/examples/hello_littleb.c 
new/littleb-0.1.2/examples/hello_littleb.c
--- old/littleb-0.1.1/examples/hello_littleb.c  2016-08-24 21:35:01.000000000 
+0200
+++ new/littleb-0.1.2/examples/hello_littleb.c  2017-08-08 15:49:35.000000000 
+0200
@@ -62,13 +62,7 @@
         exit(r);
     }
 
-    lb_context lb_ctx = lb_context_new();
-    if (lb_ctx == NULL) {
-        fprintf(stderr, "ERROR: lb_context_new\n");
-        exit(r);
-    }
-
-    r = lb_get_bl_devices(lb_ctx, 5);
+    r = lb_get_bl_devices(5);
     if (r < 0) {
         fprintf(stderr, "ERROR: lb_get_bl_devices\n");
         goto cleanup;
@@ -76,25 +70,25 @@
 
     // search for our specific device named "FIRMATA"
     lb_bl_device* firmata = NULL;
-    r = lb_get_device_by_device_name(lb_ctx, "FIRMATA", &firmata);
+    r = lb_get_device_by_device_name("FIRMATA", &firmata);
     if (r < 0) {
         fprintf(stderr, "ERROR: Device FIRMATA not found\n");
         goto cleanup;
     }
 
-    r = lb_connect_device(lb_ctx, firmata);
+    r = lb_connect_device(firmata);
     if (r < 0) {
         fprintf(stderr, "ERROR: lb_connect_device\n");
         goto cleanup;
     }
 
-    // r = lb_pair_device(lb_ctx, firmata);
+    // r = lb_pair_device(firmata);
     // if (r < 0) {
     //        fprintf(stderr, "ERROR: lb_pair_device\n");
     //        exit(r);
     //}
 
-    r = lb_get_ble_device_services(lb_ctx, firmata);
+    r = lb_get_ble_device_services(firmata);
     if (r < 0) {
         fprintf(stderr, "ERROR: lb_get_ble_device_services\n");
         goto cleanup;
@@ -118,14 +112,14 @@
     for (i = 0; i < 10; i++) {
         printf(".");
         fflush(stdout);
-        r = lb_write_to_characteristic(lb_ctx, firmata, 
"6e400002-b5a3-f393-e0a9-e50e24dcca9e", 3, led_on);
+        r = lb_write_to_characteristic(firmata, 
"6e400002-b5a3-f393-e0a9-e50e24dcca9e", 3, led_on);
         if (r < 0) {
             fprintf(stderr, "ERROR: lb_write_to_characteristic\n");
         }
         usleep(1000000);
         printf(".");
         fflush(stdout);
-        r = lb_write_to_characteristic(lb_ctx, firmata, 
"6e400002-b5a3-f393-e0a9-e50e24dcca9e", 3, led_off);
+        r = lb_write_to_characteristic(firmata, 
"6e400002-b5a3-f393-e0a9-e50e24dcca9e", 3, led_off);
         if (r < 0) {
             fprintf(stderr, "ERROR: lb_write_to_characteristic\n");
         }
@@ -136,7 +130,7 @@
     const char* userdata_test = "test";
 
     r =
-    lb_register_characteristic_read_event(lb_ctx, firmata, 
"6e400003-b5a3-f393-e0a9-e50e24dcca9e",
+    lb_register_characteristic_read_event(firmata, 
"6e400003-b5a3-f393-e0a9-e50e24dcca9e",
                                           test_callback, (void*) 
userdata_test);
     if (r < 0) {
         fprintf(stderr, "ERROR: lb_register_characteristic_read_event\n");
@@ -147,7 +141,7 @@
     printf("get_version\n");
     fflush(stdout);
     uint8_t get_version[] = { 0xf0, 0x79, 0xf7 };
-    r = lb_write_to_characteristic(lb_ctx, firmata, 
"6e400002-b5a3-f393-e0a9-e50e24dcca9e", 3, get_version);
+    r = lb_write_to_characteristic(firmata, 
"6e400002-b5a3-f393-e0a9-e50e24dcca9e", 3, get_version);
     if (r < 0) {
         fprintf(stderr, "ERROR: lb_write_to_characteristic\n");
     }
@@ -157,22 +151,17 @@
 
 cleanup:
 
-    // r = lb_unpair_device(lb_ctx, firmata);
+    // r = lb_unpair_device(firmata);
     // if (r < 0) {
     //        fprintf(stderr, "ERROR: lb_unpair_device\n");
     //        exit(r);
     //}
 
-    r = lb_disconnect_device(lb_ctx, firmata);
+    r = lb_disconnect_device(firmata);
     if (r < 0) {
         fprintf(stderr, "ERROR: lb_disconnect_device\n");
     }
 
-    r = lb_context_free(lb_ctx);
-    if (r < 0) {
-        fprintf(stderr, "ERROR: lb_context_free\n");
-    }
-
     r = lb_destroy();
     if (r < 0) {
         fprintf(stderr, "ERROR: lb_destroy\n");
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/littleb-0.1.1/include/littleb_internal_types.h 
new/littleb-0.1.2/include/littleb_internal_types.h
--- old/littleb-0.1.1/include/littleb_internal_types.h  2016-08-24 
21:35:01.000000000 +0200
+++ new/littleb-0.1.2/include/littleb_internal_types.h  2017-08-08 
15:49:35.000000000 +0200
@@ -43,6 +43,8 @@
     int devices_size;       /**< count of devices found*/
 };
 
+typedef struct bl_context* lb_context;
+
 typedef struct event_matches_callbacks {
     const char* event;
     sd_bus_message_handler_t* callback;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/littleb-0.1.1/src/littleb.c 
new/littleb-0.1.2/src/littleb.c
--- old/littleb-0.1.1/src/littleb.c     2016-08-24 21:35:01.000000000 +0200
+++ new/littleb-0.1.2/src/littleb.c     2017-08-08 15:49:35.000000000 +0200
@@ -28,6 +28,7 @@
 static pthread_t event_thread;
 static event_matches_callbacks** events_matches_array = NULL;
 static uint event_arr_size = 0;
+static lb_context lb_ctx = NULL;
 
 void*
 _run_event_loop(void* arg)
@@ -74,9 +75,6 @@
 const char*
 _convert_device_path_to_address(const char* address)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int i;
     const char* prefix = "dev_";
 
@@ -99,11 +97,8 @@
 }
 
 bool
-_is_bus_connected(lb_context lb_ctx)
+_is_bus_connected()
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     if (lb_ctx->bus == NULL) {
         return false;
     } else {
@@ -112,11 +107,8 @@
 }
 
 lb_result_t
-_get_root_objects(lb_context lb_ctx, const char** objects)
+_get_root_objects(const char** objects)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int r = 0, i = 0;
     const char* device_path;
     sd_bus_error error = SD_BUS_ERROR_NULL;
@@ -208,11 +200,8 @@
 }
 
 const char*
-_get_device_name(lb_context lb_ctx, const char* device_path)
+_get_device_name(const char* device_path)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     sd_bus_error error = SD_BUS_ERROR_NULL;
     int r;
     char* name;
@@ -230,11 +219,8 @@
 }
 
 const char*
-_get_device_address(lb_context lb_ctx, const char* device_path)
+_get_device_address(const char* device_path)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     sd_bus_error error = SD_BUS_ERROR_NULL;
     int r;
     char* address;
@@ -253,11 +239,8 @@
 }
 
 const char*
-_get_service_uuid(lb_context lb_ctx, const char* service_path)
+_get_service_uuid(const char* service_path)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     sd_bus_error error = SD_BUS_ERROR_NULL;
     int r;
     char* name;
@@ -276,11 +259,8 @@
 }
 
 const char*
-_get_characteristic_uuid(lb_context lb_ctx, const char* characteristic_path)
+_get_characteristic_uuid(const char* characteristic_path)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     sd_bus_error error = SD_BUS_ERROR_NULL;
     int r;
     char* name;
@@ -300,11 +280,8 @@
 }
 
 bool
-_is_string_in_device_introspection(lb_context lb_ctx, const char* device_path, 
const char* str)
+_is_string_in_device_introspection(const char* device_path, const char* str)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     sd_bus_error error = SD_BUS_ERROR_NULL;
     sd_bus_message* reply = NULL;
 
@@ -345,31 +322,25 @@
 }
 
 bool
-_is_bl_device(lb_context lb_ctx, const char* device_path)
+_is_bl_device(const char* device_path)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
-    return _is_string_in_device_introspection(lb_ctx, device_path, 
BLUEZ_DEVICE);
+    return _is_string_in_device_introspection(device_path, BLUEZ_DEVICE);
 }
 
 bool
-_is_ble_device(lb_context lb_ctx, const char* device_path)
+_is_ble_device(const char* device_path)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     const char** objects;
     int i = 0, r = 0;
     bool result = false;
 
-    if (!_is_bl_device(lb_ctx, device_path)) {
+    if (!_is_bl_device(device_path)) {
         syslog(LOG_ERR, "%s: not a bl device", __FUNCTION__);
         return false;
     }
 
     lb_bl_device* device = NULL;
-    r = lb_get_device_by_device_path(lb_ctx, device_path, &device);
+    r = lb_get_device_by_device_path(device_path, &device);
     if (r < 0) {
         fprintf(stderr, "ERROR: Device %s not found\n", device_path);
     }
@@ -383,7 +354,7 @@
         return -LB_ERROR_MEMEORY_ALLOCATION;
     }
 
-    r = _get_root_objects(lb_ctx, objects);
+    r = _get_root_objects(objects);
     if (r < 0) {
         syslog(LOG_ERR, "%s: Error getting root objects", __FUNCTION__);
         return false;
@@ -402,29 +373,20 @@
 }
 
 bool
-_is_ble_service(lb_context lb_ctx, const char* service_path)
+_is_ble_service(const char* service_path)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
-    return _is_string_in_device_introspection(lb_ctx, service_path, 
BLUEZ_GATT_SERVICE);
+    return _is_string_in_device_introspection(service_path, 
BLUEZ_GATT_SERVICE);
 }
 
 bool
-_is_ble_characteristic(lb_context lb_ctx, const char* service_path)
+_is_ble_characteristic(const char* service_path)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
-    return _is_string_in_device_introspection(lb_ctx, service_path, 
BLUEZ_GATT_CHARACTERISTICS);
+    return _is_string_in_device_introspection(service_path, 
BLUEZ_GATT_CHARACTERISTICS);
 }
 
 bool
-_is_service_primary(lb_context lb_ctx, const char* service_path)
+_is_service_primary(const char* service_path)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     sd_bus_error error = SD_BUS_ERROR_NULL;
     int r;
     bool primary;
@@ -444,11 +406,8 @@
 }
 
 bool
-_is_device_paired(lb_context lb_ctx, const char* device_path)
+_is_device_paired(const char* device_path)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     sd_bus_error error = SD_BUS_ERROR_NULL;
     int r;
     bool paired;
@@ -467,11 +426,8 @@
 }
 
 lb_result_t
-_add_new_characteristic(lb_context lb_ctx, lb_ble_service* service, const 
char* characteristic_path)
+_add_new_characteristic(lb_ble_service* service, const char* 
characteristic_path)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int current_index = service->characteristics_size;
     if (service->characteristics_size == 0 || service->characteristics == 
NULL) {
         service->characteristics = (lb_ble_char**) 
malloc(sizeof(lb_ble_char*));
@@ -504,7 +460,7 @@
         return -LB_ERROR_MEMEORY_ALLOCATION;
     }
 
-    const char* uuid = _get_characteristic_uuid(lb_ctx, characteristic_path);
+    const char* uuid = _get_characteristic_uuid(characteristic_path);
     if (uuid == NULL) {
         syslog(LOG_ERR, "%s: Error couldn't find characteristic uuid", 
__FUNCTION__);
         new_characteristic->uuid = strdup("null");
@@ -523,12 +479,9 @@
 }
 
 lb_result_t
-_add_new_service(lb_context lb_ctx, lb_bl_device* dev, const char* 
service_path)
+_add_new_service(lb_bl_device* dev, const char* service_path)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
-    if (!_is_ble_device(lb_ctx, dev->device_path)) {
+    if (!_is_ble_device(dev->device_path)) {
         syslog(LOG_ERR, "%s: not a ble device", __FUNCTION__);
         return -LB_ERROR_INVALID_DEVICE;
     }
@@ -563,7 +516,7 @@
         return -LB_ERROR_MEMEORY_ALLOCATION;
     }
 
-    const char* uuid = _get_service_uuid(lb_ctx, service_path);
+    const char* uuid = _get_service_uuid(service_path);
     if (uuid == NULL) {
         syslog(LOG_ERR, "%s: Error couldn't find service uuid", __FUNCTION__);
         new_service->uuid = strdup("null");
@@ -576,7 +529,7 @@
         new_service->uuid = uuid;
     }
 
-    new_service->primary = _is_service_primary(lb_ctx, service_path);
+    new_service->primary = _is_service_primary(service_path);
 
     new_service->characteristics = NULL;
     new_service->characteristics_size = 0;
@@ -587,11 +540,8 @@
 }
 
 lb_result_t
-_add_new_device(lb_context lb_ctx, const char* device_path)
+_add_new_device(const char* device_path)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int current_index = lb_ctx->devices_size;
     if (lb_ctx->devices_size == 0 || lb_ctx->devices == NULL) {
         lb_ctx->devices = (lb_bl_device**) malloc(sizeof(lb_bl_device*));
@@ -623,7 +573,7 @@
         return -LB_ERROR_MEMEORY_ALLOCATION;
     }
 
-    const char* name = _get_device_name(lb_ctx, device_path);
+    const char* name = _get_device_name(device_path);
     if (name == NULL) {
         syslog(LOG_ERR, "%s: Error couldn't find device name", __FUNCTION__);
         new_device->name = strdup("null");
@@ -636,7 +586,7 @@
     } else {
         new_device->name = name;
     }
-    const char* address = _get_device_address(lb_ctx, device_path);
+    const char* address = _get_device_address(device_path);
     if (address == NULL) {
         syslog(LOG_ERR, "%s: Error couldn't find device address", 
__FUNCTION__);
         new_device->address = "null";
@@ -654,11 +604,8 @@
 }
 
 lb_result_t
-_scan_devices(lb_context lb_ctx, int seconds)
+_scan_devices(int seconds)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int r = 0;
     sd_bus_error error = SD_BUS_ERROR_NULL;
 
@@ -693,11 +640,8 @@
 }
 
 lb_result_t
-_open_system_bus(lb_context lb_ctx)
+_open_system_bus()
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int r;
 
     /* Connect to the system bus */
@@ -710,86 +654,45 @@
 }
 
 lb_result_t
-_close_system_bus(lb_context lb_ctx)
+_close_system_bus()
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
 
     sd_bus_unref(lb_ctx->bus);
     return LB_SUCCESS;
 }
 
 lb_result_t
-lb_init()
-{
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
-    return LB_SUCCESS;
-}
-
-lb_result_t
-lb_destroy()
-{
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
-    int i, r;
-
-    pthread_cancel(event_thread);
-    pthread_join(event_thread, NULL);
-
-    r = sd_event_exit(event, SIGINT);
-    if (r < 0) {
-        syslog(LOG_ERR, "%s: failed to stop event loop", __FUNCTION__);
-    }
-    sd_event_unref(event);
-
-    if (events_matches_array != NULL) {
-        for (i = 0; i < event_arr_size; i++) {
-            free(events_matches_array[i]);
-        }
-        free(events_matches_array);
-    }
-
-    return LB_SUCCESS;
-}
-
-lb_context
 lb_context_new()
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int r = 0;
-    lb_context new_context;
 
-    new_context = (lb_context) malloc(sizeof(struct bl_context));
-    if (new_context == NULL) {
+    if (lb_ctx != NULL) {
+        syslog(LOG_ERR, "%s: Context already initialized", __FUNCTION__);
+        return -LB_ERROR_INVALID_CONTEXT;
+    }
+
+    lb_ctx = (lb_context) malloc(sizeof(struct bl_context));
+    if (lb_ctx == NULL) {
         syslog(LOG_ERR, "%s: Error allocating memory for lb_context", 
__FUNCTION__);
-        return NULL;
+        return -LB_ERROR_INVALID_CONTEXT;
     }
 
-    new_context->bus = NULL;
-    new_context->devices = NULL;
-    new_context->devices_size = 0;
+    lb_ctx->bus = NULL;
+    lb_ctx->devices = NULL;
+    lb_ctx->devices_size = 0;
 
-    r = _open_system_bus(new_context);
+    r = _open_system_bus();
     if (r < 0) {
         syslog(LOG_ERR, "%s: Failed to open system bus: %s", __FUNCTION__, 
strerror(-r));
-        return NULL;
+        return -LB_ERROR_INVALID_CONTEXT;
     }
 
-    return new_context;
+    return LB_SUCCESS;
 }
 
 lb_result_t
-lb_context_free(lb_context lb_ctx)
+lb_context_free()
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int r = 0, i = 0, j = 0, k = 0;
 
     if (lb_ctx == NULL) {
@@ -837,15 +740,48 @@
         free(lb_ctx->devices);
     free(lb_ctx);
 
+    lb_ctx = NULL;
+    return LB_SUCCESS;
+}
+
+lb_result_t
+lb_init()
+{
+    if (lb_context_new() != LB_SUCCESS)
+        return LB_ERROR_INVALID_CONTEXT;
+
+    return LB_SUCCESS;
+}
+
+lb_result_t
+lb_destroy()
+{
+    int i, r;
+
+    pthread_cancel(event_thread);
+    pthread_join(event_thread, NULL);
+
+    r = sd_event_exit(event, SIGINT);
+    if (r < 0) {
+        syslog(LOG_ERR, "%s: failed to stop event loop", __FUNCTION__);
+    }
+    sd_event_unref(event);
+
+    if (events_matches_array != NULL) {
+        for (i = 0; i < event_arr_size; i++) {
+            free(events_matches_array[i]);
+        }
+        free(events_matches_array);
+    }
+
+    lb_context_free();
+
     return LB_SUCCESS;
 }
 
 lb_result_t
-lb_get_bl_devices(lb_context lb_ctx, int seconds)
+lb_get_bl_devices(int seconds)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     const char** objects;
     int i = 0, r = 0;
 
@@ -864,21 +800,21 @@
         return -LB_ERROR_MEMEORY_ALLOCATION;
     }
 
-    r = _scan_devices(lb_ctx, seconds);
+    r = _scan_devices(seconds);
     if (r < 0) {
         syslog(LOG_ERR, "%s: Error getting root objects", __FUNCTION__);
         return -LB_ERROR_UNSPECIFIED;
     }
 
-    r = _get_root_objects(lb_ctx, objects);
+    r = _get_root_objects(objects);
     if (r < 0) {
         syslog(LOG_ERR, "%s: Error getting root objects", __FUNCTION__);
         return -LB_ERROR_UNSPECIFIED;
     }
 
     while (objects[i] != NULL) {
-        if (_is_bl_device(lb_ctx, objects[i])) {
-            _add_new_device(lb_ctx, objects[i]);
+        if (_is_bl_device(objects[i])) {
+            _add_new_device(objects[i]);
         }
         free((char*) objects[i]);
         i++;
@@ -890,11 +826,8 @@
 }
 
 lb_result_t
-lb_connect_device(lb_context lb_ctx, lb_bl_device* dev)
+lb_connect_device(lb_bl_device* dev)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int r;
     sd_bus_error error = SD_BUS_ERROR_NULL;
 
@@ -929,11 +862,8 @@
 }
 
 lb_result_t
-lb_disconnect_device(lb_context lb_ctx, lb_bl_device* dev)
+lb_disconnect_device(lb_bl_device* dev)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int r;
     sd_bus_error error = SD_BUS_ERROR_NULL;
 
@@ -968,11 +898,8 @@
 }
 
 lb_result_t
-lb_pair_device(lb_context lb_ctx, lb_bl_device* dev)
+lb_pair_device(lb_bl_device* dev)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int r;
     sd_bus_error error = SD_BUS_ERROR_NULL;
 
@@ -1006,11 +933,8 @@
 }
 
 lb_result_t
-lb_unpair_device(lb_context lb_ctx, lb_bl_device* dev)
+lb_unpair_device(lb_bl_device* dev)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int r;
     sd_bus_error error = SD_BUS_ERROR_NULL;
 
@@ -1045,11 +969,8 @@
 }
 
 lb_result_t
-lb_get_ble_device_services(lb_context lb_ctx, lb_bl_device* dev)
+lb_get_ble_device_services(lb_bl_device* dev)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int i = 0, r = 0;
     sd_bus_error error = SD_BUS_ERROR_NULL;
 
@@ -1063,14 +984,14 @@
         return -LB_ERROR_INVALID_DEVICE;
     }
 
-    if (!_is_bl_device(lb_ctx, dev->device_path)) {
+    if (!_is_bl_device(dev->device_path)) {
         syslog(LOG_ERR, "%s: device %s not a bl device", __FUNCTION__, 
dev->device_path);
         sd_bus_error_free(&error);
         return -LB_ERROR_INVALID_DEVICE;
     }
 
-    if (!_is_device_paired(lb_ctx, dev->device_path)) {
-        r = lb_pair_device(lb_ctx, dev);
+    if (!_is_device_paired(dev->device_path)) {
+        r = lb_pair_device(dev);
         if (r < 0) {
             syslog(LOG_ERR, "%s: error pairing device", __FUNCTION__);
             sd_bus_error_free(&error);
@@ -1089,7 +1010,7 @@
         return -LB_ERROR_MEMEORY_ALLOCATION;
     }
 
-    r = _get_root_objects(lb_ctx, objects);
+    r = _get_root_objects(objects);
     if (r < 0) {
         syslog(LOG_ERR, "%s: Error getting root objects", __FUNCTION__);
         if (objects != NULL)
@@ -1099,23 +1020,23 @@
     }
 
     while (objects[i] != NULL) {
-        if (strstr(objects[i], dev->device_path) && _is_ble_service(lb_ctx, 
objects[i])) {
+        if (strstr(objects[i], dev->device_path) && 
_is_ble_service(objects[i])) {
             const char* service_path = objects[i];
-            r = _add_new_service(lb_ctx, dev, service_path);
+            r = _add_new_service(dev, service_path);
             if (r < 0) {
                 syslog(LOG_ERR, "%s: Error adding ble service", __FUNCTION__);
                 continue;
             }
             int j = 0;
             while (objects[j] != NULL) {
-                if (strstr(objects[j], service_path) && 
_is_ble_characteristic(lb_ctx, objects[j])) {
+                if (strstr(objects[j], service_path) && 
_is_ble_characteristic(objects[j])) {
                     lb_ble_service* new_service = NULL;
-                    r = lb_get_ble_service_by_service_path(lb_ctx, dev, 
service_path, &new_service);
+                    r = lb_get_ble_service_by_service_path(dev, service_path, 
&new_service);
                     if (r < 0) {
                         syslog(LOG_ERR, "%s: Error getting ble service", 
__FUNCTION__);
                         continue;
                     }
-                    _add_new_characteristic(lb_ctx, new_service, objects[j]);
+                    _add_new_characteristic(new_service, objects[j]);
                     if (r < 0) {
                         syslog(LOG_ERR, "%s: Error adding ble characteristic", 
__FUNCTION__);
                         continue;
@@ -1141,14 +1062,10 @@
 }
 
 lb_result_t
-lb_get_ble_characteristic_by_characteristic_path(lb_context lb_ctx,
-                                                 lb_bl_device* dev,
+lb_get_ble_characteristic_by_characteristic_path(lb_bl_device* dev,
                                                  const char* 
characteristic_path,
                                                  lb_ble_char** 
ble_characteristic_ret)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int i, j;
 
     if (lb_ctx == NULL) {
@@ -1179,11 +1096,8 @@
 }
 
 lb_result_t
-lb_get_ble_characteristic_by_uuid(lb_context lb_ctx, lb_bl_device* dev, const 
char* uuid, lb_ble_char** ble_characteristic_ret)
+lb_get_ble_characteristic_by_uuid(lb_bl_device* dev, const char* uuid, 
lb_ble_char** ble_characteristic_ret)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int i, j;
 
     if (lb_ctx == NULL) {
@@ -1201,13 +1115,13 @@
         return -LB_ERROR_INVALID_DEVICE;
     }
 
-    if (!_is_ble_device(lb_ctx, dev->device_path)) {
+    if (!_is_ble_device(dev->device_path)) {
         syslog(LOG_ERR, "%s: not a ble device", __FUNCTION__);
         return -LB_ERROR_INVALID_DEVICE;
     }
 
     for (i = 0; i < dev->services_size; i++) {
-        for (j = 0; dev->services_size; j++) {
+        for (j = 0; j < dev->services[i]->characteristics_size; j++) {
             if (strncmp(uuid, dev->services[i]->characteristics[j]->uuid, 
strlen(uuid)) == 0) {
                 *ble_characteristic_ret = dev->services[i]->characteristics[j];
                 return LB_SUCCESS;
@@ -1218,11 +1132,8 @@
 }
 
 lb_result_t
-lb_get_ble_service_by_service_path(lb_context lb_ctx, lb_bl_device* dev, const 
char* service_path, lb_ble_service** ble_service_ret)
+lb_get_ble_service_by_service_path(lb_bl_device* dev, const char* 
service_path, lb_ble_service** ble_service_ret)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int i;
 
     if (lb_ctx == NULL) {
@@ -1250,11 +1161,8 @@
 }
 
 lb_result_t
-lb_get_ble_service_by_uuid(lb_context lb_ctx, lb_bl_device* dev, const char* 
uuid, lb_ble_service** ble_service_ret)
+lb_get_ble_service_by_uuid(lb_bl_device* dev, const char* uuid, 
lb_ble_service** ble_service_ret)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int i;
 
     if (lb_ctx == NULL) {
@@ -1272,7 +1180,7 @@
         return -LB_ERROR_INVALID_DEVICE;
     }
 
-    if (!_is_ble_device(lb_ctx, dev->device_path)) {
+    if (!_is_ble_device(dev->device_path)) {
         syslog(LOG_ERR, "%s: not a ble device", __FUNCTION__);
         return -LB_ERROR_INVALID_DEVICE;
     }
@@ -1287,11 +1195,8 @@
 }
 
 lb_result_t
-lb_get_device_by_device_path(lb_context lb_ctx, const char* device_path, 
lb_bl_device** bl_device_ret)
+lb_get_device_by_device_path(const char* device_path, lb_bl_device** 
bl_device_ret)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int i;
 
     if (lb_ctx == NULL) {
@@ -1314,11 +1219,8 @@
 }
 
 lb_result_t
-lb_get_device_by_device_name(lb_context lb_ctx, const char* name, 
lb_bl_device** bl_device_ret)
+lb_get_device_by_device_name(const char* name, lb_bl_device** bl_device_ret)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int i;
 
     if (lb_ctx == NULL) {
@@ -1341,11 +1243,8 @@
 }
 
 lb_result_t
-lb_get_device_by_device_address(lb_context lb_ctx, const char* address, 
lb_bl_device** bl_device_ret)
+lb_get_device_by_device_address(const char* address, lb_bl_device** 
bl_device_ret)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int i;
 
     if (lb_ctx == NULL) {
@@ -1368,11 +1267,8 @@
 }
 
 lb_result_t
-lb_write_to_characteristic(lb_context lb_ctx, lb_bl_device* dev, const char* 
uuid, int size, uint8_t* value)
+lb_write_to_characteristic(lb_bl_device* dev, const char* uuid, int size, 
uint8_t* value)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int r;
     sd_bus_message* func_call = NULL;
     sd_bus_error error = SD_BUS_ERROR_NULL;
@@ -1399,7 +1295,7 @@
         return -LB_ERROR_INVALID_BUS;
     }
 
-    r = lb_get_ble_characteristic_by_uuid(lb_ctx, dev, uuid, &characteristics);
+    r = lb_get_ble_characteristic_by_uuid(dev, uuid, &characteristics);
     if (r < 0) {
         syslog(LOG_ERR, "%s: Failed to get characteristic", __FUNCTION__);
         sd_bus_error_free(&error);
@@ -1423,6 +1319,7 @@
         return -LB_ERROR_UNSPECIFIED;
     }
 
+    /*
     r = sd_bus_message_append(func_call, "a{sv}", 0, NULL);
     if (r < 0) {
         syslog(LOG_ERR, "%s: Failed to append a{sv} to message call", 
__FUNCTION__);
@@ -1430,6 +1327,7 @@
         sd_bus_message_unref(func_call);
         return -LB_ERROR_UNSPECIFIED;
     }
+    */
 
     r = sd_bus_call(lb_ctx->bus, func_call, 0, &error, NULL);
     if (r < 0) {
@@ -1453,11 +1351,8 @@
 }
 
 lb_result_t
-lb_read_from_characteristic(lb_context lb_ctx, lb_bl_device* dev, const char* 
uuid, size_t* size, uint8_t** result)
+lb_read_from_characteristic(lb_bl_device* dev, const char* uuid, size_t* size, 
uint8_t** result)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int r;
     sd_bus_message* reply = NULL;
     sd_bus_error error = SD_BUS_ERROR_NULL;
@@ -1484,13 +1379,13 @@
         return -LB_ERROR_INVALID_BUS;
     }
 
-    if (!_is_ble_device(lb_ctx, dev->device_path)) {
+    if (!_is_ble_device(dev->device_path)) {
         syslog(LOG_ERR, "%s: not a ble device", __FUNCTION__);
         sd_bus_error_free(&error);
         return -LB_ERROR_INVALID_DEVICE;
     }
 
-    r = lb_get_ble_characteristic_by_uuid(lb_ctx, dev, uuid, &characteristics);
+    r = lb_get_ble_characteristic_by_uuid(dev, uuid, &characteristics);
     if (r < 0) {
         syslog(LOG_ERR, "%s: Failed to get characteristic", __FUNCTION__);
         sd_bus_error_free(&error);
@@ -1521,15 +1416,11 @@
 }
 
 lb_result_t
-lb_register_characteristic_read_event(lb_context lb_ctx,
-                                      lb_bl_device* dev,
+lb_register_characteristic_read_event(lb_bl_device* dev,
                                       const char* uuid,
                                       sd_bus_message_handler_t callback,
                                       void* userdata)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int r;
     sd_bus_error error = SD_BUS_ERROR_NULL;
     lb_ble_char* ble_char_new = NULL;
@@ -1555,7 +1446,7 @@
         return -LB_ERROR_INVALID_DEVICE;
     }
 
-    r = lb_get_ble_characteristic_by_uuid(lb_ctx, dev, uuid, &ble_char_new);
+    r = lb_get_ble_characteristic_by_uuid(dev, uuid, &ble_char_new);
     if (r < 0) {
         syslog(LOG_ERR, "%s: could find characteristic: %s", __FUNCTION__, 
uuid);
         sd_bus_error_free(&error);
@@ -1613,9 +1504,6 @@
 lb_result_t
 lb_parse_uart_service_message(sd_bus_message* message, const void** result, 
size_t* size)
 {
-#ifdef DEBUG
-    printf("Method Called: %s\n", __FUNCTION__);
-#endif
     int r;
 
     if (message == NULL) {


Reply via email to