/* * Main routine for power server. */ int main(int argc, char *argv[]) { static struct msg msg; const struct msg_map *map; object_t obj; struct bind_msg bm; object_t execobj, procobj; int error; sys_log("Starting power server\n"); /* Boost thread priority. */ thread_setpri(thread_self(), PRI_POW); /* * Wait until all required system servers * become available. */ wait_server("!proc", &procobj); wait_server("!exec", &execobj); /* * Request to bind a new capabilities for us. */ bm.hdr.code = EXEC_BINDCAP; strlcpy(bm.path, "/boot/pow", sizeof(bm.path)); msg_send(execobj, &bm, sizeof(bm)); /* * Register to process server */ register_process(); /* * Initialize power service. */ pow_init(); /* * Create an object to expose our service. */ error = object_create("!pow", &obj); if (error) sys_panic("fail to create object"); /* * Message loop */ for (;;) { /* * Wait for an incoming request. */ error = msg_receive(obj, &msg, sizeof(msg)); if (error) continue; DPRINTF(("pow: msg code=%x task=%x\n", msg.hdr.code, msg.hdr.task)); /* Check client's capability. */ if (task_chkcap(msg.hdr.task, CAP_POWERMGMT) != 0) { map = NULL; error = EPERM; } else { error = EINVAL; map = &powermsg_map[0]; while (map->code != 0) { if (map->code == msg.hdr.code) { error = (*map->func)(&msg); break; } map++; } } /* * Reply to the client. */ msg.hdr.status = error; msg_reply(obj, &msg, sizeof(msg)); #ifdef DEBUG_POWER if (map != NULL && error != 0) DPRINTF(("pow: msg code=%x error=%d\n", map->code, error)); #endif } }
/* //------------------------------------------------------------------------------------------------------ // Allocate shraed memory ,set semaphore,wakeup audio server // //------------------------------------------------------------------------------------------------------ */ static int preinit(sh_audio_t *sh) { #ifndef EngineMode union smc *sc; long curr_codec; #endif { #ifndef EngineMode if(sh->samplesize==2) { sh->sample_format=AF_FORMAT_S16_LE; //packing as 2 bytes }else if(sh->samplesize==1) { sh->sample_format=AF_FORMAT_U8; //packing as 1 bytes }else if(sh->samplesize==4) { sh->sample_format=AF_FORMAT_S32_LE; //packing as 4 bytes } #endif sh->audio_out_minsize = BLOCKS_PER_LOOP*2*sh->samplesize; } #ifndef EngineMode #ifdef AD_SHM_REWRITE sm_com_id = get_first_shared_mem_id(KEY_SM_COM, SM_COM_SIZE); if(sm_com_id < 0) sm_com_id = get_shared_mem_id(KEY_SM_COM, SM_COM_SIZE); //get shared memory ID if(sm_com == NULL) { if ((sm_com = allocate_share_mem(sm_com_id))==NULL) //allocate shared memory ( command ) return 0; } #else sm_com_id = get_shared_mem_id(KEY_SM_COM, SM_COM_SIZE); //get shared memory ID if ((sm_com = allocate_share_mem(sm_com_id))==NULL) //allocate shared memory ( command ) return 0; #endif id = get_semaphore_id(); //get semaphore ID if (!reset_semvalue(id, 0)){ //reset semaphore return 0; } sc = (union smc *)sm_com; sc->magic.magic_num = PLAYER_MAGIC; curr_codec = APE_ID; //inform server what kind of coded to be used. sc->magic.codec_id = curr_codec; if (!semaphore_v(id, 1)) //wakeup server! return 0; if (!wait_server(sc)){ //wait for server's response deallocate_share_mem(sm_com); #ifndef AD_SHM_REWRITE shmctl(sm_com_id, IPC_RMID, 0); #endif del_semvalue(id, 0); printf("Audio server crash \n"); return 0; } if (sc->magic.codec_id != curr_codec){ //check codec printf("Unsuppoted codec\n"); return 0; } #endif csd_avail_num = res_num = 0; return 1; }
/* //------------------------------------------------------------------------------------------------------ // Allocate shraed memory ,set semaphore,wakeup audio server // //------------------------------------------------------------------------------------------------------ */ static int preinit(sh_audio_t *sh) { aserver_pid = 0; #ifndef EngineMode union smc *sc; long curr_codec; #endif { sh->audio_out_minsize = 320; } #ifndef EngineMode #ifdef AD_SHM_REWRITE sm_com_id = get_first_shared_mem_id(KEY_SM_COM, SM_COM_SIZE); if(sm_com_id < 0) sm_com_id = get_shared_mem_id(KEY_SM_COM, SM_COM_SIZE); //get shared memory ID if(sm_com == NULL) { if ((sm_com = allocate_share_mem(sm_com_id))==NULL) //allocate shared memory ( command ) return 0; } #else sm_com_id = get_shared_mem_id(KEY_SM_COM, SM_COM_SIZE); //get shared memory ID if ((sm_com = allocate_share_mem(sm_com_id))==NULL) //allocate shared memory ( command ) return 0; #endif id = get_semaphore_id(); //get semaphore ID if (!reset_semvalue(id, 0)){ //reset semaphore return 0; } sc = (union smc *)sm_com; sc->magic.magic_num = PLAYER_MAGIC; curr_codec = AMRNB_ID; //inform server what kind of coded to be used. sc->magic.codec_id = curr_codec; if (!semaphore_v(id, 1)) //wakeup server! return 0; if (!wait_server(sc)){ //wait for server's response deallocate_share_mem(sm_com); #ifndef AD_SHM_REWRITE shmctl(sm_com_id, IPC_RMID, 0); #endif del_semvalue(id, 0); printf("Audio server crash \n"); return 0; } if (sc->magic.codec_id != curr_codec){ //check codec printf("Unsuppoted codec\n"); return 0; } #endif aserver_pid = sc->pinit.pid; return 1; }