#include <stdio.h>
#include <stdlib.h>
-#include <assert.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdbool.h>
#include "lib/sdp.h"
#include "log.h"
+#include "backtrace.h"
#include "adapter.h"
#include "device.h"
if (state == old)
return;
- assert(service->device != NULL);
- assert(service->profile != NULL);
+ btd_assert(service->device != NULL);
+ btd_assert(service->profile != NULL);
service->state = state;
service->err = err;
char addr[18];
int err;
- assert(service->state == BTD_SERVICE_STATE_UNAVAILABLE);
+ btd_assert(service->state == BTD_SERVICE_STATE_UNAVAILABLE);
err = service->profile->device_probe(service);
if (err == 0) {
void service_remove(struct btd_service *service)
{
+#ifdef __TIZEN_PATCH__
+ if (service->profile == NULL)
+ return;
+#endif
change_state(service, BTD_SERVICE_STATE_DISCONNECTED, -ECONNABORTED);
change_state(service, BTD_SERVICE_STATE_UNAVAILABLE, 0);
service->profile->device_remove(service);
char addr[18];
int err;
- if (!service->profile->accept)
+ switch (service->state) {
+ case BTD_SERVICE_STATE_UNAVAILABLE:
+ return -EINVAL;
+ case BTD_SERVICE_STATE_DISCONNECTED:
+ break;
+ case BTD_SERVICE_STATE_CONNECTING:
+ case BTD_SERVICE_STATE_CONNECTED:
return 0;
+ case BTD_SERVICE_STATE_DISCONNECTING:
+ return -EBUSY;
+ }
+
+ if (!service->profile->accept)
+ goto done;
err = service->profile->accept(service);
if (!err)
- return 0;
+ goto done;
ba2str(device_get_address(service->device), addr);
error("%s profile accept failed for %s", service->profile->name, addr);
return err;
+
+done:
+ change_state(service, BTD_SERVICE_STATE_CONNECTING, 0);
+ return 0;
}
int btd_service_connect(struct btd_service *service)
case BTD_SERVICE_STATE_DISCONNECTED:
break;
case BTD_SERVICE_STATE_CONNECTING:
+ return 0;
case BTD_SERVICE_STATE_CONNECTED:
return -EALREADY;
case BTD_SERVICE_STATE_DISCONNECTING:
void btd_service_set_user_data(struct btd_service *service, void *user_data)
{
- assert(service->state == BTD_SERVICE_STATE_UNAVAILABLE);
+ btd_assert(service->state == BTD_SERVICE_STATE_UNAVAILABLE);
service->user_data = user_data;
}
void btd_service_connecting_complete(struct btd_service *service, int err)
{
+#ifdef __TIZEN_PATCH__
if (service->state != BTD_SERVICE_STATE_DISCONNECTED &&
- service->state != BTD_SERVICE_STATE_CONNECTING)
+ service->state != BTD_SERVICE_STATE_CONNECTING)
return;
+#else
+ if (service->state != BTD_SERVICE_STATE_CONNECTING)
+ return;
+#endif
if (err == 0)
change_state(service, BTD_SERVICE_STATE_CONNECTED, 0);