PDL_bool receiveResultLoop(PDL_JSParameters *params) { pthread_mutex_lock(&callbackMutex); int numParams = PDL_GetNumJSParams(params); if(numParams == 0) { Funambol::LOG.info("JSCallback Loop failed."); pthread_cond_signal(&callbackReady); } else if(numParams < 6) { Funambol::LOG.info("Empty Loop."); pthread_cond_signal(&callbackReady); } else { Funambol::WString chunk = toWString(PDL_GetJSParamString(params,0)); int chunkIndex = PDL_GetJSParamInt(params,1); int numChunks = PDL_GetJSParamInt(params,2); int entryIndex = PDL_GetJSParamInt(params,3); int numEntries = PDL_GetJSParamInt(params,4); bool lastEventID = PDL_GetJSParamInt(params,5) != 0; if(chunkIndex != numChunks) { partlyResult += chunk; } else //chunkIndex == numChunks => last chunk! { if(lastEventID) //last chunk == eventId { //add parts until now as first result //and event id as second result. globalResults.push_back(partlyResult); globalResults.push_back(chunk); } else { partlyResult += chunk; globalResults.push_back(partlyResult); } partlyResult = ""; //clear result string for next entry. //was this the last entry in the list? if(entryIndex == numEntries) { //wake up processing thread, loop finished! pthread_cond_signal(&callbackReady); } } } pthread_mutex_unlock(&callbackMutex); return PDL_TRUE; }
PDL_bool GetAvgMagString(PDL_JSParameters *parms) { //ReportError("Entering Get Cur"); PDL_Err err; int32_t iTrack = PDL_GetJSParamInt(parms, 0); //ReportError1("GetAvg - iTrack:%i", iTrack); const char *cstrRet; cstrRet = g_MusController.PassMessage(MUS_MESSAGE_GET_MAG_STR, iTrack); //ReportError1("GetAvg:%s", cstrRet); err = PDL_JSReply(parms, cstrRet); if (err != PDL_NOERROR) { ReportError1("PDL_Init failed, err = %s", PDL_GetError()); return PDL_FALSE; } //ReportError("Exiting Get Cur"); return PDL_TRUE; }
PDL_bool SetNoNext(PDL_JSParameters *parms) { int32_t iTrack = PDL_GetJSParamInt(parms, 0); g_MusController.PassMessage(MUS_MESSAGE_SET_NO_NEXT, iTrack); return PDL_TRUE; }
PDL_bool SetBass(PDL_JSParameters *parms) { double fVal = PDL_GetJSParamDouble(parms, 0); int32_t iTrack = PDL_GetJSParamInt(parms, 1); g_MusController.PassMessage(MUS_MESSAGE_ATTRIB_SET, ATTRIB_BASSTREB_BASS_VAL, fVal, iTrack); return PDL_TRUE; }
PDL_bool SetNext(PDL_JSParameters *parms) { const char *cstrPath = PDL_GetJSParamString(parms, 0); double dGap = PDL_GetJSParamDouble(parms, 1); int32_t iTrack = PDL_GetJSParamInt(parms, 2); ReportError1("dGap val: %f", dGap); g_MusController.PassMessage(MUS_MESSAGE_SET_NEXT, cstrPath, dGap, iTrack); return PDL_TRUE; }
PDL_bool Open(PDL_JSParameters *parms) { const char *cstrPath = PDL_GetJSParamString(parms, 0); int32_t iTrack = PDL_GetJSParamInt(parms, 1); ReportError2("Open Message being created for %s, for track %i", cstrPath, iTrack); g_MusController.PassMessage(MUS_MESSAGE_OPEN_SONG, cstrPath, iTrack); return PDL_TRUE; }
PDL_bool Play(PDL_JSParameters *parms) { int32_t iTrack = PDL_GetJSParamInt(parms, 0); g_MusController.PassMessage(MUS_MESSAGE_ATTRIB_SET, ATTRIB_MUSCON_PAUSED, 0, iTrack); return PDL_TRUE; }
PDL_bool service::do_render(PDL_JSParameters* params) { boost::format my_formatter(filename_format); int from = PDL_GetJSParamInt(params, 1); int count = PDL_GetJSParamInt(params, 2); int zoom = PDL_GetJSParamInt(params, 3); std::string directory = PDL_GetJSParamString(params, 4); std::string prefix = PDL_GetJSParamString(params, 5); std::string suffix = PDL_GetJSParamString(params, 6); my_formatter % directory % prefix % zoom % suffix; // if (!ctx_.is_open()) // throw std::runtime_error("Document has not been opened yet"); int err = ::mkdir(directory.c_str(), 0755); if (err != 0 && errno != EEXIST) throw std::runtime_error("could not create directory"); LECTOR_LOG("Rendering call: from %d, count %d", from, count); for (int i = from; i < from + count; ++i) { std::string filename = (boost::format(my_formatter) % i).str(); if (::access(filename.c_str(), R_OK) == -1 && errno == ENOENT) { LECTOR_LOG("Starting rendering of page %d", i); queue_.push(std::make_tuple(zoom / 100.f, i, filename)); } else { LECTOR_LOG("Reusing cached image of page %d", i); std::string response_json = (boost::format(render_response) % i % filename).str(); const char* response = response_json.c_str(); PDL_CallJS("RenderCallback", &response, 1); } } return PDL_TRUE; }
PDL_bool Seek(PDL_JSParameters *parms) { ReportError("Entering Seek"); double seekTime = PDL_GetJSParamDouble(parms, 0); int32_t iTrack = PDL_GetJSParamInt(parms, 1); g_MusController.PassMessage(MUS_MESSAGE_SEEK, seekTime, iTrack); ReportError("Finishing Seek"); return PDL_TRUE; }
PDL_bool Pause(PDL_JSParameters *parms) { #ifdef PROFILE FMGUI_ChDir("/media/internal"); exit(0); #endif int32_t iTrack = PDL_GetJSParamInt(parms, 0); g_MusController.PassMessage(MUS_MESSAGE_ATTRIB_SET, ATTRIB_MUSCON_PAUSED, 1, iTrack); return PDL_TRUE; }
PDL_bool GetEndTime(PDL_JSParameters *parms) { //ReportError("Entering Get End"); PDL_Err err; int32_t iTrack = PDL_GetJSParamInt(parms, 0); const char *cstrRet; cstrRet = g_MusController.PassMessage(MUS_MESSAGE_GET_SONG_END, iTrack); err = PDL_JSReply(parms, cstrRet); if (err != PDL_NOERROR) { ReportError1("PDL_Init failed, err = %s", PDL_GetError()); return PDL_FALSE; } //ReportError("Exiting Get End"); return PDL_TRUE; }
PDL_bool dateToUTCTimestamp(PDL_JSParameters *params) { int numParams = PDL_GetNumJSParams(params); if(numParams < 4) { //problem: not enough params! PDL_JSException(params,"Not enough params, need TZName, Year, Month, Day, at least."); return PDL_TRUE; } const char* oldTZ = getenv("TZ"); struct std::tm t; setenv("TZ",PDL_GetJSParamString(params,0),true); tzset(); t.tm_year = PDL_GetJSParamInt(params,1)-1900; t.tm_mon = PDL_GetJSParamInt(params,2); //-1 already in JS. t.tm_mday = PDL_GetJSParamInt(params,3); if(numParams >= 5) t.tm_hour = PDL_GetJSParamInt(params,4); else t.tm_hour = 0; if(numParams >= 6) t.tm_min = PDL_GetJSParamInt(params,5); else t.tm_min = 0; if(numParams >= 7) t.tm_sec = PDL_GetJSParamInt(params,6); else t.tm_sec = 0; time_t time = std::mktime(&t); //this should produce a timestamp in UTC from the set timezone! Funambol::LOG.debug("Converted %02d.%02d.%04d - %02d:%02d:%02d to %d in timezone %s.",t.tm_mday,t.tm_mon+1,t.tm_year+1900,t.tm_hour,t.tm_min,t.tm_sec,time,getenv("TZ")); std::stringstream res; res << time; PDL_JSReply(params,res.str().c_str()); setenv("TZ",oldTZ,1); return PDL_TRUE; }