Ejemplo n.º 1
0
Connection::~Connection ()
{
	qDebug("Connection::~Connection() this=0x%08x", this);

	m_main_window->dockManager().removeActionAble(*this);
	recurse(m_data, UnregisterDockedWidgets(*m_main_window));

	if (m_tcpstream)
	{
		QObject::disconnect(m_tcpstream, SIGNAL(readyRead()), this, SLOT(processReadyRead()));
		QObject::disconnect(m_tcpstream, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
	}
	if (m_tcpstream)
		m_tcpstream->close();
	closeStorage();

	qDebug("destroying docked widgets");
	recurse(m_data, DestroyDockedWidgets(*m_main_window, *this));

	if (m_file_tlv_stream)
	{
		QIODevice * const f = m_file_tlv_stream->device();
		f->close();
		delete m_file_tlv_stream;
		m_file_tlv_stream = 0;
		delete f;
	}

	if (m_file_csv_stream)
	{
		QIODevice * const f = m_file_csv_stream->device();
		f->close();
		delete m_file_csv_stream;
		m_file_csv_stream = 0;
		delete f;
	}
}
Ejemplo n.º 2
0
/*============================================================================
  Description: (API call) Removes a given storage or stream from the 
               structured storage file.
  Arguments:   
   io_pParent - storage containing the item to destroy
   in_pName -   name of item to destroy
  Return:       
   Status code
  ==========================================================================*/
int 
destroy( Storage* io_pParent, const wchar_t* in_pName)
{
    SINT4           iRet =         SSTG_OK;
    TOC*            pTOC =         NULL;
    DirectoryEntry* pParentEntry = NULL;
    DirectoryEntry* pChildEntry =  NULL;
    StgInfo*        pStgChildren = NULL;
    SINT4           childCount =   0;
    SINT4           i =            0;
    Storage*        pStorage =     0;
    Header*         pHeader =      NULL;
    Fat*            pRegFat =      NULL;
    Fat*            pSmallFat =    NULL;
    
    ASSERT(io_pParent != NULL);
    ASSERT(in_pName != NULL);
    ASSERT(STG_CANWRITE(io_pParent->mode));

    if ((io_pParent == NULL) || (in_pName == NULL))
    {
        return SSTG_ERROR_ILLEGAL_CALL;
    }
    if (!STG_CANWRITE(io_pParent->mode))
    {
        return SSTG_ERROR_ILLEGAL_ACCESS;
    }

    pRegFat = rootStorageGetFat(io_pParent->pRoot);
    pSmallFat = rootStorageGetSmallFat(io_pParent->pRoot);

    /* Get parent storage's directory entry */
    pTOC = rootStorageGetTOC(io_pParent->pRoot);
    pParentEntry = tocGetEntryAtIndex(pTOC, io_pParent->ulDirIndex);
    if (pParentEntry == NULL)
    {
        return (int)SSTG_ERROR_CHILD_NOT_FOUND;
    }

    /* Find specified stream's directory entry */
    iRet = tocFindChildEntry (pTOC,
                              pParentEntry,
                              in_pName,
                              &pChildEntry);
    if (iRet != SSTG_OK)
    {
        return (int)iRet;
    }

    /* Ensure that the deletion operation is legal */
    if ((directoryGetType(pChildEntry) != DIR_STREAM) &&
        (directoryGetType(pChildEntry) != DIR_STORAGE))
    {
        return SSTG_ERROR_ILLEGAL_ACCESS;
    }

    /* From this point on, any failures will cause an incomplete state in
     * the structured storage file.  */

    /* Mark all metadata as being dirty so it will be rewritten later */
    iRet = rootStorageSetDirty(io_pParent->pRoot);
    if (iRet != SSTG_OK)
    {
        return (int)iRet;
    }

    if (directoryGetType(pChildEntry) == DIR_STREAM)
    {
        pHeader = rootStorageGetHeader(io_pParent->pRoot);
        if (directoryGetStreamLength(pChildEntry) < 
            headerGetSmallStreamCutoff(pHeader))
        {
            /* Merge the sectors of the stream into the free chain */
            iRet = fatFreeChain(pSmallFat,
                                directoryGetStartSector(pChildEntry));
            if (iRet != SSTG_OK)
            {
                return iRet;
            }

            /* Recover as many sectors as possible from the small FAT's free 
             * chain */
            iRet = fatRecoverMiniFatFreeSectors(pSmallFat, pRegFat);
            if (iRet != SSTG_OK)
            {
                return iRet;
            }
        }
        else
        {
            /* Merge the sectors of the stream into the free chain */
            iRet = fatFreeChain(pRegFat, directoryGetStartSector(pChildEntry));
            if (iRet != SSTG_OK)
            {
                return iRet;
            }
        }
    }
    else if (directoryGetType(pChildEntry) == DIR_STORAGE)
    {
        /* Non-empty storages should be removed recursively */
        iRet = openStorage(io_pParent, in_pName, &pStorage);
        if (iRet != SSTG_OK)
        {
            return iRet;
        }

        iRet = getChildrenInfo(pStorage, &pStgChildren, (int*)(void*)&childCount);
        if (iRet != SSTG_OK)
        {
            return iRet;
        }
        for (i = 0; i < childCount; i++)
        {
            iRet = destroy(pStorage, pStgChildren[i].sName);
            if (iRet != SSTG_OK)
            {
                return iRet;
            }
        }

        if (childCount > 0)
        {
            iRet = freeInfo(&pStgChildren, childCount);
            if (iRet != SSTG_OK)
            {
                return iRet;
            }
        }

        iRet = closeStorage(&pStorage);
        if (iRet != SSTG_OK)
        {
            return iRet;
        }
    }

    /* Remove the corresponding entry from the TOC */
    iRet = tocRemoveEntry(pTOC, pParentEntry, pChildEntry);
    if (iRet != SSTG_OK)
    {
        return (int)iRet;
    }

#ifdef DEBUG
    assertMiniStreamIntegrity(io_pParent->pRoot);
#endif /* DEBUG */

    return (int) iRet;
}