static void gst_ducati_viddec_finalize (GObject * obj) { GstDucatiVidDec *self = GST_DUCATIVIDDEC (obj); codec_delete (self); engine_close (self); if (self->codec_data) { gst_buffer_unref (self->codec_data); self->codec_data = NULL; } G_OBJECT_CLASS (parent_class)->finalize (obj); }
static int ioctl_engine_close(struct drm_device *dev, void *data, struct drm_file *file) { struct dce_file_priv *priv = omap_drm_file_priv(file, dce_mapper_id); struct drm_omap_dce_engine_close *arg = data; uint32_t engine; int ret; ret = engine_get(priv, arg->eng_handle, &engine); if (ret) return ret; engine_unregister(priv, arg->eng_handle); return engine_close(priv, engine); }
static int dce_release(struct drm_device *dev, struct drm_file *file) { struct dce_file_priv *priv = omap_drm_file_priv(file, dce_mapper_id); int i; // XXX not sure if this is legit.. maybe we end up with this scenario // when drm device file is opened prior to dce module being loaded?? WARN_ON(!priv); if (!priv) return 0; /* cleanup any remaining codecs and engines on behalf of the process, * in case the process crashed or didn't clean up properly for itself: */ for (i = 0; i < ARRAY_SIZE(priv->codecs); i++) { uint32_t codec = priv->codecs[i].codec; if (codec) { enum omap_dce_codec codec_id = priv->codecs[i].codec_id; codec_unregister(priv, i+1); codec_delete(priv, codec, codec_id); } } for (i = 0; i < ARRAY_SIZE(priv->engines); i++) { uint32_t engine = priv->engines[i].engine; if (engine) { engine_unregister(priv, i+1); engine_close(priv, engine); } } for (i = 0; i < ARRAY_SIZE(txns); i++) { if (txns[i].priv == priv) { txn_cleanup(&txns[i]); memset(&txns[i], 0, sizeof(txns[i])); } } kfree(priv); return 0; }
void uci_close(uci_t * uci) { int i; option_t * opt; ASSERT(uci_is_ok(uci)); engine_close(uci->engine); uci->engine = NULL; my_string_clear(&uci->name); my_string_clear(&uci->author); for (i = 0; i < uci->option_nb; i++) { opt = &uci->option[i]; my_string_clear(&opt->name); my_string_clear(&opt->default_); } uci->option_nb = 0; }
static GstStateChangeReturn gst_ducati_viddec_change_state (GstElement * element, GstStateChange transition) { GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; GstDucatiVidDec *self = GST_DUCATIVIDDEC (element); GST_INFO_OBJECT (self, "begin: changing state %s -> %s", gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)), gst_element_state_get_name (GST_STATE_TRANSITION_NEXT (transition))); switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: if (!engine_open (self)) { GST_ERROR_OBJECT (self, "could not open"); return GST_STATE_CHANGE_FAILURE; } break; default: break; } ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); if (ret == GST_STATE_CHANGE_FAILURE) goto leave; switch (transition) { case GST_STATE_CHANGE_READY_TO_NULL: codec_delete (self); engine_close (self); break; default: break; } leave: GST_LOG_OBJECT (self, "end"); return ret; }
static int ioctl_engine_open(struct drm_device *dev, void *data, struct drm_file *file) { struct dce_file_priv *priv = omap_drm_file_priv(file, dce_mapper_id); struct drm_omap_dce_engine_open *arg = data; struct dce_rpc_engine_open_rsp *rsp; int ret; /* if we are not re-starting a syscall, send req */ if (!arg->token) { struct dce_rpc_engine_open_req req = { .hdr = MKHDR(ENGINE_OPEN), }; strncpy(req.name, arg->name, sizeof(req.name)); ret = rpsend(priv, &arg->token, hdr(&req), sizeof(req)); if (ret) return ret; } /* then wait for reply, which is interruptible */ ret = rpwait(priv, arg->token, hdr(&rsp), sizeof(*rsp)); if (ret) return ret; arg->eng_handle = engine_register(priv, rsp->engine); arg->error_code = rsp->error_code; if (!engine_valid(priv, arg->eng_handle)) { engine_close(priv, rsp->engine); ret = -ENOMEM; } kfree(rsp); return ret; }
int main(int argc, char *argv[]) { // Get path char *ip = NULL; unsigned short connect_port = 0; unsigned short listen_port = 0; int net_mode = NET_MODE_NONE; int ret = 0; // Path manager if(pm_init() != 0) { err_msgbox(pm_get_errormsg()); return 1; } // Check arguments if(argc >= 2) { if(strcmp(argv[1], "-v") == 0) { printf("OpenOMF v%d.%d.%d\n", V_MAJOR, V_MINOR, V_PATCH); printf("Source available at https://github.com/omf2097/ under MIT License\n"); printf("(C) 2097 Tuomas Virtanen, Andrew Thompson, Hunter and others\n"); goto exit_0; } else if(strcmp(argv[1], "-h") == 0) { printf("Arguments:\n"); printf("-h Prints this help\n"); printf("-c [ip] [port] Connect to server\n"); printf("-l [port] Start server\n"); goto exit_0; } else if(strcmp(argv[1], "-c") == 0) { if(argc >= 3) { ip = strcpy(malloc(strlen(argv[2])+1), argv[2]); } if(argc >= 4) { connect_port = atoi(argv[3]); } net_mode = NET_MODE_CLIENT; } else if(strcmp(argv[1], "-l") == 0) { if(argc >= 3) { listen_port = atoi(argv[2]); } net_mode = NET_MODE_SERVER; } } // Init log #if defined(DEBUGMODE) || defined(STANDALONE_SERVER) if(log_init(0)) { err_msgbox("Error while initializing log!"); goto exit_0; } #else if(log_init(pm_get_local_path(LOG_PATH))) { err_msgbox("Error while initializing log '%s'!", pm_get_local_path(LOG_PATH)); goto exit_0; } #endif // Simple header INFO("Starting OpenOMF v%d.%d.%d", V_MAJOR, V_MINOR, V_PATCH); // Dump pathmanager log pm_log(); // Random seed rand_seed(time(NULL)); // Init stringparser sd_stringparser_lib_init(); // Init config if(settings_init(pm_get_local_path(CONFIG_PATH))) { err_msgbox("Failed to initialize settings file"); goto exit_1; } settings_load(); // Find plugins and make sure they are valid plugins_init(); // Network game override stuff if(ip) { DEBUG("Connect IP overridden to %s", ip); settings_get()->net.net_connect_ip = ip; } if(connect_port > 0 && connect_port < 0xFFFF) { DEBUG("Connect Port overridden to %u", connect_port&0xFFFF); settings_get()->net.net_connect_port = connect_port; } if(listen_port > 0 && listen_port < 0xFFFF) { DEBUG("Listen Port overridden to %u", listen_port&0xFFFF); settings_get()->net.net_listen_port = listen_port; } // Init SDL2 unsigned int sdl_flags = SDL_INIT_TIMER; #ifndef STANDALONE_SERVER sdl_flags |= SDL_INIT_VIDEO; #endif if(SDL_Init(sdl_flags)) { err_msgbox("SDL2 Initialization failed: %s", SDL_GetError()); goto exit_2; } SDL_version sdl_linked; SDL_GetVersion(&sdl_linked); INFO("Found SDL v%d.%d.%d", sdl_linked.major, sdl_linked.minor, sdl_linked.patch); INFO("Running on platform: %s", SDL_GetPlatform()); #ifndef STANDALONE_SERVER if(SDL_InitSubSystem(SDL_INIT_JOYSTICK|SDL_INIT_GAMECONTROLLER|SDL_INIT_HAPTIC)) { err_msgbox("SDL2 Initialization failed: %s", SDL_GetError()); goto exit_2; } // Attempt to find gamecontrollerdb.txt, either from resources or from // built-in header SDL_RWops *rw = SDL_RWFromConstMem(gamecontrollerdb, strlen(gamecontrollerdb)); SDL_GameControllerAddMappingsFromRW(rw, 1); char *gamecontrollerdbpath = malloc(128); snprintf(gamecontrollerdbpath, 128, "%s/gamecontrollerdb.txt", pm_get_local_path(RESOURCE_PATH)); int mappings_loaded = SDL_GameControllerAddMappingsFromFile(gamecontrollerdbpath); if (mappings_loaded > 0) { DEBUG("loaded %d mappings from %s", mappings_loaded, gamecontrollerdbpath); } free(gamecontrollerdbpath); // Load up joysticks INFO("Found %d joysticks attached", SDL_NumJoysticks()); SDL_Joystick *joy; char guidstr[33]; for (int i = 0; i < SDL_NumJoysticks(); i++) { joy = SDL_JoystickOpen(i); if (joy) { SDL_JoystickGUID guid = SDL_JoystickGetGUID(joy); SDL_JoystickGetGUIDString(guid, guidstr, 33); INFO("Opened Joystick %d", i); INFO(" * Name: %s", SDL_JoystickNameForIndex(i)); INFO(" * Number of Axes: %d", SDL_JoystickNumAxes(joy)); INFO(" * Number of Buttons: %d", SDL_JoystickNumButtons(joy)); INFO(" * Number of Balls: %d", SDL_JoystickNumBalls(joy)); INFO(" * Number of Hats: %d", SDL_JoystickNumHats(joy)); INFO(" * GUID : %s", guidstr); } else { INFO("Joystick %d is unsupported", i); } if (SDL_JoystickGetAttached(joy)) { SDL_JoystickClose(joy); } } // Init libDumb dumb_register_stdfiles(); #endif // Init enet if(enet_initialize() != 0) { err_msgbox("Failed to initialize enet"); goto exit_3; } // Initialize engine if(engine_init()) { err_msgbox("Failed to initialize game engine."); goto exit_4; } // Run engine_run(net_mode); // Close everything engine_close(); exit_4: enet_deinitialize(); exit_3: SDL_Quit(); exit_2: dumb_exit(); settings_save(); settings_free(); exit_1: sd_stringparser_lib_deinit(); INFO("Exit."); log_close(); exit_0: if (ip) { free(ip); } plugins_close(); pm_free(); return ret; }
int main(int argc, char * argv[]) { // board_t board[1]; // init Init = false; #ifdef _WIN32 signal(SIGINT,SIG_IGN); signal(SIGTERM,SIG_IGN); #ifdef SIGPIPE signal(SIGPIPE,SIG_IGN); #endif #endif util_init(); printf("PolyGlot %s by Fabien Letouzey\n",Version); option_init(); uci_options_init(); square_init(); piece_init(); attack_init(); hash_init(); my_random_init(); // build book if (argc >= 2 && my_string_equal(argv[1],"make-book")) { book_make(argc,argv); return EXIT_SUCCESS; } if (argc >= 2 && my_string_equal(argv[1],"merge-book")) { book_merge(argc,argv); return EXIT_SUCCESS; } // read options if (argc == 2) option_set("OptionFile",argv[1]); // HACK for compatibility parse_option(); // HACK: also launches the engine // EPD test if (argc >= 2 && my_string_equal(argv[1],"epd-test")) { epd_test(argc,argv); return EXIT_SUCCESS; } // opening book book_clear(); if (option_get_bool("Book")){ if (book_open(option_get_string("BookFile"))) option_set("Book","false");//some error,set to false } //adapter_loop(); #ifdef _WIN32 Engine_ready_ok=CreateEvent(NULL,FALSE,FALSE,NULL); Engine_sync_stop = CreateEvent(NULL,FALSE,FALSE,NULL); // all set and done.lets open a thread for fun DWORD dwThreadID; HANDLE hThread; hThread= CreateThread( NULL, //default security attributes 0, //default stacksize ThreadFunc, //The thread function! &sCommand, //the commands for the thread function 0, //default creation flags &dwThreadID); //the thread identifier Idle500msecs();// if(hThread==NULL){ my_log("CreateThread failed\n"); } #endif adapter_loop(); engine_send(Engine,"quit"); engine_close(Engine); #ifdef _WIN32 CloseHandle(hThread); //close the thread; #endif return EXIT_SUCCESS; }