派生自 development/c++

pansen
2019-03-07 d3b7bbe7102cd089680a828f5d8f6402c8cf6342
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "StructureAppI.h"
Ice::Int StructureAppI::addCamera(Ice::Int index, const std::string &json, const Ice::Current &current)
{
    if(controllers.find(index)==controllers.end()){
        if(currentCount>=maxCount){
            ERR("addCamera faild, camera's num is full!")
            return -1;
        }
        Json::CharReaderBuilder builder;
        auto reader = builder.newCharReader();
        Json::Value value;
        reader->parse(json.data(), json.data() + json.size(), &value, nullptr);
        controllers[index] = new AppPipeController(index,std::move(value));
        controllers[index]->start();
        currentCount++;
        return 0;
    }else{
        removeCamera(index,current);
        DBG("removeCamera "<<index)
        return addCamera(index,json,current);
    }
}
 
Ice::Int StructureAppI::removeCamera(Ice::Int index, const Ice::Current &)
{
    if(controllers.find(index)==controllers.end())return -1;
    auto controller = controllers[index];
    controller->stop();
    controller->wait();
    delete controller;
    controllers.erase(index);
    currentCount--;
    return 0;
}
 
Ice::Int StructureAppI::removeAll(const Ice::Current &)
{
    for(auto controller: controllers){
        controller.second->stop();
    }
    for(auto controller: controllers){
        controller.second->wait();
        delete controller.second;
    }
    controllers.clear();
    currentCount = 0;
    return 0;
}
 
Ice::Int StructureAppI::getMaxCamCount(const Ice::Current &)
{
    return maxCount;
}
 
Ice::Int StructureAppI::getCurrentCamCount(const Ice::Current &)
{
    return currentCount;
}
 
int StructureAppI::addVedio(int index, string path,string state)
{
    if(controllers.find(index)==controllers.end()){
        if(currentCount>=maxCount){
            ERR("addCamera faild, camera's num is full!")
            return -1;
        }
        Json::Value json;
        json["rtsp"] = path;
        json["state"] = state;
        controllers[index] = new AppPipeController(index,json);
        controllers[index]->start();
        currentCount++;
        return 0;
    }/*else
    {
        removeCamera(index,current);
        DBG("removeCamera "<<index)
        return addCamera(index,json,current);
    }*/
}
 
string StructureAppI::getRtmp(Ice::Int index, const Ice::Current &)
{
    if(controllers.find(index)==controllers.end())return "";
    auto controller = controllers[index];
    return controller->getRtmp();
}