void detect_window_below_cursor() { window_lst.clear(); CFArrayRef osx_window_list = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID); if(osx_window_list) { CFIndex osx_window_count = CFArrayGetCount(osx_window_list); for(CFIndex i = 0; i < osx_window_count; ++i) { CFDictionaryRef elem = (CFDictionaryRef)CFArrayGetValueAtIndex(osx_window_list, i); window_lst.push_back(app_info()); CFDictionaryApplyFunction(elem, print_keys, NULL); } CGEventRef event = CGEventCreate(NULL); CGPoint cursor = CGEventGetLocation(event); CFRelease(event); std::cout << "Mouse Pos: " << cursor.x << ", " << cursor.y << std::endl; for(int i = 0; i < window_lst.size(); ++i) { if(window_lst[i].layer == 0) { if(cursor.x >= window_lst[i].x && cursor.x <= window_lst[i].x + window_lst[i].width && cursor.y >= window_lst[i].y && cursor.y <= window_lst[i].y + window_lst[i].height) { window_lst_focus_index = i; pid = window_lst[i].pid; GetProcessForPID(pid, &psn); SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); break; } std::cout << "Owner: " << window_lst[i].owner << std::endl; std::cout << "Name: " << window_lst[i].name << std::endl; std::cout << "PID: " << window_lst[i].pid << std::endl; std::cout << "Layer: " << window_lst[i].layer << std::endl; std::cout << "X: " << window_lst[i].x << std::endl; std::cout << "Y: " << window_lst[i].y << std::endl; std::cout << "Width: " << window_lst[i].width << std::endl; std::cout << "Height: " << window_lst[i].height << std::endl; } } std::cout << "Keyboard focus: " << pid << std::endl; } }
bool parse(const std::string& json_string, cocaine_node_info_t& node_info) { Json::Value root; Json::Reader reader; if (!reader.parse(json_string, root)) { return false; } // parse apps const Json::Value apps = root["apps"]; if (!apps.isObject() || !apps.size()) { return false; } Json::Value::Members app_names(apps.getMemberNames()); for (Json::Value::Members::iterator it = app_names.begin(); it != app_names.end(); ++it) { std::string parsed_app_name(*it); Json::Value json_app_data(apps[parsed_app_name]); cocaine_node_app_info_t app_info(parsed_app_name); if (!parse_app_info(json_app_data, app_info)) { continue; } else { node_info.apps[parsed_app_name] = app_info; } } // parse remaining properties const Json::Value jobs_props = root["jobs"]; if (jobs_props.isObject()) { node_info.pending_jobs = jobs_props.get("pending", 0).asInt(); node_info.processed_jobs = jobs_props.get("processed", 0).asInt(); } node_info.route = root.get("route", "").asString(); node_info.uptime = root.get("uptime", 0.0f).asDouble(); node_info.ip_address = m_node_ip_address; node_info.port = m_node_port; return true; }
void readself(){ printf("\nReading...\n"); u32 offset=0; u32 magic = be32(self); /* 53434500 = SCE\0 */ offset += sizeof(u32); u32 version = le32(self+offset); /* header version 3*/ offset += sizeof(u32); u16 sdk_type = le16(self+offset); /* SDK type */ offset += sizeof(u16); u16 header_type = le16(self+offset); /* 1 self, 2 unknown, 3 pkg */ offset += sizeof(u16); u32 metadata_offset = le32(self+offset); /* metadata offset */ offset += sizeof(u32); u64 header_len = le64(self+offset); /* self header length */ offset += sizeof(u64); u64 elf_filesize = le64(self+offset); /* ELF file length */ offset += sizeof(u64); u64 self_filesize = le64(self+offset); /* SELF file length */ offset += sizeof(u64); u64 unknown1 = le64(self+offset); /* UNKNOWN */ offset += sizeof(u64); u64 self_offset = le64(self+offset); /* Self Offset */ offset += sizeof(u64); u64 appinfo_offset = le64(self+offset); /* app info offset */ offset += sizeof(u64); u64 elf_offset = le64(self+offset); /* ELF #1 offset */ offset += sizeof(u64); u64 phdr_offset = le64(self+offset); /* program header offset */ offset += sizeof(u64); u64 shdr_offset = le64(self+offset); /* section header offset */ offset += sizeof(u64); u64 section_info_offset = le64(self+offset); /* section info offset */ offset += sizeof(u64); u64 sceversion_offset = le64(self+offset); /* version offset */ offset += sizeof(u64); u64 controlinfo_offset = le64(self+offset); /* control info offset */ offset += sizeof(u64); u64 controlinfo_size = le64(self+offset); /* control info size */ offset += sizeof(u64); if(magic!=HDR) fail("\nERROR! Not a PlayStation Vita Self File (Magic: %08x)",magic); if(header_type!=1){ char* HType; if(header_type==2) HType = "rvk"; else if(header_type==3) HType = "pkg"; else if(header_type==4) HType = "spp"; else HType = "Unknown"; fail("\nERROR! Not a PlayStation Vita Self File (Type : %08x)\n" " [%s]",header_type,HType); } printf("Magic 0x%08x\n",magic); printf("Version 0x%08x\n",version); printf("SDK Type 0x%08x\n",sdk_type); printf("Header Type 0x%08x\n",header_type); printf("Metadata offset 0x%08x\n",metadata_offset); printf("Header Length 0x%016lx (%lu Bytes)\n",header_len,header_len); printf("Elf Size 0x%016lx (%lu Bytes)\n",elf_filesize,elf_filesize); printf("Self Size 0x%016lx (%lu Bytes)\n",self_filesize,self_filesize); printf("Unknown_1 0x%016lx\n",unknown1); printf("Self Offset 0x%016lx\n",self_offset); printf("Application Info Offset 0x%016lx\n",appinfo_offset); printf("Elf Offset 0x%016lx\n",elf_offset); printf("Program hdr Offset 0x%016lx\n",phdr_offset); printf("Section hdr Offset 0x%016lx\n",shdr_offset); printf("Section Info Offset 0x%016lx\n",section_info_offset); printf("Version Offset 0x%016lx\n",sceversion_offset); printf("Control Info Offset 0x%016lx\n",controlinfo_offset); printf("Control Info Size 0x%016lx (%lu Bytes)\n",controlinfo_size,controlinfo_size); app_info(appinfo_offset); elf(elf_offset); program_hdr(phdr_offset); section_hdr(shdr_offset); sce_version(sceversion_offset); control_information(controlinfo_offset); printf("\nDone\n"); }
int main(int argc, char *argv[]) { OPENST_ERR errcode; char *FILE_IN, *FILE_OUT, *V_DATASET_NAME; double *U, *V, vmin, vmean,vmax, HI, HJ, HK; int max_iter; int it, converged; double t1,t2; size_t NI, NJ, NK; double SRCI, SRCJ, SRCK; size_t BSIZE_I; size_t BSIZE_J; size_t BSIZE_K; char *LSM_UNLOCKED; int OMP_MAX_THREADS; double EPS, EPS_MULT, EIK3D_Time; const char *IMP_NAME; size_t SRCidx_i, i, j, k; size_t *SRCidx, SRCidx_NI, SRCidx_NJ; if(argc < 6) { fprintf(stderr,"Error: invalid command line parameters\n"); app_info(argv[0],1); errcode = OPENST_ERR_PARAM_INVALID; goto EXIT; } app_info(argv[0],0); FILE_IN = argv[1]; FILE_OUT = argv[2]; SRCI = atof(argv[3]); SRCJ = atof(argv[4]); SRCK = atof(argv[5]); printf("SRCI = %e; SRCJ = %e; SRCK = %e\n",SRCI,SRCJ,SRCK); if(argc > 6) { V_DATASET_NAME = argv[6]; } else { V_DATASET_NAME = DEFAULT_V_DATASET_NAME; } if(argc > 7) { EPS_MULT = atof(argv[7]); } else { EPS_MULT = DEFAULT_EPS_MULT; } if(argc > 8) { max_iter = atoi(argv[8]); } else { max_iter = DEFAULT_MAX_ITER; } hdf5_read_model(FILE_IN,V_DATASET_NAME,&V,&HI,&HJ,&HK,&NI,&NJ,&NK); #ifdef _MSC_VER printf("NI = %Iu; NJ = %Iu; NK = %Iu\n",NI,NJ,NK); #else printf("NI = %zu; NJ = %zu; NK = %zu\n",NI,NJ,NK); #endif printf("HI = %e; HJ = %e; HK = %e\n",HI,HJ,HK); printf("V[0,0,0]: %e\n",V[OPENST_MEMADR_3D(0,0,0,NI,NJ,NK)]); printf("V[0,0,1]: %e\n",V[OPENST_MEMADR_3D(0,0,1,NI,NJ,NK)]); printf("V[0,1,0]: %e\n",V[OPENST_MEMADR_3D(0,1,0,NI,NJ,NK)]); printf("V[1,0,0]: %e\n",V[OPENST_MEMADR_3D(1,0,0,NI,NJ,NK)]); if(OpenST_CRS_IsPointNotWithinBounds(SRCI,SRCJ,SRCK,NI,NJ,NK,HI,HJ,HK)) { fprintf(stderr,"Error: SRC is not within domain bounds\n"); errcode = OPENST_ERR_PARAM_INVALID; goto EXIT; } if(argc > 9) { BSIZE_I = (size_t) atoi(argv[9]); BSIZE_J = (size_t) atoi(argv[10]); BSIZE_K = (size_t) atoi(argv[11]); } else { OpenST_FSM3D_SuggestBlockSize(NI,NJ,NK,&BSIZE_I,&BSIZE_J,&BSIZE_K); } U = (double *)malloc(NI * NJ * NK * sizeof(double)); assert(U); LSM_UNLOCKED = (char *)malloc(NI * NJ * NK * sizeof(char)); assert(LSM_UNLOCKED); OMP_MAX_THREADS = omp_get_max_threads(); if(EPS_MULT != 0.0) { OpenST_AOP_GetArrStats(V, NI * NJ * NK, &vmin, &vmax, &vmean); printf("Vmin = %e; Vmean = %e; Vmax = %e\n",vmin,vmean,vmax); EPS = EPS_MULT * OpenST_BRT3D_SuggestTSTEP(vmax, HI, HJ, HK); } else { EPS = 0.0; } t1 = omp_get_wtime(); #ifndef TEST_FSM IMP_NAME = OPENST_LSM3D_COMPUTEPARTIAL_IMP_NAME; errcode = OpenST_LSM3D_Init_2(U,LSM_UNLOCKED,V, NI,NJ,NK, HI,HJ,HK, SRCI,SRCJ,SRCK, &SRCidx,&SRCidx_NI,&SRCidx_NJ, OPENST_FSM3D_INIT_DEFAULT); #else IMP_NAME = OPENST_FSM3D_IMP_NAME; errcode = OpenST_FSM3D_Init_2(U,V, NI,NJ,NK, HI,HJ,HK, SRCI,SRCJ,SRCK, &SRCidx,&SRCidx_NI,&SRCidx_NJ, OPENST_FSM3D_INIT_DEFAULT); #endif t2 = omp_get_wtime(); if(errcode != OPENST_ERR_SUCCESS) { fprintf(stderr,"Error: Initialization errcode = %i\n",errcode); goto EXIT; } printf("Initialization time: %e sec\n", t2 - t1); printf("U initialized in:\n"); for(SRCidx_i = 0; SRCidx_i < SRCidx_NI; ++SRCidx_i) { i = SRCidx[OPENST_MEMADR_2D(SRCidx_i,0,SRCidx_NI,SRCidx_NJ)]; j = SRCidx[OPENST_MEMADR_2D(SRCidx_i,1,SRCidx_NI,SRCidx_NJ)]; k = SRCidx[OPENST_MEMADR_2D(SRCidx_i,2,SRCidx_NI,SRCidx_NJ)]; #ifdef _MSC_VER printf("U[%Iu,%Iu,%Iu] = %e\n",i,j,k,U[OPENST_MEMADR_3D(i,j,k,NI,NJ,NK)]); #else printf("U[%zu,%zu,%zu] = %e\n",i,j,k,U[OPENST_MEMADR_3D(i,j,k,NI,NJ,NK)]); #endif } t1 = omp_get_wtime(); #ifndef TEST_FSM it = OpenST_LSM3D_Compute(U,LSM_UNLOCKED,V, NI,NJ,NK, HI,HJ,HK, max_iter,&converged, BSIZE_I,BSIZE_J,BSIZE_K,EPS); #else it = OpenST_FSM3D_Compute(U,V, NI,NJ,NK, HI,HJ,HK, max_iter,&converged, BSIZE_I,BSIZE_J,BSIZE_K,EPS); #endif t2 = omp_get_wtime(); EIK3D_Time = t2 - t1; hdf5_write_time(FILE_OUT,"T",U,&HI,&HJ,&HK,NI,NJ,NK); printf("\n====================================================\n"); printf("TEST_ID,METHOD_ID,OMP_MAX_THREADS,BSIZE_I,BSIZE_J,BSIZE_K," \ "EPS,max_iter,it,converged,sec," \ "NI,NJ,NK,SRCI,SRCJ,SRCK,OPENST_BUILDINFO_LINK_TYPE\n"); #ifdef _MSC_VER printf("%s,%s,%i,%Iu,%Iu,%Iu,%e,%i,%i,%i,%e," \ "%Iu,%Iu,%Iu,%e,%e,%e,%s\n", #else printf("%s,%s,%i,%zu,%zu,%zu,%e,%i,%i,%i,%e," \ "%zu,%zu,%zu,%e,%e,%e,%s\n", #endif FILE_IN,IMP_NAME,OMP_MAX_THREADS,BSIZE_I,BSIZE_J,BSIZE_K, EPS,max_iter,it,converged,EIK3D_Time, NI,NJ,NK,SRCI,SRCJ,SRCK,OPENST_BUILDINFO_LINK_TYPE_STATIC ); EXIT: return errcode; }