diff options
author | Petre Eftime <[email protected]> | 2016-05-06 19:08:25 +0300 |
---|---|---|
committer | Petre Eftime <[email protected]> | 2016-05-06 19:10:51 +0300 |
commit | b0545a46bcfec1571c75499f0f2ed319f1f73c2e (patch) | |
tree | ef7a321e07863d15f83aecf50a3a47ccf1d8a98d /src | |
parent | 4f79c8d481119f8fa3e63f77286faddbeadb2b3c (diff) |
c++, java: Optional values return null when they are not available
Signed-off-by: Petre Eftime <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/BluetoothAdapter.cpp | 7 | ||||
-rw-r--r-- | src/BluetoothDevice.cpp | 14 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/BluetoothAdapter.cpp b/src/BluetoothAdapter.cpp index 821e3c37..86f1084e 100644 --- a/src/BluetoothAdapter.cpp +++ b/src/BluetoothAdapter.cpp @@ -246,7 +246,10 @@ std::vector<std::string> BluetoothAdapter::get_uuids () return uuids; } -std::string BluetoothAdapter::get_modalias () +std::unique_ptr<std::string> BluetoothAdapter::get_modalias () { - return std::string(adapter1_get_modalias (object)); + const gchar *modalias= adapter1_get_modalias (object); + if (modalias == nullptr) + return std::unique_ptr<std::string>(); + return std::unique_ptr<std::string>(new std::string(modalias)); } diff --git a/src/BluetoothDevice.cpp b/src/BluetoothDevice.cpp index cf3a59d4..3d37f862 100644 --- a/src/BluetoothDevice.cpp +++ b/src/BluetoothDevice.cpp @@ -232,9 +232,12 @@ uint16_t BluetoothDevice::get_appearance () return device1_get_appearance (object); } -std::string BluetoothDevice::get_icon () +std::unique_ptr<std::string> BluetoothDevice::get_icon () { - return std::string(device1_get_icon (object)); + const gchar *icon = device1_get_icon (object); + if (icon == nullptr) + return std::unique_ptr<std::string>(); + return std::unique_ptr<std::string>(new std::string(icon)); } bool BluetoothDevice::get_paired () @@ -287,9 +290,12 @@ std::vector<std::string> BluetoothDevice::get_uuids () return uuids; } -std::string BluetoothDevice::get_modalias () +std::unique_ptr<std::string> BluetoothDevice::get_modalias () { - return std::string(device1_get_modalias (object)); + const gchar *modalias= device1_get_modalias (object); + if (modalias == nullptr) + return std::unique_ptr<std::string>(); + return std::unique_ptr<std::string>(new std::string(modalias)); } BluetoothAdapter BluetoothDevice::get_adapter () |