int _tmain(int argc, _TCHAR* argv[]) { try { LoadConfig(); boost::asio::io_service io_service; APP_EVENT("Application Start"); // Initialise server. http::server::server s(io_service); if ( ! s.start() ) { APP_ERROR("Http Tips Server Start Error"); return 0; } APP_ERROR("Application Start Succeed"); // Set console control handler to allow server to be stopped. console_ctrl_function = boost::bind(&http::server::server::stop, &s); SetConsoleCtrlHandler(console_ctrl_handler, TRUE); // Run the server until stopped. io_service.run(); } catch (std::exception& e) { std::cerr << "exception: " << e.what() << "\n"; } return 0; }
SDL_Surface *sdlMainScreenInit(DWORD nResW, DWORD nResH) { SDL_Surface *screen; Uint8 video_bpp; Uint32 videoflags; /* Initialize SDL */ if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 ) { APP_ERROR("Couldn't initialize SDL: %s\n", SDL_GetError()); return NULL; } //atexit(SDL_Quit); /* Clean up on exit */ video_bpp = 24; /* double buffer & full screen */ //videoflags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN; //screen=SDL_SetVideoMode(0, 0, video_bpp,videoflags); videoflags = SDL_HWSURFACE | SDL_DOUBLEBUF; screen=SDL_SetVideoMode(nResW, nResH, video_bpp, videoflags); if ( screen == NULL ) { APP_ERROR("Couldn't set screen x %d video mode: %s\n", video_bpp, SDL_GetError() ); SDL_Quit(); return NULL; } /* Set the window manager title bar */ SDL_WM_SetCaption("PW projector Steam Viewer", "pwStreamViewer"); APP_INFO("screen size %d x %d\n", screen->w, screen->h); return screen; }
static int get_lib_image_params(void) { if (mw_get_auto_local_exposure_mode(&g_mw_basic_iq.local_exposure_mode) < 0) { APP_ERROR("mw_get_auto_local_exposure_mode error\n"); return -1; } iq_map.local_exposure_mode = g_mw_basic_iq.local_exposure_mode; if (mw_get_mctf_strength(&g_mw_basic_iq.mctf_strength) < 0) { APP_ERROR("mw_get_mctf_strength error\n"); return -1; } iq_map.mctf_strength = g_mw_basic_iq.mctf_strength; if (mw_get_exposure_level((int*)&g_mw_basic_iq.ae_target_ratio) < 0) { APP_ERROR("mw_get_exposure_level error\n"); return -1; } iq_map.ae_target_ratio = g_mw_basic_iq.ae_target_ratio; iq_map.day_night_mode = 0; iq_map.back_light_comp_enable = 0; iq_map.dc_iris_enable = 0; return 0; }
static int config_imager(void) { load_config_file(); #if 0 if (mw_set_iq_preference(iq_map.ae_preference) < 0) { APP_PRINTF("mw_set_iq_preference error\n"); } #endif if (mw_set_ae_param(&iq_map.ae) < 0) { APP_ERROR("mw_set_ae_param error\n"); return -1; } if (mw_set_image_param(&image_map) < 0) { APP_ERROR("mw_set_image_param error\n"); return -1; } if (mw_set_awb_param(&awb_map) < 0) { APP_ERROR("mw_set_awb_param error\n"); return -1; } if (set_basic_image_params(&iq_map) < 0) { APP_ERROR("set_basic_image_params error\n"); return -1; } g_mw_basic_iq = iq_map; g_mw_image = image_map; g_mw_awb = awb_map; return 0; }
static int start_server(void) { int flag = 1; struct sockaddr_in server_addr; APP_ASSERT(sockfd <= 0); if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { APP_ERROR("socket failed %d !\n", sockfd); return -1; } if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)) < 0) { APP_ERROR("setsockopt\n"); return -1; } memset(&server_addr, 0, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(IMAGE_SERVER_PORT); server_addr.sin_addr.s_addr = htons(INADDR_ANY); if (bind(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { APP_ERROR("bind\n"); return -1; } if (listen(sockfd, 10) < 0) { APP_ERROR("listen\n"); return -1; } return 0; }
//------------------------------------------------------------------------------------------------ // Name: obtainSourceGeometry // Desc: Loads geometry from the source file into the output subset geometry //------------------------------------------------------------------------------------------------ bool XMesh::obtainSourceGeometry(LPDIRECT3DDEVICE9 pd3dDevice, SubsetGeometry* subsetGeometry) const { // Fail without a device or if something is wrong with the output pointer if (APP_ERROR(!pd3dDevice || !subsetGeometry)("Invalid paramter to obtainSourceGeometry") || APP_ERROR(!subsetGeometry->empty())("Provided geometry subset for obtainSourceGeometry must be empty")) return false; // Check to make sure a file exists (if not, just exit) if (mySourceFile.getValue().empty()) return true; // Keeps track of how many subsets this mesh contains DWORD subsets = 0; // Stores the mesh that was loaded from the file LPD3DXMESH pXMesh = NULL; // Load the mesh from the specified file if (APP_ERROR(D3DXLoadMeshFromX(mySourceFile.getValue().c_str(), D3DXMESH_SYSTEMMEM, pd3dDevice, NULL, NULL, NULL, &subsets, &pXMesh))("XMesh couldn't load \"%s\"", mySourceFile.getValue().c_str())) return false; // Convert the mesh bool succeeded = buildGeometryFromD3DXMesh(pXMesh, subsetGeometry, subsets); // Release the mesh pXMesh->Release(); // Return an error code if an error occurred if (APP_ERROR(!succeeded)("Unable to build geometry for mesh from \"%s\"", mySourceFile.getValue().c_str())) return false; // Success return true; }
static void receive_cb_image(union sigval sv) { while (mq_receive(*(mqd_t *)sv.sival_ptr, (char *)receive_buffer, MAX_MESSAGES_SIZE, NULL) >= 0){ //INFO("RECEIVE MESSAGE:%s", receive_buffer); int i = 0; while(i < CMD_COUNT) { if(i == receive_buffer->cmd_id) { process_cmd(i); break; } i++; } if(i == CMD_COUNT) { send_buffer->cmd_id = UNSUPPORTED_ID; sprintf(send_buffer->data, "UNSUPPORTED_ID!"); APP_ERROR("NOT SUPPORTED COMMAND!"); } while(1){ if (0 != mq_send (msg_queue_send, (char *)send_buffer, MAX_MESSAGES_SIZE, 0)) { APP_ERROR("mq_send failed!"); continue; } break; } memset(send_buffer, 0, MAX_MESSAGES_SIZE); memset(receive_buffer, 0, MAX_MESSAGES_SIZE); } NotifySetup((mqd_t *)sv.sival_ptr); }
static int init_server(void) { if (mw_start_aaa(fd_iav) < 0) { APP_ERROR("mw_start_aaa"); #ifdef CONFIG_AMBARELLA_IMAGE_SERVER_DAEMON nl_image_config.nl_msg.pid = getpid(); nl_image_config.nl_msg.index = IMAGE_MSG_INDEX_AAA_STATUS; nl_image_config.nl_msg.msg.image_status = IMAGE_STATUS_START_AAA_FAIL; send_image_msg_to_kernel(nl_image_config.nl_msg); #endif return -1; } #ifdef CONFIG_AMBARELLA_IMAGE_SERVER_DAEMON nl_image_config.nl_msg.pid = getpid(); nl_image_config.nl_msg.index = IMAGE_MSG_INDEX_AAA_STATUS; nl_image_config.nl_msg.msg.image_status = IMAGE_STATUS_START_AAA_SUCCESS; send_image_msg_to_kernel(nl_image_config.nl_msg); #endif if (mw_set_log_level(G_log_level) < 0) { APP_ERROR("mw_set_log_level"); return -1; } if (get_library_params() < 0) { APP_ERROR("get_library_params"); return -1; } if (config_imager() < 0) { APP_ERROR("config_imager"); return -1; } APP_INFO("[Done] init image_server\n"); return 0; }
/* main application */ int main(int argc, char *argv[]) { int i; char *ifname, ofname[FILENAME_MAX], *cfile, ch; FILE *ifile, *ofile; unsigned long len; struct stat sinfo; unsigned int cmd_loadaddr = 0xFFFFFFFF; int c; char *appname = argv[0]; /* Default to x-load.bin and 0x40200800 and no config file */ ifname = "x-load.bin"; cfile = NULL; loadaddr = 0x40208800; while ((c = getopt(argc, argv, CONFIG_FILE_ARG ":" IMAGE_FILE_ARG ":" LOAD_ADDRESS_ARG ":")) != -1) switch (c) { case CONFIG_FILE_ARG_C: cfile = optarg; break; case IMAGE_FILE_ARG_C: ifname = optarg; break; case LOAD_ADDRESS_ARG_C: sscanf(optarg, "%x", &cmd_loadaddr); break; case '?': i = 0; if ((optopt == IMAGE_FILE_ARG_C) || (optopt == CONFIG_FILE_ARG_C) || (optopt == LOAD_ADDRESS_ARG_C)) { APP_ERROR("Option -%c requires an argument.\n", optopt); } else if (optopt == '?') { APP_ERROR("EXTENDED help\n") i = 1; } else if (isprint(optopt)) { APP_ERROR("Unknown option `-%c'.\n", optopt) } else { APP_ERROR("Unknown option character `\\x%x'.\n", optopt) } usage(appname, i); return 1; default: abort(); }
bool loadXFile( const std::string& filename, FrameNode* rootFrameNode, LPDIRECT3DDEVICE9 d3dDevice ) { ID3DXFile* dxFile = 0; ID3DXFileEnumObject* dxFileEnum = 0; // Create the file parsing structure if( APP_ERROR( FAILED( D3DXFileCreate( &dxFile ) ) )( "Couldn't create IDirectXFile to parse source file" ) ) goto FAILED; // Register templates for parsing an X file if( APP_ERROR( FAILED( dxFile->RegisterTemplates( (LPVOID)D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES ) ) ) ( "Failed to register D3DRM X-file templates" ) ) goto FAILED; // Register extended templates for parsing an X file if( APP_ERROR( FAILED( dxFile->RegisterTemplates( (LPVOID)XSKINEXP_TEMPLATES, sizeof(XSKINEXP_TEMPLATES) - 1 ) ) ) ( "Failed to register extended X-file templates" ) ) goto FAILED; // Create an enumerator so that we can look at the top-level entries in the file if( APP_ERROR( FAILED( dxFile->CreateEnumObject( (LPCVOID)filename.c_str(), D3DXF_FILELOAD_FROMFILE, &dxFileEnum ) ) ) ( "Couldn't create enumerator for .X file in memory" ) ) goto FAILED; // Scan all of the top-level objects in the file bool continueLoading = true; SIZE_T numberOfChildren; dxFileEnum->GetChildren( &numberOfChildren ); for( SIZE_T i = 0; continueLoading && i < numberOfChildren; ++i ) { ID3DXFileData* dxFileDataObject = NULL; continueLoading = !APP_ERROR( FAILED( dxFileEnum->GetChild( i, &dxFileDataObject ) ) || !rootFrameNode->load( dxFileDataObject, d3dDevice ) )( "Couldn't load element" ); SAFE_RELEASE( dxFileDataObject ); } // Free the file objects SAFE_RELEASE( dxFileEnum ); SAFE_RELEASE( dxFile ); // Success return true; FAILED: SAFE_RELEASE( dxFileEnum ); SAFE_RELEASE( dxFile ); return false; }
static int get_library_params(void) { // Get AE settings if (mw_get_ae_param(&g_mw_basic_iq.ae) < 0) { APP_ERROR("mw_get_ae_param error\n"); return -1; } memcpy(&iq_map.ae, &g_mw_basic_iq.ae, sizeof(mw_ae_param)); // Get Image settings if (mw_get_image_param(&g_mw_image) < 0) { APP_ERROR("mw_get_image_param error\n"); return -1; } memcpy(&image_map, &g_mw_image, sizeof(mw_image_param)); // Get AWB settings if (mw_get_awb_param(&g_mw_awb) < 0) { APP_ERROR("mw_get_awb_param error\n"); return -1; } memcpy(&awb_map, &g_mw_awb, sizeof(mw_awb_param)); // Get AF settings if (mw_get_af_param(&g_mw_af) < 0) { APP_ERROR("mw_get_af_param error\n"); return -1; } memcpy(&af_map, &g_mw_af, sizeof(mw_af_param)); // Get other settings #if 0 if (mw_get_iq_preference(&g_mw_basic_iq.ae_preference) < 0) { APP_ERROR("mw_get_iq_preference error\n"); return -1; } iq_map.ae_preference = g_mw_basic_iq.ae_preference; if (mw_get_ae_metering_mode(&g_mw_basic_iq.metering_mode) < 0) { APP_ERROR("mw_get_ae_metering_mode error\n"); return -1; } iq_map.metering_mode = g_mw_basic_iq.metering_mode; if (mw_get_auto_local_exposure_mode(&g_mw_basic_iq.local_exposure_mode) < 0) { APP_ERROR("mw_get_auto_local_exposure_mode error\n"); return -1; } iq_map.local_exposure_mode = g_mw_basic_iq.local_exposure_mode; if (mw_get_mctf_strength(&g_mw_basic_iq.mctf_strength) < 0) { APP_ERROR("mw_get_mctf_strength error\n"); return -1; } iq_map.mctf_strength = g_mw_basic_iq.mctf_strength; #endif if(get_lib_image_params() < 0) { APP_ERROR("get_lib_image_params error\n"); return -1; } return 0; }
bool GlobalSoundManager::create(HWND hMainWindow) { if (APP_ERROR(FAILED(DirectSoundCreate8(NULL, &direct_sound_, NULL)) || FAILED(direct_sound_->SetCooperativeLevel(hMainWindow, DSSCL_NORMAL))) ("Couldn't initialize DirectSound")) return false; return true; }
int main(int argc, char **argv) { signal(SIGINT, sigstop); signal(SIGQUIT, sigstop); signal(SIGTERM, sigstop); if ((fd_iav = open("/dev/iav", O_RDWR, 0)) < 0) { perror("open /dev/iav"); return -1; } if (init_param(argc, argv) < 0) { usage(); return -1; } parse_default_configs(); if (create_server() < 0) { APP_ERROR("create_server"); return -1; } main_handle(); #if 0 while (1) { main_loop(); } #endif while (1) { sleep(1); } return 0; }
static int do_aaa_control(Request *req) { int retv = 0; Ack ack; APP_INFO("Process AAA control id [%d].\n", (int)req->info); switch (req->info) { case AAA_START: retv = mw_start_aaa(fd_iav); if (retv < 0) { APP_ERROR("mw_start_aaa failed!\n"); } APP_INFO("AAA control : Start AAA done !\n"); break; case AAA_STOP: retv = mw_stop_aaa(); APP_INFO("AAA control : Stop AAA done !\n"); break; default: APP_PRINTF("Unknown AAA control id [%d]\n", (int)req->info); break; } ack.result = ack.info = retv; retv = send_text((u8 *)&ack, sizeof(ack)); return retv; }
static int set_image_param(char * section_name) { APP_INFO("Section [%s] settings:\n", section_name); #if 0 if (g_mw_basic_iq.ae_preference != iq_map.ae_preference) { if (mw_set_iq_preference(iq_map.ae_preference) < 0) { APP_PRINTF("mw_set_iq_preference error\n"); } g_mw_basic_iq.ae_preference = iq_map.ae_preference; } #endif if (0 != memcmp(&g_mw_basic_iq.ae, &iq_map.ae, sizeof(g_mw_basic_iq.ae))) { if (mw_set_ae_param(&iq_map.ae) < 0) { APP_ERROR("mw_set_ae_param error\n"); return -1; } else { g_mw_basic_iq.ae = iq_map.ae; } } if (0 != memcmp(&g_mw_image, &image_map, sizeof(g_mw_image))) { if (mw_set_image_param(&image_map) < 0) { APP_ERROR("mw_set_image_param error\n"); return -1; } else { g_mw_image = image_map; } } if (0 != memcmp(&g_mw_awb, &awb_map, sizeof(g_mw_awb))) { if (mw_set_awb_param(&awb_map) < 0) { APP_ERROR("mw_set_awb_param error\n"); return -1; } else { g_mw_awb = awb_map; } } if (0 != memcmp(&g_mw_basic_iq, &iq_map, sizeof(g_mw_basic_iq))) { if (set_basic_image_params(&iq_map) < 0) { APP_ERROR("set_basic_image_params error\n"); return -1; } else { g_mw_basic_iq = iq_map; } } return 0; }
static void main_handle(void) { if (start_mq() < 0) { APP_ERROR("start_mq"); return; } return; }
type_handler_i *typereg_get_handler(int type_id) { if (!g_reg()->by_number[type_id]) { APP_ERROR("Type id " << type_id << " has no handler"); } return g_reg()->by_number[type_id]; }
void ServerEquipmentSlotMask::equipment_unequipMultipleSlotItem(const ServerEquipmentSlotMask* itemFilledSlotsMask) { // Make sure this item was equipped APP_ERROR(!(((itemFilledSlotsMask->mask ^ mask) & itemFilledSlotsMask->mask) == itemFilledSlotsMask->mask))("Unequipping item that was not equipped"); // Free up the item's occupied slots mask |= itemFilledSlotsMask->mask; }
int send_text(u8 *pBuffer, u32 size) { int retv = send(sockfd2, pBuffer, size, MSG_NOSIGNAL); if ((u32)retv != size) { APP_ERROR("send() returns %d\n", retv); return -1; } return 0; }
type_handler_i *typereg_get_handler(type_t t) { if (!g_reg()->handlers[t]) { APP_ERROR("Type " << t << " has no handler") } return g_reg()->handlers[t]; }
static int get_image_stat(char * section_name, u32 info) { APP_INFO("Section [%s] setting:\n", section_name); if (mw_get_image_statistics(&image_stat_map) < 0) { APP_ERROR("mw_get_image_statistics"); return -1; } return 0; }
/* signalHandler ** ** Purpose: ** Handle any kill interrupts i.e. pressing control-C ** ** Parameter Dictionary: ** None ** ** Return Values: ** None ** ** Notes: ** ** Algorithm: ** Description of the algorithm (optional) and any other notes. */ static void signalHandler() { CONDITION cond; fprintf(stderr, "\nProcess Killed\n"); cond = COND_PushCondition(APP_ERROR(APP_OPERATIONINTERRUPTED)); exitApplication(cond); }
/* addChildProcess ** ** Purpose: ** Adds information about a child to the process list maintained by ** the parent ** ** Parameter Dictionary: ** service Handle to the service parameters ** pid Process ID of the child ** list Handle to the list of processes ** ** Return Values: ** APP_NORMAL ** APP_MALLOCFAILURE ** APP_FAILURE ** ** Notes: ** ** Algorithm: ** Description of the algorithm (optional) and any other notes. */ static CONDITION addChildProcess(DUL_ASSOCIATESERVICEPARAMETERS * service, int pid, LST_HEAD ** list) { PROCESS_ELEMENT * e; if ((e = malloc(sizeof(PROCESS_ELEMENT))) == NULL) { return COND_PushCondition(APP_ERROR(APP_MALLOCFAILURE)); } strcpy(e->callingAPTitle, service->callingAPTitle); strcpy(e->calledAPTitle, service->calledAPTitle); e->pid = pid; if (LST_Enqueue(list, e) != LST_NORMAL) { return COND_PushCondition(APP_ERROR(APP_FAILURE), "LST_Enqueue", "addChildProcess"); } return APP_NORMAL; }
void ServerEquipmentSlotMask::equipment_unequipSingleSlotItem(const ServerEquipmentSlotMask* itemCompatibilityMask) { // Get the bits from this equipment mask that are used which are potentially // filled by this item unsigned long unavailableMask = itemCompatibilityMask->mask & (~mask); // Find the first bit that is unavailable int bit = getLowestBitSet(unavailableMask); if (APP_ERROR(bit < 0)("Unequipping item that wasn't equippped!")) return; mask |= 1 << bit; }
static CONDITION openGQ(int qID) { CONDITION cond; /* Get a new or existing Queue for the GQ operations */ if (gqueueFlag) { #ifdef ASG cond = GQ_GetQueue(qID, sizeof(GQ_ELEM)); if (cond != GQ_NORMAL) { (void) COND_PopCondition(TRUE); /* necessary to clear the * stack since, this is not * an error and any * conditions dumped later, * unnecessarily displays * this message */ /* The Q may not be existing, in which case we create one */ cond = GQ_InitQueue(qID, 128, sizeof(GQ_ELEM)); if (cond != GQ_NORMAL) { return COND_PushCondition(APP_ERROR(APP_FAILURE), "GQ_InitQueue", "main"); } } appHandles.gqID = qID; /* set the gqID field */ /* Now again invoke GetQueue */ #endif /* * We try to open an existing Queue. It is assumed that an * accompanying program viz. print_server_display will be running * with the desired GQ already created */ cond = GQ_GetQueue(qID, sizeof(GQ_ELEM)); if (cond != GQ_NORMAL) { return COND_PushCondition(APP_ERROR(APP_FAILURE), "GQ_GetQueue", "main"); } } return APP_NORMAL; }
static int set_local_exposure_mode(u32 mode) { if (mode != LE_CUSTOMER) { if (mw_set_auto_local_exposure_mode(mode) < 0) { APP_ERROR("mw_set_local_exposure_curve error.\n"); return -1; } } else { if (img_set_auto_local_exposure(0) < 0) { APP_ERROR("img_set_auto_local_exposure error.\n"); return -1; } sleep(1); if (mw_set_local_exposure_curve(fd_iav, &G_local_exposure[2]) < 0) { APP_ERROR("mw_set_local_exposure_curve error.\n"); return -1; } } return 0; }
static int create_server(void) { if (create_pid_file(IMAGE_SERVER_PROC) < 0) { APP_ERROR("create_pid_file"); return -1; } if (init_server() < 0) { APP_ERROR("init_server"); return -1; } #if 0 #ifndef CONFIG_AMBARELLA_IMAGE_SERVER_DAEMON if (start_server() < 0) { APP_ERROR("start_server"); return -1; } #endif #endif APP_INFO("[Done] create image_server\n"); return 0; }
//------------------------------------------------------------------------------------------------ // Name: initialize // Desc: Sets up the sprite manager for use. This must be called before //------------------------------------------------------------------------------------------------ bool SpriteManager::initialize(LPDIRECT3DDEVICE9 d3dDevice) { // Make sure the sprite renderer doesn't already exist if (APP_WARNING(mySpriteRenderer != 0)("SpriteManager - multiple initialization")) return false; // Create the rendering sprite if (APP_ERROR(FAILED(D3DXCreateSprite(d3dDevice, &mySpriteRenderer)))("Unable to create sprite renderer for GUI")) return false; // Success return true; }
static int start_mq(void) { struct mq_attr attr; attr.mq_flags = 0; attr.mq_maxmsg = MAX_MESSAGES; attr.mq_msgsize = MAX_MESSAGES_SIZE; attr.mq_curmsgs = 0; if (create_message_queue( &attr) < 0) { APP_ERROR("Failed to create mq."); return -1; } return 0; }
int receive_text(u8 *pBuffer, u32 size) { int retv = recv(sockfd2, pBuffer, size, MSG_WAITALL); if (retv <= 0) { if (retv == 0) { APP_INFO("Port [%d] closed\n\n", IMAGE_SERVER_PORT); return -2; } APP_ERROR("recv() returns %d\n", retv); return -1; } return retv; }