gobbledegook icon indicating copy to clipboard operation
gobbledegook copied to clipboard

uninit() will not leave lib in uninitialized state

Open matswebjorn opened this issue 1 year ago • 0 comments

Calling uninit() will not leave library in a state where it can be initialized again. There are several problems, but they are all in uninit()

  1. uninit() does not reset state to EUninitialized
  2. uninit() does not deallocate allocated context properly which will cause initializationStateProcessor() to fail to reinitialize library

This works ` void uninit() { // // Unregister our appliation with the BlueZ GATT manager // if (bApplicationRegistered) { /* Registering application once it has been registered does not work. So leave it registrered * once it has been done. Because unregistrering application is a new can of worms that hasn't * been explored, and it seems to work to keep registration even if the rest of the context is * deallocated. */ }

//
// Unregister our object with D-bus
//
if (!registeredObjectIds.empty())
{
	for (guint id : registeredObjectIds)
	{
		g_dbus_connection_unregister_object(pBusConnection, id);
	}
	registeredObjectIds.clear();
}

//
// Deconfigure the adapter
//
if (bAdapterConfigured)
{
	bAdapterConfigured = false; // Allow adapter configuration to be run again
}

//
// Cleanup the adapter interface
//
if (nullptr != pBluezAdapterObject)
{
	g_object_unref(pBluezAdapterObject);
	pBluezAdapterObject = nullptr;
}

if (nullptr != pBluezDeviceObject)
{
	g_object_unref(pBluezDeviceObject);
	pBluezDeviceObject = nullptr;
}

if (nullptr != pBluezAdapterInterfaceProxy)
{
	g_object_unref(pBluezAdapterInterfaceProxy);
	pBluezAdapterInterfaceProxy = nullptr;
}

if (nullptr != pBluezAdapterPropertiesInterfaceProxy)
{
	g_object_unref(pBluezAdapterPropertiesInterfaceProxy);
	pBluezAdapterPropertiesInterfaceProxy = nullptr;
}

if (nullptr != pBluezGattManagerProxy)
{
	g_object_unref(pBluezGattManagerProxy);
	pBluezGattManagerProxy = nullptr;
}

if (!bluezGattManagerInterfaceName.empty())
{
	bluezGattManagerInterfaceName.clear();
}

//
// Cleanup BlueZ's ObjectManager
//
if (nullptr != pBluezObjectManager)
{
	g_object_unref(pBluezObjectManager);
	pBluezObjectManager = nullptr;
}

//
// Cleanup owned name on the bus
//
if (0 != periodicTimeoutId)
{
	g_source_remove(periodicTimeoutId);
	periodicTimeoutId = 0;
}

if (ownedNameId > 0)
{
	bOwnedNameAcquired = false;
	g_bus_unown_name(ownedNameId);
	ownedNameId = 0;
}

//
// Cleanup bus connection
//
if (nullptr != pBusConnection)
{
	g_object_unref(pBusConnection);
	pBusConnection = nullptr;
}

//
// Cleanup main loop
//
if (nullptr != pMainLoop)
{
	g_main_loop_unref(pMainLoop);
	pMainLoop = nullptr;
}

setServerRunState(EUninitialized);

} `

matswebjorn avatar Dec 28 '24 10:12 matswebjorn