static void OnBackUpTimer(WID__ wid) { //DBGMSG("onbackuptimer 112!\n"); if(bk_nano.err_exit) { if(backup_tts_get_stopped()) { plextalk_set_hotplug_voice_disable(0); DBGMSG("[in]test:--- enable desktop tts\n"); TimerDisable(bk_nano.timer); NeuxAppStop(); } return; } if(bk_nano.iscdda) { if(bk_nano.ret_pathsize) { cdda_nano=&bk_nano; bk_nano.ret_pathsize = 0; DBGMSG("run backup_cdda!\n"); if (pthread_create(&back_pid, NULL, Backup_cdda, (void*)cdda_nano)) { DBGMSG("backup_cdda start pthread failure!\n"); return; }else{ DBGMSG("backup_cdda start pthread success!\n"); } //Backup_cdda(bk_nano.source, bk_nano.dest); } else{ DBGMSG("get prog_val !\n"); int ret = return_backup_error(); DBGMSG("return backup error ret:%d\n",ret); if(ret > 0) { switch(ret) { case CDDA_Remove: backup_tts(TTS_REMOVE_MEDIA_READ, 0); break; case SD_card_Remove: backup_tts(TTS_REMOVE_MEDIA_WRITE, 0); break; case Stroage_medium_Full: backup_tts(TTS_NOTMEM, 0); break; case Faile_to_backup: backup_tts(TTS_CDDA_WRITE_ERROR, 0); break; default: backup_tts(TTS_FAILBACKUP, 0); break; } bk_nano.err_exit = 1; return; } else{ bk_nano.thiz->prog_val = Return_precnet(); //DBGMSG("bk_nano.thiz->prog_val = %f \n",bk_nano.thiz->prog_val ); } } } else{ if(bk_nano.ret_pathsize) { DBGMSG("OnBackUpTimer \n"); if(bk_nano.pathtotal < bk_nano.freedir) { if(bk_nano.path_fp){ pclose(bk_nano.path_fp); bk_nano.path_fp = NULL; } DBGMSG("copy\n"); backup_copy(bk_nano.source, bk_nano.dest); } else{ DBGMSG("exit\n"); backup_tts(TTS_NOTMEM, 0); bk_nano.err_exit = 1; return; } bk_nano.ret_pathsize = 0; bk_nano.getting_size = 0; } } if(bk_nano.thiz->prog_val < 100.0) { if(backup_tts_get_stopped() && bk_nano.bgsound == 0) { bk_nano.bgsound = 1; } if(backup_tts_get_stopped() && bk_nano.bgsound == 1){ backup_tts(TTS_BG_MP3, 0); } //DBGMSG("bk_nano.thiz->prog_val = %f \n",bk_nano.thiz->prog_val ); switch(bk_nano.wait_state) { case 0: NeuxLabelSetText(bk_nano.label, _("Waiting.")); break; case 1: NeuxLabelSetText(bk_nano.label, _("Waiting..")); break; case 2: NeuxLabelSetText(bk_nano.label, _("Waiting...")); break; } if(bk_nano.wait_state < 2) bk_nano.wait_state++; else bk_nano.wait_state = 0; } else { //DBGMSG("bk_nano.thiz->prog_valaa = %f \n",bk_nano.thiz->prog_val ); DBGMSG("bk_nano.thiz->prog_val >= 100 g_end = %d\n", g_end); if(g_end) { if(backup_tts_get_stopped()) { TimerDisable(bk_nano.timer); NeuxAppStop(); DBGMSG("NeuxAppStop()\n"); } } else{ system("sync"); g_end= 1; backup_tts(TTS_COMPELTE, 0); } } }
void backup_pathsize_progress() { char strinfo[MAX_PATH_BYTES]; // ssize_t count; char *p; char *pread; int end = 0; long size = 0; memset(strinfo, 0, MAX_PATH_BYTES); pread = fgets(strinfo, sizeof(strinfo), bk_nano.path_fp); // count = read(bk_nano.path_fd, strinfo, 500); // DBGMSG("count = %d\n", count); if( NULL != pread){ DBGMSG("read:%s\n",strinfo); p = strstr(strinfo, "\x09/media"); if(p){ int depth; p++; char *pEnd = p + strlen(p) -1; while(0x0d==*pEnd || 0x0a==*pEnd ){ *pEnd = 0; pEnd --; } depth = PlextalkMediaPathDepth(p); DBGMSG("depth:%d\n", depth); if(bk_nano.src_depth < depth ){ bk_nano.src_depth = depth; } return; } p = strstr(strinfo, "\x09total\n"); if(p){ size = atol(strinfo); DBGMSG("size:%ld\n", size); bk_nano.pathtotal = size * 1024; bk_nano.ret_pathsize = 1; DBGMSG("size:%lld\n", bk_nano.pathtotal); bk_nano.path_report = 0; NeuxAppFDSourceUnregister(bk_nano.path_fd); return; } }else{ DBGMSG("read:end\n"); // bk_nano.path_report = 0; NeuxAppFDSourceUnregister(bk_nano.path_fd); bk_nano.dest_depth = PlextalkMediaPathDepth(bk_nano.dest); bk_nano.src_depth = bk_nano.src_depth - PlextalkMediaPathDepth(bk_nano.source); DBGMSG("depth:%d\n", bk_nano.dest_depth); DBGMSG("srcdepth:%d\n",bk_nano.src_depth); if((bk_nano.dest_depth + bk_nano.src_depth)>=8){ DBGMSG("depth over\n"); backup_tts(TTS_MAX_FILELEVEL, 0); backup_tts(TTS_FAILBACKUP, 0); bk_nano.err_exit = 1; return; } } }
static void OnBackupAppDestroy() { // plextalk_set_auto_off_disable(0); DBGMSG("OnBackupAppDestroy destroy!\n"); close(bk_nano.fd); }
int backup_copy_progress(struct CopyInfo *thiz) { // char *strinfo; ssize_t count; // size_t num; char *p, pread; float persent = 0.0; // num = MAX_PATH_BYTES; memset(thiz->strinfo, 0, MAX_PATH_BYTES); //pread = fgets(thiz->strinfo, MAX_PATH_BYTES , thiz->fp); count = read(thiz->fd, thiz->strinfo, MAX_PATH_BYTES); //DBGMSG("count = %d\n", count); //DBGMSG("thiz->strinfo = %s\n", thiz->strinfo); if(count > 0){ thiz->strinfo[count] = 0; DBGMSG("line:%s\n", thiz->strinfo); p = strrchr(thiz->strinfo, '%'); if(p){ struct statfs diskinfo; unsigned long long copysize, remainsize; statfs (bk_nano.dirpath, &diskinfo); remainsize = ((long long)diskinfo.f_bfree * (long long)diskinfo.f_bsize); copysize = bk_nano.freedir - remainsize; DBGMSG("copysize = %lld \n", copysize); persent = (float)(copysize) / (float)(bk_nano.pathtotal) * 100.0; thiz->prog_val = persent; DBGMSG("thiz->prog_val = %f \n", thiz->prog_val); } else{ p = strstr(thiz->strinfo, "total size is"); if(p) { persent = 100.0; thiz->prog_val = persent; } else{ DBGMSG("no per num \n"); } } }else if((count == -1) && (errno == EAGAIN)){ DBGMSG("no data yet!\n"); }else{ DBGMSG("read empty\n"); thiz->report = 0; NeuxAppFDSourceUnregister(thiz->fd); DBGMSG("GrUnregisterInput\n"); } if(persent >= 100.0){ thiz->report = 0; DBGMSG("100 persent\n"); NeuxAppFDSourceUnregister(thiz->fd); DBGMSG("GrUnregisterInput\n"); } return 0; }
KNSProxies * KNSManagerKNSProxiesMake ( struct KNSManager * mgr, const KConfig * kfg ) { rc_t rc = 0; int i = 0; int n = 2; typedef enum { eEnv, eKfg, } EType; EType type [ 2 ] = { eKfg, eEnv }; KNSProxies * self = calloc ( 1, sizeof * self ); if ( self == NULL ) return NULL; assert ( self ); BSTreeInit ( & self -> proxie_tree ); rc = KConfigReadBool ( kfg, "/http/proxy/enabled", & self -> http_proxy_enabled ); if ( rc != 0 ) { if ( GetRCState ( rc ) == rcNotFound ) rc = 0; else { KNSManagerSetHTTPProxyPath ( mgr, NULL ); assert ( self -> http_proxy_enabled == false ); } } else if ( ! self -> http_proxy_enabled ) return self; { bool proxy_only = false; rc_t rc = KConfigReadBool ( kfg, "/http/proxy/only", & proxy_only ); if ( rc == 0 && proxy_only ) self-> http_proxy_only = true; } { String * result = NULL; rc = KConfigReadString ( kfg, "/http/proxy/use", & result ); if ( rc == 0 ) { if ( StringCmp ( result, "env") ) { n = 1; type [ 0 ] = eEnv; } else if ( StringCmp ( result, "kfg") ) { n = 1; type [ 0 ] = eKfg; } else if ( StringCmp ( result, "none") ) { n = 0; } else if ( StringCmp ( result, "env,kfg") ) { n = 2; type [ 0 ] = eEnv; type [ 1 ] = eKfg; } else if ( StringCmp ( result, "kfg,env") ) { n = 2; type [ 0 ] = eKfg; type [ 1 ] = eEnv; } } RELEASE ( String, result ); } for ( i = 0; i < n; ++ i ) { switch ( type [ i ] ) { case eEnv: KNSProxiesHttpProxyInitFromEnv ( self ); break; case eKfg: KNSProxiesHttpProxyInitFromKfg ( self, kfg ); break; default: assert ( 0 ); break; } } BSTreeForEach ( & self -> proxie_tree, false, KNSProxiesBSTreeCount, & self -> http_proxies_cnt ); if ( self -> http_proxies_cnt > 0 ) { self -> http_proxies = calloc ( self -> http_proxies_cnt, sizeof * self -> http_proxies ); if ( self -> http_proxies == NULL ) return NULL; DBGMSG ( DBG_KNS, DBG_FLAG ( DBG_KNS_PROXY ), ( "Will use %zu proxy spec%s%s\n", self -> http_proxies_cnt, self -> http_proxies_cnt > 1 ? "s" : "", self -> http_proxy_only ? "" : " and direct connection") ); } self -> tmpS = 0; n = self -> http_proxies_cnt; srand ( time ( NULL ) ); while ( n > 0 ) { self -> rand = rand () % n; self -> tmpI = 0; if ( ! BSTreeDoUntil ( & self -> proxie_tree, false, KNSProxiesBSTreeSetRand, self ) ) { BSTreeForEach ( & self -> proxie_tree, false, KNSProxiesBSTreeInit, self ) ; n = 0; } else { const BSTItem * item = ( BSTItem * ) self -> tmpB; self -> http_proxies [ self -> tmpS ++ ] = item -> proxy; BSTreeUnlink ( & self -> proxie_tree, self -> tmpB ); BSTItemWhack ( self -> tmpB, NULL ); self -> tmpB = NULL; -- n; } } /* BSTreeForEach ( & self -> proxie_tree, false, KNSProxiesBSTreeInit, self );*/ for ( self -> tmpS = 1; self -> tmpS < self ->http_proxies_cnt; ++ self -> tmpS ) { self -> http_proxies [ self -> tmpS - 1 ] -> next = self -> http_proxies [ self -> tmpS ]; } return self; }
bool InitialiseAudio(unsigned int inId, unsigned int outId, unsigned int sr, unsigned int iovs, unsigned int chnls, unsigned int inChanL, unsigned int outChanL ) { TRACE; if (gDAC->isStreamOpen()) { if (gDAC->isStreamRunning()) { try { gDAC->abortStream(); } catch (RtAudioError& e) { e.printMessage(); } } gDAC->closeStream(); } RtAudio::StreamParameters iParams, oParams; iParams.deviceId = inId; iParams.nChannels = chnls; iParams.firstChannel = inChanL; oParams.deviceId = outId; oParams.nChannels = chnls; oParams.firstChannel = outChanL; gIOVS = iovs; // gIOVS may get changed by stream gSigVS = atoi(gState->mAudioSigVS); // This is done here so that it changes when the callback is stopped DBGMSG("\ntrying to start audio stream @ %i sr, %i iovs, %i sigvs\nindev = %i:%s\noutdev = %i:%s\n", sr, iovs, gSigVS, inId, GetAudioDeviceName(inId).c_str(), outId, GetAudioDeviceName(outId).c_str()); RtAudio::StreamOptions options; options.flags = RTAUDIO_NONINTERLEAVED; // options.streamName = BUNDLE_NAME; // JACK stream name, not used on other streams gBufIndex = 0; gVecElapsed = 0; gFadeMult = 0.; gPluginInstance->SetBlockSize(gSigVS); gPluginInstance->SetSampleRate(sr); gPluginInstance->Reset(); try { TRACE; gDAC->openStream( &oParams, &iParams, RTAUDIO_FLOAT64, sr, &gIOVS, &AudioCallback, NULL, &options); gDAC->startStream(); memcpy(gActiveState, gState, sizeof(AppState)); // copy state to active state } catch (RtAudioError& e ) { e.printMessage(); return false; } return true; }
/* HomeDirectory * returns a KDirectory where the binary for a given function is located * * "dir" [ OUT ] - return parameter for home directory ( read-only ), if found * * "func" [ IN ] - function pointer within binary to be located */ LIB_EXPORT rc_t CC KDyldHomeDirectory ( const KDyld *self, const KDirectory **dir, fptr_t func ) { rc_t rc; if ( dir == NULL ) rc = RC ( rcFS, rcDylib, rcSearching, rcParam, rcNull ); else { * dir = NULL; if ( self == NULL ) rc = RC ( rcFS, rcDylib, rcSearching, rcSelf, rcNull ); else if ( func == NULL ) rc = RC ( rcFS, rcDylib, rcSearching, rcFunction, rcNull ); else { Dl_info info; memset ( & info, 0, sizeof info ); if ( dladdr ( ( void* ) func, & info ) == 0 ) rc = RC ( rcFS, rcDylib, rcSearching, rcFunction, rcNotFound ); else { KDirectory *wd; rc = KDirectoryNativeDir ( & wd ); if ( rc == 0 ) { /* turn this into a real path */ const KSysDir *sdir = KDirectoryGetSysDir ( wd ); if ( sdir == NULL ) rc = RC ( rcFS, rcDylib, rcSearching, rcDirectory, rcIncorrect ); else { /* "dladdr" will return a simple name rather than a path when the address is within the application itself and the application was found using PATH. this is brilliant design at its best. */ char thanks_for_brilliant_APIs [ PATH_MAX ]; const char *dli_fname = info . dli_fname; /* check for a path rather than a name */ const char *last_slash = strrchr ( info . dli_fname, '/' ); if ( last_slash == NULL ) { /* simple name - get PATH */ const char *PATH = getenv ( "PATH" ); rc = RC ( rcFS, rcDylib, rcSearching, rcPath, rcNotFound ); if ( PATH != NULL ) { /* loop over PATH */ const char *path_start, *path_end; for ( path_start = PATH;; path_start = path_end + 1 ) { /* look for non-empty directory */ path_end = strchr ( path_start, ':' ); if ( path_start != path_end && path_start [ 0 ] != 0 ) { rc_t rc2; uint32_t path_type; /* handle last element in list */ if ( path_end == NULL ) last_slash = path_start + strlen ( path_start ); else for ( last_slash = path_end; last_slash > path_start; -- last_slash ) { if ( last_slash [ -1 ] != '/' ) break; } /* create possible path, using up to ':' */ rc2 = string_printf ( thanks_for_brilliant_APIs, sizeof thanks_for_brilliant_APIs, NULL, "%.*s/%s", ( int ) ( last_slash - path_start ), path_start, dli_fname ); /* if failed to create path string */ if ( rc2 != 0 ) break; /* check path against working directory */ path_type = KDirectoryPathType ( wd, "%s", thanks_for_brilliant_APIs ); if ( ( path_type & ~ kptAlias ) == kptFile ) { uint32_t access = 0; rc = KDirectoryAccess ( wd, & access, "%s", thanks_for_brilliant_APIs ); if ( rc != 0 ) break; /* try to do a quick check that the file can be executed. but it could fail to do the right guess. */ if ( access & 0100 || access & 0010 || access & 0001 ) { /* this is a file, which can be assumed to be an executable */ dli_fname = thanks_for_brilliant_APIs; last_slash = & thanks_for_brilliant_APIs [ last_slash - path_start ]; rc = 0; break; } } } /* exit if no more paths */ if ( path_end == NULL ) break; } } } if ( rc == 0 ) { char real [ PATH_MAX ]; rc = KSysDirRealPath ( sdir, real, sizeof real, "%.*s" , ( int ) ( last_slash - dli_fname ), dli_fname ); if ( rc == 0 ) rc = KDirectoryOpenDirRead ( wd, dir, false, "%s", real ); DBGMSG(DBG_KFS, DBG_FLAG(DBG_KFS_DIR), ("%s: %R path is '%s'\n", __func__, rc, real)); } } KDirectoryRelease ( wd ); } } } } return rc; }