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; }
bool ActionMail::Execute() { IPCam *camera = NULL; if (mail_attachment != "") { Input *in = ListeRoom::Instance().get_input(mail_attachment); Output *out = NULL; if (!in) out = ListeRoom::Instance().get_output(mail_attachment); if (in) { CamInput *camin = reinterpret_cast<CamInput *>(in); if (camin) camera = camin->get_cam(); } if (out) { CamOutput *camout = reinterpret_cast<CamOutput *>(out); if (camout) camera = camout->get_cam(); } } if (camera) { cInfoDom("rule.action.mail") << "Need to download camera (" << camera->get_param("name") << ") attachment"; 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([=](string signal, void *sender_data) { if (signal == "done") { mail_attachment_tfile = *(reinterpret_cast<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; }