native_handle_t *JNativeHandle::MakeCppNativeHandle( JNIEnv *env, jobject jHandle, EphemeralStorage *storage) { if (jHandle == nullptr) { return nullptr; } if (!env->IsInstanceOf(jHandle, gNativeHandleFields.clazz)) { jniThrowException(env, "java/lang/ClassCastException", "jHandle must be an instance of NativeHandle."); return nullptr; } ScopedLocalRef<jintArray> fds(env, (jintArray) env->CallObjectMethod( jHandle, gNativeHandleFields.getFdsID)); ScopedLocalRef<jintArray> ints(env, (jintArray) env->CallObjectMethod( jHandle, gNativeHandleFields.getIntsID)); const int numFds = (int) env->GetArrayLength(fds.get()); const int numInts = (int) env->GetArrayLength(ints.get()); native_handle_t *handle = (storage == nullptr) ? native_handle_create(numFds, numInts) : storage->allocTemporaryNativeHandle(numFds, numInts); if (handle != nullptr) { env->GetIntArrayRegion(fds.get(), 0, numFds, &(handle->data[0])); env->GetIntArrayRegion(ints.get(), 0, numInts, &(handle->data[numFds])); } else { jniThrowException(env, "java/lang/OutOfMemoryError", "Failed to allocate memory for native_handle_t."); } return handle; }
void fileio_set_fds_bios(void) { Nes::Api::Fds fds( emulator ); char dirname[1024], *home; if (fdsBiosFile) { return; } home = getenv("HOME"); snprintf(dirname, sizeof(dirname), "%s/.nestopia/disksys.rom", home); fdsBiosFile = new std::ifstream(dirname, std::ifstream::in|std::ifstream::binary); if (fdsBiosFile->is_open()) { fds.SetBIOS(fdsBiosFile); } else { snprintf(msgbuf, sizeof(msgbuf), "~/.nestopia/disksys.rom not found, Disk System games will not work."); print_message(msgbuf); delete fdsBiosFile; fdsBiosFile = NULL; } }
void auxio_set_fds_bios(void) { Nes::Api::Fds fds( emulator ); char dirname[1024], *home; if (fdsBiosFile) { return; } home = getenv("HOME"); sprintf(dirname, "%s/.nestopia/disksys.rom", home); fdsBiosFile = new std::ifstream(dirname, std::ifstream::in|std::ifstream::binary); if (fdsBiosFile->is_open()) { fds.SetBIOS(fdsBiosFile); } else { std::cout << "Couldn't find ~/.nestopia/disksys.rom\nDisk System games will not work\n"; delete fdsBiosFile; fdsBiosFile = NULL; } }
jobject JNativeHandle::MakeJavaNativeHandleObj( JNIEnv *env, const native_handle_t *handle) { if (handle == nullptr) { return nullptr; } const int numFds = handle->numFds; ScopedLocalRef<jintArray> fds(env, env->NewIntArray(numFds)); env->SetIntArrayRegion(fds.get(), 0, numFds, &(handle->data[0])); const int numInts = handle->numInts; ScopedLocalRef<jintArray> ints(env, env->NewIntArray(numInts)); env->SetIntArrayRegion(ints.get(), 0, numInts, &(handle->data[numFds])); return env->NewObject(gNativeHandleFields.clazz, gNativeHandleFields.constructID, fds.get(), ints.get(), false /*own*/); }
void genOpenDescriptors(int pid, descriptor_type type, QueryData& results) { int bufsize = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, 0, 0); if (bufsize == -1) { VLOG(1) << "Could not list descriptors for pid: " << pid; return; } // Allocate structs for each descriptor. std::vector<proc_fdinfo> fds(bufsize / PROC_PIDLISTFD_SIZE); proc_pidinfo(pid, PROC_PIDLISTFDS, 0, fds.data(), bufsize); for (auto fd_info : fds) { if (type == DESCRIPTORS_TYPE_VNODE && fd_info.proc_fdtype == PROX_FDTYPE_VNODE) { genFileDescriptor(pid, fd_info.proc_fd, results); } else if (type == DESCRIPTORS_TYPE_SOCKET && fd_info.proc_fdtype == PROX_FDTYPE_SOCKET) { genSocketDescriptor(pid, fd_info.proc_fd, results); } } }
void fileio_set_fds_bios(void) { Nes::Api::Fds fds(emulator); char biospath[512]; if (fdsBiosFile) { return; } snprintf(biospath, sizeof(biospath), "%sdisksys.rom", nstdir); fdsBiosFile = new std::ifstream(biospath, std::ifstream::in|std::ifstream::binary); if (fdsBiosFile->is_open()) { fds.SetBIOS(fdsBiosFile); } else { fprintf(stderr, "%s not found, Disk System games will not work.\n", biospath); delete fdsBiosFile; fdsBiosFile = NULL; } }
//_____________________________________________________________________________ Int_t ProofAux::GenerateTree(const char *fnt, Long64_t ent, TString &fn) { // Generate the main tree for the 'friends' tutorial; the tree is called // 'Tmain', has 'ent' entries and is saved to file 'fnt'. // The full file path is returned in 'fn'. // Return 0 on success, -1 on error. Int_t rc = -1; // Check the filename fn = fnt; if (fn.IsNull()) { Error("GenerateTree", "file name undefined!"); return rc; } TUrl uu(fn, kTRUE); if (!strcmp(uu.GetProtocol(), "file") && !fn.BeginsWith("/")) { // Local file with relative path: create under the data directory if (!gProofServ || !(gProofServ->GetDataDir()) || strlen(gProofServ->GetDataDir()) <= 0) { Error("GenerateTree", "data directory undefined!"); return rc; } // Insert data directory fn.Insert(0, TString::Format("%s/", gProofServ->GetDataDir())); // Make sure the directory exists TString dir = gSystem->DirName(fn); if (gSystem->AccessPathName(dir, kWritePermission)) { if (gSystem->mkdir(dir, kTRUE) != 0) { Error("GenerateTree", "problems creating directory %s to store the file", dir.Data()); return rc; } } } // Create the file TDirectory* savedir = gDirectory; TFile *f = new TFile(fn, "RECREATE"); if (!f || f->IsZombie()) { Error("GenerateTree", "problems opening file %s", fn.Data()); return rc; } savedir->cd(); rc = 0; // Create the tree TTree *T = new TTree("Tmain","Main tree for tutorial friends"); T->SetDirectory(f); Int_t Run = 1; T->Branch("Run",&Run,"Run/I"); Long64_t Event = 0; T->Branch("Event",&Event,"Event/L"); Float_t x = 0., y = 0., z = 0.; T->Branch("x",&x,"x/F"); T->Branch("y",&y,"y/F"); T->Branch("z",&z,"z/F"); TRandom r; for (Long64_t i = 0; i < ent; i++) { if (i > 0 && i%1000 == 0) Run++; Event = i; x = r.Gaus(10,1); y = r.Gaus(20,2); z = r.Landau(2,1); T->Fill(); } T->Print(); f->cd(); T->Write(); T->SetDirectory(0); f->Close(); delete f; delete T; // Notify success Info("GenerateTree", "file '%s' successfully created", fn.Data()); // Add to the list TString fds(fn); if (!strcmp(uu.GetProtocol(), "file")) { if (gSystem->Getenv("LOCALDATASERVER")) { if (strcmp(TUrl(gSystem->Getenv("LOCALDATASERVER"), kTRUE).GetProtocol(), "file")) fds.Insert(0, TString::Format("%s/", gSystem->Getenv("LOCALDATASERVER"))); } else { fds.Insert(0, TString::Format("root://%s/", gSystem->HostName())); } } fMainList->Add(new TObjString(fds)); // Done return rc; }