void mtx_common_init(std::string const &program_name) { init_common_output(true); s_program_name = program_name; #if defined(SYS_WINDOWS) fix_windows_errormode(); #endif matroska_init(); atexit(mtx_common_cleanup); srand(time(nullptr)); init_debugging(); init_hacks(); init_locales(); mm_file_io_c::setup(); g_cc_local_utf8 = charset_converter_c::init(""); init_common_output(false); stereo_mode_c::init(); }
static status_t packagefs_std_ops(int32 op, ...) { switch (op) { case B_MODULE_INIT: { init_debugging(); PRINT("package_std_ops(): B_MODULE_INIT\n"); status_t error = StringPool::Init(); if (error != B_OK) { ERROR("Failed to init StringPool\n"); exit_debugging(); return error; } if (!StringConstants::Init()) { ERROR("Failed to init string constants\n"); StringPool::Cleanup(); exit_debugging(); return error; } error = GlobalFactory::CreateDefault(); if (error != B_OK) { ERROR("Failed to init GlobalFactory\n"); StringConstants::Cleanup(); StringPool::Cleanup(); exit_debugging(); return error; } error = PackageFSRoot::GlobalInit(); if (error != B_OK) { ERROR("Failed to init PackageFSRoot\n"); GlobalFactory::DeleteDefault(); StringConstants::Cleanup(); StringPool::Cleanup(); exit_debugging(); return error; } return B_OK; } case B_MODULE_UNINIT: { PRINT("package_std_ops(): B_MODULE_UNINIT\n"); PackageFSRoot::GlobalUninit(); GlobalFactory::DeleteDefault(); StringConstants::Cleanup(); StringPool::Cleanup(); exit_debugging(); return B_OK; } default: return B_ERROR; } }
static status_t checksumfs_std_ops(int32 operation, ...) { switch (operation) { case B_MODULE_INIT: init_debugging(); PRINT("checksumfs_std_ops(): B_MODULE_INIT\n"); return B_OK; case B_MODULE_UNINIT: PRINT("checksumfs_std_ops(): B_MODULE_UNINIT\n"); exit_debugging(); return B_OK; default: return B_BAD_VALUE; } }
static void init(void) { int i; char *s; char *error; struct rlimit rlim; getrlimit(RLIMIT_NOFILE, &rlim); max_fds=(int) rlim.rlim_max; fds=(struct fadv_info *) malloc(max_fds * sizeof(struct fadv_info)); assert(fds != NULL); _original_open = (int (*)(const char *, int, mode_t)) dlsym(RTLD_NEXT, "open"); _original_open64 = (int (*)(const char *, int, mode_t)) dlsym(RTLD_NEXT, "open64"); _original_creat = (int (*)(const char *, int, mode_t)) dlsym(RTLD_NEXT, "creat"); _original_creat64 = (int (*)(const char *, int, mode_t)) dlsym(RTLD_NEXT, "creat64"); _original_openat = (int (*)(int, const char *, int, mode_t)) dlsym(RTLD_NEXT, "openat"); _original_openat64 = (int (*)(int, const char *, int, mode_t)) dlsym(RTLD_NEXT, "openat64"); _original_dup = (int (*)(int)) dlsym(RTLD_NEXT, "dup"); _original_dup2 = (int (*)(int, int)) dlsym(RTLD_NEXT, "dup2"); _original_close = (int (*)(int)) dlsym(RTLD_NEXT, "close"); _original_fopen = (FILE *(*)(const char *, const char *)) dlsym(RTLD_NEXT, "fopen"); _original_fopen64 = (FILE *(*)(const char *, const char *)) dlsym(RTLD_NEXT, "fopen64"); _original_fclose = (int (*)(FILE *)) dlsym(RTLD_NEXT, "fclose"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(EXIT_FAILURE); } if((s = getenv(env_nr_fadvise)) != NULL) nr_fadvise = atoi(s); if(nr_fadvise <= 0) nr_fadvise = 1; PAGESIZE = getpagesize(); for(i = 0; i < max_fds; i++) fds[i].fd = -1; init_mutex(); init_debugging(); handle_stdout(); }
// netfs_mount static int netfs_mount(nspace_id nsid, const char *device, ulong flags, void *parameters, size_t len, void **data, vnode_id *rootID) { status_t error = B_OK; init_debugging(); #ifdef DEBUG_OBJECT_TRACKING ObjectTracker::InitDefault(); #endif // create and init the volume manager VolumeManager* volumeManager = new(std::nothrow) VolumeManager(nsid, flags); Volume* rootVolume = NULL; if (volumeManager) { error = volumeManager->MountRootVolume(device, (const char*)parameters, len, &rootVolume); if (error != B_OK) { delete volumeManager; volumeManager = NULL; } } else error = B_NO_MEMORY; VolumePutter _(rootVolume); // set results if (error == B_OK) { *data = volumeManager; *rootID = rootVolume->GetRootID(); } else { #ifdef DEBUG_OBJECT_TRACKING ObjectTracker::ExitDefault(); #endif exit_debugging(); } return error; }
int setup() { init_debugging(); int result, numSensors, i; const char *err; //handles *Handles; //Declare an InterfaceKit handle // Setup the IFKit CPhidgetInterfaceKit_create(&ifKit); CPhidget_set_OnAttach_Handler((CPhidgetHandle)ifKit, AttachHandler, NULL); CPhidget_set_OnDetach_Handler((CPhidgetHandle)ifKit, DetachHandler, NULL); CPhidget_set_OnError_Handler((CPhidgetHandle)ifKit, ErrorHandler, NULL); CPhidgetInterfaceKit_set_OnInputChange_Handler (ifKit, IKInputChangeHandler, NULL); CPhidgetInterfaceKit_set_OnSensorChange_Handler (ifKit, IKSensorChangeHandler, NULL); CPhidgetInterfaceKit_set_OnOutputChange_Handler (ifKit, IKOutputChangeHandler, NULL); CPhidget_open((CPhidgetHandle)ifKit, -1); //get the program to wait for an interface kit device to be attached SetupLog("Waiting for interface kit to be attached...."); if((result = CPhidget_waitForAttachment((CPhidgetHandle)ifKit, 10000))) { CPhidget_getErrorDescription(result, &err); printf("Problem waiting for attachment: %s\n", err); return 0; } //Display the properties of the attached interface kit device IKDisplayProperties(ifKit); // Setup motoControl CPhidgetMotorControl_create(&motoControl); CPhidget_set_OnAttach_Handler((CPhidgetHandle)motoControl, AttachHandler, NULL); CPhidget_set_OnDetach_Handler((CPhidgetHandle)motoControl, DetachHandler, NULL); CPhidget_set_OnError_Handler((CPhidgetHandle)motoControl, ErrorHandler, NULL); CPhidgetMotorControl_set_OnInputChange_Handler (motoControl, MCInputChangeHandler, NULL); CPhidgetMotorControl_set_OnVelocityChange_Handler (motoControl, MCVelocityChangeHandler, NULL); CPhidgetMotorControl_set_OnCurrentChange_Handler (motoControl, MCCurrentChangeHandler, NULL); CPhidget_open((CPhidgetHandle)motoControl, -1); SetupLog("Waiting for MotorControl to be attached...."); if((result = CPhidget_waitForAttachment((CPhidgetHandle)motoControl, 10000))) { CPhidget_getErrorDescription(result, &err); printf("Problem waiting for attachment: %s\n", err); return 0; } MCDisplayProperties(motoControl); CPhidgetMotorControl_setAcceleration (motoControl, 0, 50.00); CPhidgetMotorControl_setAcceleration (motoControl, 1, 50.00); // Setup AdvancedServo CPhidgetAdvancedServo_create(&servo); CPhidget_set_OnAttach_Handler((CPhidgetHandle)servo, AttachHandler, NULL); CPhidget_set_OnDetach_Handler((CPhidgetHandle)servo, DetachHandler, NULL); CPhidget_set_OnError_Handler((CPhidgetHandle)servo, ErrorHandler, NULL); CPhidgetAdvancedServo_set_OnPositionChange_Handler(servo, ASPositionChangeHandler, NULL); CPhidget_open((CPhidgetHandle)servo, -1); SetupLog("Waiting for Phidget to be attached...."); if((result = CPhidget_waitForAttachment((CPhidgetHandle)servo, 10000))) { CPhidget_getErrorDescription(result, &err); printf("Problem waiting for attachment: %s\n", err); return 0; } //Display the properties of the attached device ASDisplayProperties(servo); CPhidgetAdvancedServo_setEngaged(servo, 0, 1); state.ServoPosition = 0; sensor.RightWhisker = 0; sensor.LeftWhisker = 0; sensor.FrontFacingIR = 0; sensor.TopIR = 0; state.AverageBaseLight = (float)10000; sensor.TopLeftLight = 0; sensor.TopRightLight = 0; state.flashWasOn = 0; state.wasOnBlackInLastIteration = 0; sensor.SpinSensor = 10.0; state.expectedMovement = None; state.expectedFor = 0; state.exitTrialCounter = 0; state.stuckCounter = 0; state.previousState = 2; gettimeofday(&state.lastFlashSighted, NULL); //#ifdef FREQUENCY //state.frequency = FREQUENCY; //#endif #ifndef NO_POWERLIB power_button_reset(); while(power_button_get_value()==0) { sleep(1); } #endif return 0; }
// main int main(int argc, char** argv) { kArgC = argc; kArgV = argv; // init debugging init_debugging(); struct DebuggingExiter { DebuggingExiter() {} ~DebuggingExiter() { exit_debugging(); } } _; // parse arguments int argi = 1; for (; argi < argc; argi++) { const char* arg = argv[argi]; int32 argLen = strlen(arg); if (argLen == 0) { print_usage(); return 1; } if (arg[0] != '-') break; if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) { print_usage(false); return 0; } else if (strcmp(arg, "--debug") == 0) { gServerSettings.SetEnterDebugger(true); } } // get file system, if any bool dispatcher = true; const char* fileSystem = NULL; if (argi < argc) { fileSystem = argv[argi++]; dispatcher = false; } // get the port, if any int32 port = -1; if (argi < argc) { port = atol(argv[argi++]); if (port <= 0) { print_usage(); return 1; } } if (argi < argc) { print_usage(); return 1; } // create and init the application status_t error = B_OK; UserlandFSServer* server = new(std::nothrow) UserlandFSServer(kServerSignature); if (!server) { fprintf(stderr, "Failed to create server.\n"); return 1; } error = server->Init(fileSystem, port); // run it, if everything went fine if (error == B_OK) server->Run(); delete server; return 0; }