#1 2014-12-12 18:21:11

Alexis
Member
Registered: 2014-12-12
Posts: 4

Management of shared objects.

Hello Sascha:

I'm developing a File Manager for the MoonLight Desktop Environment it must be extended with different Views and Models in order to allow the navigation over different protocols (smb, ftp, davfs, etc). In order to allow this I use an approach similar to the SpellChecking example but instead of dictionaries I create object factories. But when a "Factory" module is unloaded the pointers to the created objects become into dangling pointers causing a total crash.

I was considering the creation of a registry of shared_ptr in each Factory in order to track then but I would like know if there is another way.

Cheers

Offline

#2 2014-12-15 03:47:08

sascha
Administrator
Registered: 2012-05-04
Posts: 45

Re: Management of shared objects.

struct IFileProtocol
{
  virtual ~IFileProtocol() {}
  virtual void Foo() = 0;
};

class FileProtocolHandler : public IFileProtocol
{
private:

  us::ServiceTracker<IFileProtocol> m_FileProtocolTracker;

public:

  FileProtocolHandler(us::ModuleContext* context, /* service props if needed */)
   : m_FileProtocolTracker(context)
  {
    m_FileProtocolTracker.Open();
  }

  // IFileProtocol interface
  void Foo()
  {
    if(IFileProtocol* fileProto = m_FileProtocolTracker.GetService())
    {
      return fileProto->Foo();
    }
    else
    {
      // fallback / warning msg / etc
    }
  }
};

Offline

#3 2014-12-15 22:43:48

Alexis
Member
Registered: 2014-12-12
Posts: 4

Re: Management of shared objects.

I was checking the  PrototypeServiceFactory documentation and I found that it makes a cache of the object service per module. This means that i can't get different service objects for the same module?

Cheers

Last edited by Alexis (2014-12-15 22:47:42)

Offline

#4 2014-12-15 22:56:03

sascha
Administrator
Registered: 2012-05-04
Posts: 45

Re: Management of shared objects.

Offline

#5 2014-12-15 23:01:11

Alexis
Member
Registered: 2014-12-12
Posts: 4

Re: Management of shared objects.

So as long as I register my Factory services as  PrototypeServiceFactory and use ServiceObjects::GetService()  from clients I will get different objects.

Thanks a lot!

Offline

#6 2014-12-15 23:11:19

sascha
Administrator
Registered: 2012-05-04
Posts: 45

Re: Management of shared objects.

Offline

Board footer

Powered by FluxBB