I want to use client_socket_fd.
way1
main thread function{ //caller call this function
res = bt_socket_set_connection_state_changed_cb(socket_connection_state_changed, NULL);
res = bt_socket_connect_rfcomm(pServerID, service_uuid);
res = bt_socket_send_data(client_socket_fd, hash, len); //I'll get client_socket_fd in socket_connection_state_changed. NOT work.
... some process
return process reuslt;
}
In this routine, bt_socket_send_data use bad client_socket_fd because socket_connection_state_changed is not called yet.
way2
main thread function{ //caller call this function
res = bt_socket_set_connection_state_changed_cb(socket_connection_state_changed, NULL);
res = bt_socket_connect_rfcomm(pServerID, service_uuid);
}
other thread function{
while(client_socket_fd==0){}//busy wait for checking client_socket_fd
res = bt_socket_send_data(client_socket_fd, hash, len); //called after socket_connection_state_changed is called.
... some process
return process result; //impossible returning to caller
}
This work well but can't return value to caller.
way3
I want to wait client_socket_fd in main thread like below.
main thread function{ //caller call this function
res = bt_socket_set_connection_state_changed_cb(socket_connection_state_changed, NULL);
res = bt_socket_connect_rfcomm(pServerID, service_uuid);
while(client_socket_fd==0){} <- block
res = bt_socket_send_data(client_socket_fd, hash, len);
... some process
return process result;
}
Actually I have to return value in main thread function after getting socket like way3. But while() is blocking and socket_connection_state_changed is not called continuously.
It's seems for socket_connection_state_changed to be called in main thread too. In way2, I can't return client_socket_fd and result of some process to function caller.
How can I wait client_socket_fd(socket_connection_state_changed call complete) in main thread function? Or can I call callback(socket_connection_state_changed) in other thread?