3

We are using Poco in our project and we've found 3 cases where we are embarrassed with poco and its pointer gesture.

In most of cases when you call a mathod of a poco class, it take in parameter a Poco::SharedPtr<> but sometimes, it take a pointer in parameter. After it take ownership of the pointer creating a SharedPtr<> inside its class.

Sometime we would like to provide a class to poco keeping the ownership of it. For example to prevent it from being detroy at the end of each call.

For example, this class use the poco::TaskManager class to run a task. But we must be very careful about this because the ownership of the object we have created belongs to poco::TaskManager.

CMyClass()
{

  m_xplTask = new CXplServiceTask(...);

  //task manager take the ownership !! (why ??)
  m_taskManager.start(m_xplTask);
}

~CMyClass()
{
    //do not delete m_xplTask; because owned by Poco::TaskManager ;-(
}

Another example :

We use a CRestRequestHandler pointer named p in a locally context to provide it to the HTTPServer. but we must create it at each call ! If we could we prefer to make a Poco::ShaaredPtr in member an simply return it. But if we do that with this pointer we can't know if the pointer is alive or not.

Poco::Net::HTTPRequestHandler* CHttpRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest& request)
{
  //do not keep pointers in shared_ptr or somewhere else, because poco take ownership ;-(

  if (boost::istarts_with(request.getURI(), m_webSocketKeyword))
     return new CWebSocketRequestHandler(m_notificationCenter);
  else if (boost::istarts_with(request.getURI(), m_restKeywordBase))
  {
     CRestRequestHandler * p = new CRestRequestHandler(m_restKeywordBase);

     //do some very long init
     std::vector< boost::shared_ptr<web::rest::service::IRestService> >::iterator i;
     for (i = m_restService.begin(); i != m_restService.end(); ++i)
        p->registerRestService(*i);
     p->initialize();

     return p;
  }
  else
  {
     CWebsiteRequestHandler * p = new CWebsiteRequestHandler(m_configDocRoot);
     std::map<std::string, std::string>::iterator i;
     for (i = m_alias.begin(); i != m_alias.end();++i)
        p->configureAlias(i->first, i->second);
     return p;
  }

}

the other case concern the TCPServerConnectionFactory already post in stack overflow: Can't use Poco TCPServer and TCPServerConnectionFactory

Why some methods always take ownership ? Is it not possible to have a signature to provide a SharedPtr<> instead ? I think there is not many modification into poco lib to do that.

Any explanation ?

lgm42
  • 591
  • 1
  • 6
  • 29
  • 4
    I think this question ("Why is this and that so and so ...") is too broad and rather belongs to the [pocoproject forum](http://pocoproject.org/forum/). – TobiMcNamobi Dec 08 '14 at 10:20
  • 1
    I think this question can interest other people and it has more visibility on stack overflow – lgm42 Dec 08 '14 at 10:28
  • This is indeed a question for the poco forum. There will be redesign of interfaces to some extent in 2.0, with alignment of poco shared per with standard one. Poco is open source and free - there is nothing preventing you from proposing changes and contributing code to alleviate your pains. – Alex Dec 09 '14 at 10:47
  • ok, I've just posted the question on poco forum. For those that interest : http://pocoproject.org/forum/viewtopic.php?f=12&t=6403 – lgm42 Dec 15 '14 at 10:44

1 Answers1

0

See discussion on the POCO Forum.

Alex
  • 5,159
  • 4
  • 25
  • 33