mercredi 4 août 2021

Scope of shared pointer in this clippet

  void RecHouse::createRec( const std::string& SourceId,
                                           const std::string& Name,
                                           const std::string& Location,
                                           const std::string& Description,
                                           const std::string& Address,
                                           const std::string& Content,
                                           const std::string& MaxTime,
                                           std::string& RecToken,
                                           bool defRec )
    {
       std::shared_ptr<Recording> rec = std::make_shared<Recording>(
            Recording( SourceId, Name, Location,
                       Description, Address, Content,
                       MaxTime, m_EventList,
                       m_eventServiceResource ));

        LOG("finished: create rec object");

        m_eventServiceResource->GetEventProducerManager()->RegisterEventProducer( std::weak_ptr<Recording>(recording) );
        RecordingToken = recording->getToken();
        if ( m_RecordingList.count( RecordingToken ) )
        {
            throw onvif_exception( BadConfiguration );
        }
        m_RecordingList[ RecordingToken ] = recording;
        updateFindRecordings();
        m_serialize.serialize( this );
        LOG ("fn end : create rec object");
    }

What is the scope of the shared pointer rec ? does it finish by the end of the function createRec because it is not transferred to another shared pointer ? It is sent to RegisterEventProducer as an argument but only as a weak pointer. This weak pointer is further stored in a list of weak pointers and is not getting put into a shared pointer for use elsewhere.

Aucun commentaire:

Enregistrer un commentaire