Merged from Tizen2.2
[platform/framework/native/bluetooth.git] / src / FNetBt_BluetoothHdpSystemAdapter.cpp
index 8045ae1..287a9fe 100755 (executable)
@@ -104,24 +104,32 @@ _BluetoothHdpSystemAdapter::_BluetoothHdpSystemAdapter(void)
 
 _BluetoothHdpSystemAdapter::~_BluetoothHdpSystemAdapter(void)
 {
-       // unregister the callback methods from the underlying layer
-       int err = bt_hdp_unset_connection_state_changed_cb();
-       SysLog(NID_NET_BT, "[0x%x] error in unregistering the connection state change callback method", err);
-
-       err = bt_hdp_unset_data_received_cb();
-       SysLog(NID_NET_BT, "[0x%x] error in unregistering the data received state change callback method", err);
 }
 
 void
 _BluetoothHdpSystemAdapter::InitSingleton(void)
 {
        bool r = false;
-       static _BluetoothHdpSystemAdapter inst;
+       std::unique_ptr<_BluetoothHdpSystemAdapter> pInst;
 
-       r = inst.Construct();
+       pInst.reset(new (std::nothrow) _BluetoothHdpSystemAdapter());
+       r = pInst->Construct();
        SysTryReturnVoidResult(NID_NET_BT, r == true, E_SYSTEM, "[E_SYSTEM] Propagating.");
 
-       __pInstance = &inst;
+       __pInstance = pInst.release();
+
+       std::atexit(DeinitializeSingleton);
+}
+
+void
+_BluetoothHdpSystemAdapter::DeinitializeSingleton(void)
+{
+       // unregister the callback methods from the underlying layer
+       int err = bt_hdp_unset_connection_state_changed_cb();
+       SysLog(NID_NET_BT, "[0x%x] error in unregistering the connection state change callback method", err);
+
+       err = bt_hdp_unset_data_received_cb();
+       SysLog(NID_NET_BT, "[0x%x] error in unregistering the data received state change callback method", err);
 }
 
 _BluetoothHdpSystemAdapter*