void AVReceiver::delConnection(Ecore_Con_Server *srv)
{
    if (srv != econ) return;

    DELETE_NULL(timer_con);

    cWarningDom("output") << "Main Connection closed !";
    cWarningDom("output") << "Trying to reconnect...";

    timer_con = new EcoreTimer(AVR_RECONNECT, (sigc::slot<void>)sigc::mem_fun(*this, &AVReceiver::timerConnReconnect));

    isConnected = false;
}
Example #2
0
void OwCtrl::processNewMessage(const string &msg)
{
    json_error_t jerr;
    json_t *jroot = json_loads(msg.c_str(), 0, &jerr);

    if (!jroot || !json_is_array(jroot))
    {
        cWarningDom("1wire") << "Error parsing json from sub process: " << jerr.text;
        if (jroot)
            json_decref(jroot);
        return;
    }

    int idx;
    json_t *value;

    json_array_foreach(jroot, idx, value)
    {
        Params p;
        jansson_decode_object(value, p);

        if (p.Exists("id"))
        {
            if (p.Exists("value"))
                mapValues[p["id"]] = p["value"];
            if (p.Exists("type"))
                mapValues[p["id"]] = p["type"];
        }
    }
Example #3
0
void AudioPlayer::unregisterChange()
{
    changeReg--;

    if (changeReg < 0)
    {
        cWarningDom("network") << "called too many times !";
        changeReg = 0;
    }

    if (changeReg == 0)
        DELETE_NULL(timer_change);
}
void ActionStd::Add(IOBase *out)
{
    if (!out->isOutput())
    {
        cWarningDom("rule.action.standard") << "Unable to add IO "
                                            << out->get_param("id")
                                            << " to action list. IO is not an output";
        return;
    }

    outputs.push_back(out);

    cDebugDom("rule.action.standard") <<  "Output(" << out->get_param("id") << ") added";
}
Example #5
0
OwCtrl::OwCtrl(const string &args)
{
    cDebugDom("1wire") << "new OWCtrl: " << args;
    process = new ExternProcServer("1wire");

    exe = Prefix::Instance().binDirectoryGet() + "/calaos_1wire";

    process->messageReceived.connect(sigc::mem_fun(*this, &OwCtrl::processNewMessage));

    process->processExited.connect([=]()
    {
        //restart process when stopped
        cWarningDom("process") << "process exited, restarting...";
        process->startProcess(exe, "1wire", args);
    });

    process->startProcess(exe, "1wire", args);
}
Example #6
0
void CalaosCameraView::requestCompleted()
{
    if (single_frame)
    {
        evas_object_image_memfile_set(camImage, &buffer[0], buffer.size(), NULL, NULL);

        Evas_Load_Error err = evas_object_image_load_error_get(camImage);
        if (err != EVAS_LOAD_ERROR_NONE)
            cErrorDom("camera") << "could not load image. error string is \"%s\"" << evas_load_error_str(err);
    }

    if (format_error)
        return;

    EcoreTimer::singleShot(0, [=]()
    {
        if (!single_frame)
            cWarningDom("camera") << "Restarting request to camera...";
        play();
    });
}
void AVReceiver::processMessage(std::vector<char> msg)
{
    cWarningDom("output") << "Should be inherited !";
}
void AVReceiver::processMessage(std::string msg)
{
    cWarningDom("output") << "Should be inherited !";
}
Example #9
0
void CalaosCameraView::processData()
{
    if (!formatDetected)
    {
        //first frame, we need to look for the boundary
        //and for content-type/content-length if present
        if (buffer.size() < 4)
            return; //need more data

        if (buffer[0] != '-' || buffer[1] != '-')
        {
            //try to detect of the data is directly the jpeg picture
            if (buffer[0] == 0xFF && buffer[1] == 0xD8)
            {
                cWarningDom("camera") << "Data seems to be a single frame.";
                single_frame = true;
            }
            else
            {
                cWarningDom("camera") << "Wrong start of frame, give up!";
                format_error = true;
            }

            formatDetected = true;
            return;
        }

        //search for the line end after the boundary to get the boundary text
        int end, next;
        if (!readEnd(2, end, next))
        {
            if (buffer.size() > 500)
            {
                cWarningDom("camera") << "Boundary not found, give up!";
                format_error = true;
            }

            return; //need more data;
        }

        //get boundary
        boundary = string((char *)&buffer[0], end);

        cDebugDom("camera") << "Found boundary \"" << boundary << "\"";

        int i = next;
        while (readEnd(next, end, next))
        {
            int len = end - i;

            if (len == 0)
            {
                //line is empty, data starts now
                nextDataStart = next;
                formatDetected = true;
                scanpos = 0;
                break;
            }

            if (len > 15)
            {
                string s((char *)&buffer[i], len);
                if (Utils::strStartsWith(s, "Content-Length", Utils::CaseInsensitive))
                {
                    Utils::from_string(s.substr(15), nextContentLength);
                    cDebugDom("camera") << "Found content length header: \"" << nextContentLength << "\"";
                    //nextContentLength = -1; //to test code without content-length header
                }
            }

            i = next;
        }

        if (!formatDetected)
        {
            cWarningDom("camera") << "need more data...";
            return;
        }
    }

    if (formatDetected && !single_frame)
    {
        //we should be positionned at the start of data
        //small check to be sure
        if (buffer.size() <= nextDataStart)
        {
            cWarningDom("camera") << "need more data...";
            return;
        }

        if (!(buffer[nextDataStart] == 0xFF && buffer[nextDataStart + 1] == 0xD8))
        {
            cWarningDom("camera") << "Wrong image data.";
            format_error = true;

            EcoreTimer::singleShot(0, [=]()
            {
                cDebugDom("camera") << "Cancel stream";
                ecore_con_url_free(ecurl);
                ecurl = nullptr;
            });

            return;
        }

        if (nextContentLength >= 0)
        {
            //the content-length is known, fast path
            if ((int)buffer.size() < nextContentLength + nextDataStart + 2)
                return; //need more data

            cDebugDom("camera") << "Set new frame";

            evas_object_image_memfile_set(camImage, &buffer[nextDataStart], nextContentLength, NULL, NULL);
            //evas_object_image_size_get(camImage, &w, &h);

            if (buffer[nextDataStart + nextContentLength] == '\r') //assume a \n always follows \r
                nextContentLength += 2;
            else if (buffer[nextDataStart + nextContentLength] == '\n')
                nextContentLength += 1;

            //remove unused data from buffer
            auto iter = buffer.begin();
            buffer.erase(iter, iter + (nextDataStart + nextContentLength));

            //reset for next frame
            nextContentLength = -1;
            formatDetected = false;
            nextDataStart = 0;
            scanpos = 0;
        }
        else
        {
            uint i = 0;
            cDebugDom("camera") << "scanpos: " << scanpos;
            for (i = nextDataStart + scanpos;
                 i < buffer.size() - boundary.length();i++)
            {
                if (buffer[i] == '-' && buffer[i + 1] == '-' &&
                    !boundary.compare(0, boundary.length(), (const char *)&buffer[i], boundary.length()))
                {
                    //boundary found
                    //check for newline between boundary and data
                    nextContentLength = i - nextDataStart;
                    if (buffer[i - 2] == '\r')
                        nextContentLength -= 2;
                    else if (buffer[i - 1] == '\n')
                        nextContentLength -= 1;

                    evas_object_image_memfile_set(camImage, &buffer[nextDataStart], nextContentLength, NULL, NULL);
                    //evas_object_image_size_get(camImage, &w, &h);

                    if (buffer[nextDataStart + nextContentLength] == '\r') //assume a \n always follows \r
                        nextContentLength += 2;
                    else if (buffer[nextDataStart + nextContentLength] == '\n')
                        nextContentLength += 1;

                    //remove unused data from buffer
                    auto iter = buffer.begin();
                    buffer.erase(iter, iter + (nextDataStart + nextContentLength));

                    //reset for next frame
                    nextContentLength = -1;
                    formatDetected = false;
                    nextDataStart = 0;
                    scanpos = 0;
                    cDebugDom("camera") << "scanpos: " << scanpos << " --> return";
                    return;
                }
            }

            scanpos = i - nextDataStart;
            cDebugDom("camera") << "--> scanpos: " << scanpos;
        }
    }
}
bool FileDownloader::Start()
{
    cDebugDom("downloader") << "Start download (" << url << ")";

    if (url_con)
    {
        cWarningDom("downloader") << "A download is already in progress...";

        return false;
    }

    url_con = ecore_con_url_new(url.c_str());
    if (!url_con)
    {
        std::string err = "Failed to create Ecore_Con_Url";

        IPC::Instance().SendEvent("downloader::" + Utils::to_string(this),
                                  "failed",
                                  IPCData(new std::string(err), new Utils::DeletorT<std::string *>()),
                                  true);

        cb_signal.emit("failed", &err);
        cb_signal_user.emit("failed", &err, user_data);

        cErrorDom("downloader") << "Download failed: " << err;

        return false;
    }

    if (dest.empty())
    {
        //Create a temporary file for download
        int cpt = 0;

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

        dl_file = fopen(tmpFile.c_str(), "wb");
    }
    else
    {
        dl_file = fopen(dest.c_str(), "wb");
    }

    if (!dl_file)
    {
        std::string err = "Failed to open file";

        IPC::Instance().SendEvent("downloader::" + Utils::to_string(this),
                                  "failed",
                                  IPCData(new std::string(err), new Utils::DeletorT<std::string *>()),
                                  true);

        cb_signal.emit("failed", &err);
        cb_signal_user.emit("failed", &err, user_data);

        cErrorDom("downloader") << "Download failed: " << err;

        ecore_con_url_free(url_con);
        url_con = NULL;

        return false;
    }

    ecore_con_url_fd_set(url_con, fileno(dl_file));
    ecore_con_url_data_set(url_con, this);
    ecore_con_url_ssl_verify_peer_set(url_con, false);

    bool ret = false;
    if (postData.empty())
    {
        ret = ecore_con_url_get(url_con);
    }
    else
    {
        ret = ecore_con_url_post(url_con, postData.c_str(), postData.length(), postContentType.c_str());
    }

    if (!ret)
    {
        std::string err = "Failed to call GET/POST";

        IPC::Instance().SendEvent("downloader::" + Utils::to_string(this),
                                  "failed",
                                  IPCData(new std::string(err), new Utils::DeletorT<std::string *>()),
                                  true);

        cb_signal.emit("failed", &err);
        cb_signal_user.emit("failed", &err, user_data);

        cErrorDom("downloader") << "Download failed: " << err;

        ecore_con_url_free(url_con);
        url_con = NULL;
        fclose(dl_file);

        if (dest.empty())
            ecore_file_unlink(tmpFile.c_str());

        return false;
    }

    return true;
}
Example #11
0
void ModuleManager::SearchModules()
{
    for (uint i = 0; i < search_paths.size(); i++)
    {
        cInfoDom("module") << "ModuleManager: searching modules in: " << search_paths[i];
        char *fname = NULL;
        void *data = NULL;
        Eina_List *subdir = ecore_file_ls(search_paths[i].c_str());
        Eina_List *l = NULL;

        EINA_LIST_FOREACH(subdir, l, data)
        {
            fname = (char *)data;
            string p;

            p = search_paths[i];

            if (fname)
            {
                p += "/";
                p += fname;
            }
            if (p[p.length() - 1] != '/') p += "/";

            if (!ecore_file_is_dir(p.c_str()))
                continue;

            p += "module.so";

            if (!ecore_file_exists(p.c_str()))
                continue;

            bool alreadyin = false;
            for (uint im = 0; im < modules.size() && !alreadyin; im++)
            {
                ModuleDef mdef = modules[im];
                if (p == mdef.mod_fname)
                    alreadyin = true;
            }

            if (alreadyin) continue;

            //try to load the module
            void *handle = dlopen(p.c_str(), RTLD_LAZY);

            if (handle)
            {
                //object can be loaded, check version and
                CalaosModuleApi *api = (CalaosModuleApi *)dlsym(handle, "calaos_modapi");
                if (!api)
                {
                    dlclose(handle);
                    cErrorDom("module") << "ModuleManager: module " << p << ". calaos_modapi export not found: " << dlerror();
                    continue;
                }

                if (api->api_version != CALAOS_MODULE_API_VERSION)
                {
                    dlclose(handle);

                    cErrorDom("module") << "ModuleManager: module " << p << ". The API version doesn't match";

                    continue;
                }

                string module_name;
                vector<string> tok;
                Utils::split(p, tok, "/");
                if (tok.size() > 2)
                    module_name = tok[tok.size() - 2];

                string themepath = Prefix::Instance().dataDirectoryGet();
                themepath += "/widgets/" + module_name;

                ModuleDef mdef;
                mdef.mod_name = gettext(api->name);
                mdef.mod_desc = gettext(api->desc);
                mdef.mod_version = api->version;
                mdef.mod_author = api->author;
                mdef.mod_icon = themepath + "/icon.edj";
                mdef.mod_fname = p;
                mdef.handle = handle;
                mdef.inst = NULL;
                mdef.api = api;

                cInfoDom("module") << "ModuleManager: found module: " << mdef.mod_name;

                modules.push_back(mdef);
            }
            else
            {
                cWarningDom("module") << "ModuleManager: file " << p << " : failed to dlopen: " << dlerror();
            }

        }

        EINA_LIST_FREE(subdir, data)
        free(data);
    }