示例#1
0
void MainBook::CreateSession(SessionEntry& session, wxArrayInt* excludeArr)
{
    std::vector<LEditor*> editors;
    GetAllEditors(editors, kGetAll_RetainOrder);

    session.SetSelectedTab(0);
    std::vector<TabInfo> vTabInfoArr;
    for(size_t i = 0; i < editors.size(); i++) {

        if(excludeArr && (excludeArr->GetCount() > i) && (!excludeArr->Item(i))) {
            // If we're saving only selected editors, and this isn't one of them...
            continue;
        }

        if(editors[i] == GetActiveEditor()) {
            session.SetSelectedTab(vTabInfoArr.size());
        }
        TabInfo oTabInfo;
        oTabInfo.SetFileName(editors[i]->GetFileName().GetFullPath());
        oTabInfo.SetFirstVisibleLine(editors[i]->GetFirstVisibleLine());
        oTabInfo.SetCurrentLine(editors[i]->GetCurrentLine());

        wxArrayString astrBookmarks;
        editors[i]->StoreMarkersToArray(astrBookmarks);
        oTabInfo.SetBookmarks(astrBookmarks);

        std::vector<int> folds;
        editors[i]->StoreCollapsedFoldsToArray(folds);
        oTabInfo.SetCollapsedFolds(folds);

        vTabInfoArr.push_back(oTabInfo);
    }
    session.SetTabInfoArr(vTabInfoArr);
}
示例#2
0
bool SessionManager::addSession( std::string address, SessionType type )
{
    lockSessions();

    bool ret = true;
    bool audio = ( type == AUDIOSESSION );
    SessionEntry* entry = new SessionEntry( address, audio );
    Group* sessions = sessionMap[ type ];
    entry->setPos( sessions->getX(), sessions->getY() );
    Texture t = GLUtil::getInstance()->getTexture( "circle" );
    entry->setTexture( t.ID, t.width, t.height );

    if ( type != AVAILABLEVIDEOSESSION )
    {
        ret = ret && initSession( entry );
    }

    /*
     * Note - used to delete entries on fail. Now will display an entry in a
     * failed state, so it can potentially be reenabled when it could work.
     * (But still returns false on failed init)
     */

    sessions->add( entry );
    objectManager->lockSources();
    objectManager->addToDrawList( entry );
    objectManager->unlockSources();
    entry->show( shown, !shown );

    recalculateSize();

    unlockSessions();
    return ret;
}
示例#3
0
void MainBook::RestoreSession(SessionEntry &session)
{
    size_t sel = session.GetSelectedTab();
    const std::vector<TabInfo> &vTabInfoArr = session.GetTabInfoArr();
    for (size_t i = 0; i < vTabInfoArr.size(); i++) {
        const TabInfo &ti = vTabInfoArr[i];
        m_reloadingDoRaise = (i == vTabInfoArr.size()-1); // Raise() when opening only the last editor
        LEditor *editor = OpenFile(ti.GetFileName());
        if (!editor) {
            if (i < sel) {
                // have to adjust selected tab number because couldn't open tab
                sel--;
            }
            continue;
        }

        editor->ScrollToLine(ti.GetFirstVisibleLine());
        editor->SetEnsureCaretIsVisible(editor->PositionFromLine(ti.GetCurrentLine()));
        editor->LoadMarkersFromArray(ti.GetBookmarks());
        editor->LoadCollapsedFoldsFromArray(ti.GetCollapsedFolds());
    }
    // We can't just use SelectPane() here.
    // Notebook::DoPageChangedEvent has posted events to us,
    // which have the effect of selecting back to page 0
    // So post ourselves an event, so that it arrives after that one
    NotebookEvent event(wxEVT_COMMAND_BOOK_PAGE_CHANGED, GetId());
    event.SetSelection(sel);
    m_book->GetEventHandler()->AddPendingEvent(event);
}
示例#4
0
void MainBook::RestoreSession(SessionEntry& session)
{
    if(session.GetTabInfoArr().empty()) return; // nothing to restore

    CloseAll(false);
    size_t sel = session.GetSelectedTab();
    const std::vector<TabInfo>& vTabInfoArr = session.GetTabInfoArr();
    for(size_t i = 0; i < vTabInfoArr.size(); i++) {
        const TabInfo& ti = vTabInfoArr[i];
        m_reloadingDoRaise = (i == vTabInfoArr.size() - 1); // Raise() when opening only the last editor
        LEditor* editor = OpenFile(ti.GetFileName());
        if(!editor) {
            if(i < sel) {
                // have to adjust selected tab number because couldn't open tab
                sel--;
            }
            continue;
        }

        editor->SetFirstVisibleLine(ti.GetFirstVisibleLine());
        editor->SetEnsureCaretIsVisible(editor->PositionFromLine(ti.GetCurrentLine()));
        editor->LoadMarkersFromArray(ti.GetBookmarks());
        editor->LoadCollapsedFoldsFromArray(ti.GetCollapsedFolds());
    }
    m_book->SetSelection(sel);
}
示例#5
0
void PluginManager::StoreWorkspaceSession(const wxFileName& workspaceFile)
{
    if(workspaceFile.Exists()) {
        SessionEntry session;
        clMainFrame::Get()->GetMainBook()->CreateSession(session);
        session.SetWorkspaceName(workspaceFile.GetFullPath());
        SessionManager::Get().Save(session.GetWorkspaceName(), session);
    }
}
示例#6
0
void SessionManager::checkGUISessionShift()
{
    // this method doesn't do mutex locking - similar reasons to
    // sessionEntryAction(), see above for details

    Group* target;
    SessionGroup* parent = videoSessions;

    // just loop over video & available video for now
    for ( unsigned int i = 0; i < 2; i++ )
    {
        if ( parent == videoSessions )
        {
            target = availableVideoSessions;
        }
        else if ( parent == availableVideoSessions )
        {
            target = videoSessions;
        }

        std::vector<RectangleBase*> outsideList =
            parent->checkMemberIntersect();
        bool gotIntersect = false;

        for ( unsigned int i = 0; i < outsideList.size(); i++ )
        {
            SessionEntry* entry = dynamic_cast<SessionEntry*>( outsideList[i] );
            if ( entry == NULL )
            {
                gravUtil::logWarning( "SessionManager::checkGUISessionShift: "
                                      "invalid SessionGroup child?\n" );
            }
            else
            {
                // check intersect with projected destination, shift if so
                if ( entry->destIntersect( target ) )
                {
                    // we have to use the external method here to ensure that
                    // the side window GUI stays accurate - that will in turn
                    // call the shiftSession() method in this class
                    sessionTree->shiftSession( entry->getAddress(), false );
                    gotIntersect = true;
                }
            }
        }

        // rearrange when there was at least one object moved outside of the
        // group bounds but not in the target
        if ( outsideList.size() > 0 && !gotIntersect )
        {
            parent->rearrange();
        }

        parent = availableVideoSessions;
    }
}
示例#7
0
bool SessionManager::isInFailedState( std::string addr, SessionType type )
{
    lockSessions();

    SessionEntry* entry = findSessionByAddress( addr, type );
    if ( entry == NULL )
    {
        unlockSessions();
        return false;
    }

    bool ret = entry->isInFailedState();
    unlockSessions();
    return ret;
}
示例#8
0
bool SessionManager::isSessionProcessEnabled( std::string addr )
{
    lockSessions();

    SessionEntry* entry = findSessionByAddress( addr );
    if ( entry == NULL )
    {
        unlockSessions();
        return false;
    }

    bool ret = entry->isProcessingEnabled();
    unlockSessions();
    return ret;
}
示例#9
0
bool SessionManager::setSessionProcessEnable( std::string addr, bool set )
{
    lockSessions();

    SessionEntry* entry = findSessionByAddress( addr );
    if ( entry == NULL )
    {
        unlockSessions();
        return false;
    }

    entry->setProcessingEnabled( set );
    unlockSessions();
    return true;
}
示例#10
0
bool SessionManager::setEncryptionKey( std::string addr, std::string key )
{
    lockSessions();

    SessionEntry* entry = findSessionByAddress( addr );
    if ( entry == NULL )
    {
        unlockSessions();
        return false;
    }

    entry->setEncryptionKey( key );

    unlockSessions();
    return true;
}
示例#11
0
bool SessionManager::disableEncryption( std::string addr )
{
    lockSessions();

    SessionEntry* entry = findSessionByAddress( addr );
    if ( entry == NULL )
    {
        unlockSessions();
        return false;
    }

    entry->disableEncryption();

    unlockSessions();
    return true;
}
示例#12
0
bool SessionManager::isEncryptionEnabled( std::string addr )
{
    lockSessions();

    SessionEntry* entry = findSessionByAddress( addr );
    if ( entry == NULL )
    {
        unlockSessions();
        return false; // this doesn't quite make sense - should throw some other
        // kind of error for session not found?
    }

    bool ret = entry->isEncryptionEnabled();
    unlockSessions();
    return ret;
}
示例#13
0
bool SessionManager::Save(const wxString& name,
                          SessionEntry& session,
                          const wxString& suffix /*=wxT("")*/,
                          const wxChar* Tag /*=sessionTag*/)
{
    if(!m_doc.GetRoot()) {
        return false;
    }

    if(name.empty()) return false;

    wxXmlNode* child = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, Tag);
    child->AddProperty(wxT("Name"), name);

    Archive arch;
    arch.SetXmlNode(child);
    session.Serialize(arch);

    wxXmlDocument doc;
    doc.SetRoot(child);

    // If we're saving a tabgroup, suffix will be ".tabgroup", not the default ".session"
    const wxFileName& sessionFileName = GetSessionFileName(name, suffix);
    return doc.Save(sessionFileName.GetFullPath());
}
示例#14
0
bool SessionManager::GetSession(const wxString& workspaceFile,
                                SessionEntry& session,
                                const wxString& suffix,
                                const wxChar* Tag)
{
    if(!m_doc.GetRoot()) {
        return false;
    }

    wxFileName sessionFileName = GetSessionFileName(workspaceFile, suffix);
    wxXmlDocument doc;
    
    if(sessionFileName.FileExists()) {
        if(!doc.Load(sessionFileName.GetFullPath()) || !doc.IsOk()) return false;
    } else {
        doc.SetRoot(new wxXmlNode(NULL, wxXML_ELEMENT_NODE, Tag));
    }

    wxXmlNode* const node = doc.GetRoot();
    if(!node || node->GetName() != Tag) return false;

    Archive arch;
    arch.SetXmlNode(node);
    session.DeSerialize(arch);

    return true;
}
示例#15
0
bool SessionManager::iterateSessions()
{
    // kind of a hack to force this to wait, when removing etc.
    // mutex should do this but this thread seems way too eager
    if ( pause )
    {
        gravUtil::logVerbose( "Sessions temporarily paused...\n" );
        wxMicroSleep( 10 );
    }

    // note: iterate doesn't do lockSessions() since it shouldn't affect pause
    mutex_lock( sessionMutex );
    lockCount++;

    bool haveSessions = false;
    Group* sessions;
    SessionEntry* session;
    std::map<SessionType, Group*>::iterator i;

    // we iterate over the sessionmap here, instead of the regular group
    // children, since we might want to remove individual sessiongroups (like
    // audio) from that list for visual reasons
    for ( i = sessionMap.begin(); i != sessionMap.end(); ++i )
    {
        sessions = i->second;
        for ( int j = 0; j < sessions->numObjects(); j++ )
        {
            session = static_cast<SessionEntry*>( (*sessions)[j] );
            haveSessions = session->iterate() || haveSessions;
        }

        if ( haveSessions && gravApp::threadDebug )
        {
            if ( session->getTimestamp() % 1000 == 0 )
            {
                gravUtil::logVerbose( "SessionManager::iterate: "
                                      "have %u sessions in this group, last TS=%u\n",
                                      sessions->numObjects(), session->getTimestamp() );
            }
        }
    }

    lockCount--;
    mutex_unlock( sessionMutex );

    return haveSessions;
}
示例#16
0
SessionEntry* SessionManager::findSessionByAddress( std::string address,
        SessionType type )
{
    Group* sessions = sessionMap[ type ];
    SessionEntry* session;

    for ( int j = 0; j < sessions->numObjects(); j++ )
    {
        session = dynamic_cast<SessionEntry*>( (*sessions)[j] );
        if ( session != NULL && session->getAddress().compare( address ) == 0 )
            return session;
    }

    gravUtil::logWarning( "SessionManager::findSessionByAddress: session %s "
                          "not found\n", address.c_str() );
    return NULL;
}
示例#17
0
void BreakptMgr::LoadSession(const SessionEntry& session)
{
    const std::vector<BreakpointInfo>& breakpoints = session.GetBreakpoints();
    for (std::vector<BreakpointInfo>::const_iterator itr = breakpoints.begin(); itr != breakpoints.end(); ++itr) {
        BreakpointInfo bp = *itr;
        bp.internal_id = GetNextID();
        bp.origin      = BO_Editor;
        AddBreakpoint(bp);
    }
    RefreshBreakpointMarkers();
}
示例#18
0
std::string SessionManager::getCurrentRotateSessionAddress()
{
    lockSessions();

    if ( rotatePos != -1 && rotatePos < availableVideoSessions->numObjects() )
    {
        SessionEntry* entry = static_cast<SessionEntry*>(
                                  (*availableVideoSessions)[ rotatePos ] );
        if ( entry != NULL )
        {
            unlockSessions();
            return entry->getAddress();
        }
    }

    gravUtil::logVerbose( "SessionManager::getCurrentRotateSessionAddress: "
                          "failed to find valid session (rotate position %i)",
                          rotatePos );
    unlockSessions();
    return "";
}
示例#19
0
// 数据处理函数
// @sess session标识
// @data 收到的数据起始指针
// @bytes 收到的数据长度
// @returns: 返回一个size_t, 表示已处理的数据长度. 当返回-1时表示数据错误, 链接即会被关闭.
size_t OnMessage(SessionEntry sess, const char* data, size_t bytes)
{
    printf("receive: %.*s\n", (int)bytes, data);
    sess->Shutdown();   // 收到回复后关闭连接
    return bytes;
}
示例#20
0
// 数据处理函数
// @sess session标识
// @data 收到的数据起始指针
// @bytes 收到的数据长度
// @returns: 返回一个size_t, 表示已处理的数据长度. 当返回-1时表示数据错误, 链接即会被关闭.
size_t OnMessage(SessionEntry sess, const char* data, size_t bytes)
{
    printf("receive: %.*s\n", (int)bytes, data);
    sess->Send(data, bytes);    // Echo. 将收到的数据原样回传
    return bytes;
}
示例#21
0
void BreakptMgr::SaveSession(SessionEntry& session)
{
    session.SetBreakpoints(m_bps);
}