~ubuntu-branches/ubuntu/lucid/mythtv/lucid

« back to all changes in this revision

Viewing changes to programs/mythbackend/mainserver.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2009-10-02 00:23:18 UTC
  • mfrom: (1.1.36 upstream)
  • Revision ID: james.westby@ubuntu.com-20091002002318-5qu2fr0gxl59egft
Tags: 0.22.0~trunk22167-0ubuntu1
* New upstream checkout (r22167).
  - Fixes some segfaults.

Show diffs side-by-side

added added

removed removed

Lines of Context:
532
532
    {
533
533
        HandlePixmapLastModified(listline, pbs);
534
534
    }
 
535
    else if (command == "QUERY_PIXMAP_GET_IF_MODIFIED")
 
536
    {
 
537
        HandlePixmapGetIfModified(listline, pbs);
 
538
    }
535
539
    else if (command == "QUERY_ISRECORDING")
536
540
    {
537
541
        HandleIsRecording(listline, pbs);
2884
2888
    QString wantHost = sList.at(1);
2885
2889
    QString groupname = sList.at(2);
2886
2890
    QString path = sList.at(3);
 
2891
    bool fileNamesOnly = false;
2887
2892
    QStringList strList;
2888
2893
 
 
2894
    if (sList.size() >= 5)
 
2895
        fileNamesOnly = sList.at(4).toInt();
 
2896
 
2889
2897
    bool slaveUnreachable = false;
2890
2898
 
2891
2899
    VERBOSE(VB_FILE, QString("HandleSGGetFileList: group = %1  host = %2  path = %3 wanthost = %4").arg(groupname).arg(host).arg(path).arg(wantHost));
2895
2903
    {
2896
2904
        StorageGroup sg(groupname, host);
2897
2905
        VERBOSE(VB_FILE, QString("HandleSGGetFileList: Getting local info"));
2898
 
        strList = sg.GetFileList(path);
 
2906
        if (fileNamesOnly)
 
2907
            strList = sg.GetFileList(path);
 
2908
        else
 
2909
            strList = sg.GetFileInfoList(path);
2899
2910
    }
2900
2911
    else
2901
2912
    {
2903
2914
        if (slave)
2904
2915
        {
2905
2916
            VERBOSE(VB_FILE, QString("HandleSGGetFileList: Getting remote info"));
2906
 
            strList = slave->GetSGFileList(wantHost, groupname, path);
 
2917
            strList = slave->GetSGFileList(wantHost, groupname, path,
 
2918
                                           fileNamesOnly);
2907
2919
            slave->DownRef();
2908
2920
            slaveUnreachable = false;
2909
2921
        }
3092
3104
    MythSocket *pbssock = pbs->getSocket();
3093
3105
    QString pbshost = pbs->getHostname();
3094
3106
 
 
3107
    vector<uint> excluded_cardids;
3095
3108
    QStringList strlist;
3096
3109
    int retval = -1;
3097
3110
 
3116
3129
                enchost = elink->GetHostName();
3117
3130
 
3118
3131
            if (enchost == pbshost && elink->IsConnected() &&
3119
 
                !elink->IsBusy() && !elink->IsTunerLocked())
 
3132
                !elink->IsTunerLocked() &&
 
3133
                !elink->GetFreeInputs(excluded_cardids).empty())
3120
3134
            {
3121
3135
                encoder = elink;
3122
3136
                retval = iter.key();
3127
3141
        }
3128
3142
 
3129
3143
        if ((retval == -1 || lastcard) && elink->IsConnected() &&
3130
 
            !elink->IsBusy() && !elink->IsTunerLocked())
 
3144
            !elink->IsTunerLocked() &&
 
3145
            !elink->GetFreeInputs(excluded_cardids).empty())
3131
3146
        {
3132
3147
            encoder = elink;
3133
3148
            retval = iter.key();
3167
3182
{
3168
3183
    MythSocket *pbssock = pbs->getSocket();
3169
3184
 
 
3185
    vector<uint> excluded_cardids;
3170
3186
    QStringList strlist;
3171
3187
    int count = 0;
3172
3188
 
3175
3191
    {
3176
3192
        EncoderLink *elink = *iter;
3177
3193
 
3178
 
        if ((elink->IsConnected()) &&
3179
 
            (!elink->IsBusy()) &&
3180
 
            (!elink->IsTunerLocked()))
 
3194
        if (elink->IsConnected() && !elink->IsTunerLocked() &&
 
3195
            !elink->GetFreeInputs(excluded_cardids).empty())
3181
3196
        {
3182
3197
            count++;
3183
3198
        }
3199
3214
    {
3200
3215
        EncoderLink *elink = *iter;
3201
3216
 
3202
 
        if ((elink->IsConnected()) &&
3203
 
            (!elink->IsBusy()) &&
3204
 
            (!elink->IsTunerLocked()))
 
3217
        if (elink->IsConnected() && !elink->IsTunerLocked() &&
 
3218
            !elink->IsBusy())
3205
3219
        {
3206
3220
            strlist << QString::number(iter.key());
3207
3221
        }
3234
3248
 
3235
3249
    if (currrec > 0 && curr != encoderList->end())
3236
3250
    {
 
3251
        vector<uint> excluded_cardids;
 
3252
        excluded_cardids.push_back(currrec);
 
3253
 
3237
3254
        // cycle through all recorders
3238
3255
        for (iter = curr;;)
3239
3256
        {
3247
3264
 
3248
3265
            elink = *iter;
3249
3266
 
3250
 
            if ((retval == -1) &&
3251
 
                (elink->IsConnected()) &&
3252
 
                (!elink->IsBusy()) &&
3253
 
                (!elink->IsTunerLocked()))
 
3267
            if (retval == -1 && elink->IsConnected() &&
 
3268
                !elink->IsTunerLocked() &&
 
3269
                !elink->GetFreeInputs(excluded_cardids).empty())
3254
3270
            {
3255
3271
                encoder = elink;
3256
3272
                retval = iter.key();
4617
4633
    delete pginfo;
4618
4634
}
4619
4635
 
 
4636
void MainServer::HandlePixmapGetIfModified(
 
4637
    const QStringList &slist, PlaybackSock *pbs)
 
4638
{
 
4639
    QStringList strlist;
 
4640
 
 
4641
    MythSocket *pbssock = pbs->getSocket();
 
4642
    if (slist.size() < (3 + NUMPROGRAMLINES))
 
4643
    {
 
4644
        strlist = QStringList("ERROR");
 
4645
        strlist += "1: Parameter list too short";
 
4646
        SendResponse(pbssock, strlist);
 
4647
        return;
 
4648
    }
 
4649
 
 
4650
    QDateTime cachemodified;
 
4651
    if (slist[1].toInt() != -1)
 
4652
        cachemodified.setTime_t(slist[1].toInt());
 
4653
 
 
4654
    int max_file_size = slist[2].toInt();
 
4655
 
 
4656
    ProgramInfo pginfo;
 
4657
 
 
4658
    if (!pginfo.FromStringList(slist, 3))
 
4659
    {
 
4660
        strlist = QStringList("ERROR");
 
4661
        strlist += "2: Invalid ProgramInfo";
 
4662
        SendResponse(pbssock, strlist);
 
4663
        return;
 
4664
    }
 
4665
 
 
4666
    pginfo.pathname = GetPlaybackURL(&pginfo) + ".png";
 
4667
    if (pginfo.pathname.left(1) == "/")
 
4668
    {
 
4669
        QFileInfo finfo(pginfo.pathname);
 
4670
        if (finfo.exists())
 
4671
        {
 
4672
            size_t fsize = finfo.size();
 
4673
            QDateTime lastmodified = finfo.lastModified();
 
4674
            bool out_of_date = !cachemodified.isValid() ||
 
4675
                (lastmodified > cachemodified);
 
4676
 
 
4677
            if (out_of_date && (fsize > 0) && ((ssize_t)fsize < max_file_size))
 
4678
            {
 
4679
                QByteArray data;
 
4680
                QFile file(pginfo.pathname);
 
4681
                bool open_ok = file.open(QIODevice::ReadOnly);
 
4682
                if (open_ok)
 
4683
                    data = file.readAll();
 
4684
 
 
4685
                if (data.size())
 
4686
                {
 
4687
                    VERBOSE(VB_FILE, QString("Read preview file '%1'")
 
4688
                            .arg(pginfo.pathname));
 
4689
                    strlist += QString::number(lastmodified.toTime_t());
 
4690
                    strlist += QString::number(data.size());
 
4691
                    strlist += QString::number(
 
4692
                        qChecksum(data.constData(), data.size()));
 
4693
                    strlist += QString(data.toBase64());
 
4694
                }
 
4695
                else
 
4696
                {
 
4697
                    VERBOSE(VB_IMPORTANT,
 
4698
                            QString("Failed to read preview file '%1'")
 
4699
                            .arg(pginfo.pathname));
 
4700
 
 
4701
                    strlist = QStringList("ERROR");
 
4702
                    strlist +=
 
4703
                        QString("3: Failed to read preview file '%1'%2")
 
4704
                        .arg(pginfo.pathname)
 
4705
                        .arg((open_ok) ? "" : " open failed");
 
4706
                }
 
4707
            }
 
4708
            else if (out_of_date && (max_file_size > 0))
 
4709
            {
 
4710
                if (fsize >= (size_t) max_file_size)
 
4711
                {
 
4712
                    strlist = QStringList("WARNING");
 
4713
                    strlist += QString("1: Preview file too big %1 > %2")
 
4714
                        .arg(fsize).arg(max_file_size);
 
4715
                }
 
4716
                else
 
4717
                {
 
4718
                    strlist = QStringList("ERROR");
 
4719
                    strlist += "4: Preview file is invalid";
 
4720
                }
 
4721
            }
 
4722
            else
 
4723
            {
 
4724
                strlist += QString::number(lastmodified.toTime_t());
 
4725
            }
 
4726
 
 
4727
            SendResponse(pbssock, strlist);
 
4728
            return;
 
4729
        }
 
4730
    }
 
4731
 
 
4732
    // handle remote ...
 
4733
    if (ismaster && pginfo.hostname != gContext->GetHostName())
 
4734
    {
 
4735
        PlaybackSock *slave = getSlaveByHostname(pginfo.hostname);
 
4736
        if (!slave)
 
4737
        {
 
4738
            strlist = QStringList("ERROR");
 
4739
            strlist +=
 
4740
                "5: Could not locate mythbackend that made this recording";
 
4741
            SendResponse(pbssock, strlist);
 
4742
            return;
 
4743
        }
 
4744
 
 
4745
        strlist = slave->ForwardRequest(slist);
 
4746
 
 
4747
        slave->DownRef(); slave = NULL;
 
4748
 
 
4749
        if (!strlist.empty())
 
4750
        {
 
4751
            SendResponse(pbssock, strlist);
 
4752
            return;
 
4753
        }
 
4754
    }
 
4755
 
 
4756
    strlist = QStringList("WARNING");
 
4757
    strlist += "2: Could not locate requested file";
 
4758
    SendResponse(pbssock, strlist);
 
4759
}
 
4760
 
4620
4761
void MainServer::HandleBackendRefresh(MythSocket *socket)
4621
4762
{
4622
4763
    gContext->RefreshBackendConfig();