コード例 #1
0
void JsonApiHandlerHttp::processGetCameraPic()
{
    int pid;
    Utils::from_string(jsonParam["camera_id"], pid);
    if (pid < 0 || pid >= CamManager::Instance().get_size())
    {
        json_t *jret = json_object();
        json_object_set_new(jret, "success", json_string("false"));
        json_object_set_new(jret, "error_str", json_string("camera_id not set"));
        sendJson(jret);
        return;
    }

    IPCam *camera = CamManager::Instance().get_camera(pid);

    string w, h;
    if (jsonParam.Exists("width"))
        w = jsonParam["width"];
    if (jsonParam.Exists("height"))
        h = jsonParam["height"];

    string cmd = "calaos_thumb \"" + camera->getPictureUrl() + "\" \"" + tempfname + "\"";
    if (w.empty() || h.empty())
        cmd += " " + w + "x" + h;
    exe_thumb = ecore_exe_run(cmd.c_str(), nullptr);
}
コード例 #2
0
bool ActionMail::Execute()
{
    IPCam *camera = NULL;

    if (mail_attachment != "")
        camera = dynamic_cast<IPCam *>(ListeRoom::Instance().get_io(mail_attachment));

    if (camera)
    {
        cInfoDom("rule.action.mail") <<  "Need to download camera ("
                                      << camera->get_param("name")
                                      << ") attachment";

        std::string tmpFile;
        int cpt = 0;

        //Get a temporary filename
        do
        {
            tmpFile = "/tmp/calaos_mail_attachment_";
            tmpFile += Utils::to_string(cpt);
            cpt++;
        }
        while (ecore_file_exists(tmpFile.c_str()));

        // Autodestroy file downloader
        cDebug() << "DL URL: " << camera->getPictureUrl();
        FileDownloader* downloader = new FileDownloader(camera->getPictureUrl(), tmpFile, true);
        downloader->addCallback([=](std::string signal, void *sender_data)
        {
            if (signal == "done")
            {
                mail_attachment_tfile = *(reinterpret_cast<std::string *>(sender_data));
                sendMail();
            }
            else if (signal == "failed" || signal == "aborted")
            {
                mail_attachment_tfile.clear();
                sendMail();
            }
        });
        downloader->Start();
    }
    else
    {
        sendMail();

        cInfoDom("rule.action.mail") <<  "Ok, mail is in queue";
    }

    return true;
}
コード例 #3
0
ファイル: JsonApi.cpp プロジェクト: choovin/calaos_base
json_t *JsonApi::buildJsonCameras()
{
    json_t *jdata = json_array();

    int cpt = 0;
    for (int i = 0;i < ListeRoom::Instance().get_nb_input();i++)
    {
        Input *in = ListeRoom::Instance().get_input(i);
        CamInput *ipcam = dynamic_cast<CamInput *>(in);
        if (ipcam)
        {
            IPCam *camera = ipcam->get_cam();

            json_t *jcam = json_object();
            json_object_set_new(jcam, "id", json_string(Utils::to_string(cpt).c_str()));
            json_object_set_new(jcam, "input_id", json_string(camera->get_param("iid").c_str()));
            json_object_set_new(jcam, "output_id", json_string(camera->get_param("oid").c_str()));
            json_object_set_new(jcam, "name", json_string(camera->get_param("name").c_str()));
            json_object_set_new(jcam, "type", json_string(camera->get_param("type").c_str()));
            json_object_set_new(jcam, "url_jpeg", json_string(camera->get_picture().c_str()));
            json_object_set_new(jcam, "url_mjpeg", json_string(camera->get_mjpeg_stream().c_str()));
            Params caps = camera->getCapabilities();
            if (caps["ptz"] == "true")
                json_object_set_new(jcam, "ptz", json_string("true"));
            else
                json_object_set_new(jcam, "ptz", json_string("false"));

            cpt++;

            json_array_append_new(jdata, jcam);
        }
    }

    return jdata;
}