int sandbox_init(sandbox_t * psbox, const char * argv[]) { FUNC_BEGIN("sandbox_init(%p,%p)", psbox, argv); assert(psbox); if (psbox == NULL) { WARNING("psbox: bad pointer"); FUNC_RET(-1, "sandbox_init()"); } pthread_mutex_init(&psbox->mutex, NULL); P(&psbox->mutex); pthread_cond_init(&psbox->update, NULL); __sandbox_task_init(&psbox->task, argv); __sandbox_stat_init(&psbox->stat); __sandbox_ctrl_init(&psbox->ctrl, (thread_func_t)__sandbox_tracer, #ifdef WITH_CUSTOM_MONITOR (thread_func_t)__sandbox_monitor #else (thread_func_t)(NULL) #endif /* WITH_CUSTOM_MONITOR */ ); V(&psbox->mutex); P(&psbox->mutex); psbox->result = S_RESULT_PD; psbox->status = S_STATUS_PRE; pthread_cond_broadcast(&psbox->update); V(&psbox->mutex); FUNC_RET(0, "sandbox_init()"); }
int sandbox_fini(sandbox_t * psbox) { FUNC_BEGIN("sandbox_fini(%p)", psbox); assert(psbox); if (psbox == NULL) { WARNING("psbox: bad pointer"); FUNC_RET(-1, "sandbox_fini()"); } P(&psbox->mutex); psbox->result = S_RESULT_PD; psbox->status = S_STATUS_FIN; pthread_cond_broadcast(&psbox->update); V(&psbox->mutex); P(&psbox->mutex); __sandbox_task_fini(&psbox->task); __sandbox_stat_fini(&psbox->stat); __sandbox_ctrl_fini(&psbox->ctrl); pthread_cond_destroy(&psbox->update); V(&psbox->mutex); pthread_mutex_destroy(&psbox->mutex); FUNC_RET(0, "sandbox_fini()"); }
int32_t fs_opr_t::subscribe_event(const char* event) { FUNC_BEGIN(); (void)szcmd; (void)fs_resp; if (esl_events(&_handle, ESL_EVENT_TYPE_PLAIN, event) == ESL_SUCCESS) { TRACE_LOG("subscribe_event %s success", event); ret = IMS_SUCCESS; break; } else { WARNING_LOG("subscribe_event %s failed(connect err)", event); ims_tool_t::safe_sleepms(20); } /* if(is_handle_valid()){ ret=IMS_FAIL_TIMEOUT; break; } else if(IMS_SUCCESS!=connect(_address,_port,_pswd,true)){ WARNING_LOG("subscribe_event %s failed(connect err)",event); ret=IMS_FAIL_CONNECT; break; } */ FUNC_END(); }
int32_t fs_opr_t::eval(const char* key, char* val, uint32_t val_len) { FUNC_BEGIN(); snprintf(szcmd, LEN_512, "api eval %s\n\n", key); TRACE_LOG("eval, (%s)", szcmd); if (esl_send_recv(&_handle, szcmd) == ESL_SUCCESS && (fs_resp = esl_event_get_body(_handle.last_sr_event))) { strncpy(val, fs_resp, val_len); fs_resp = val; while (fs_resp && *fs_resp && (fs_resp - val) < val_len) { if ('\n' == *fs_resp || '\r' == *fs_resp) { val[fs_resp - val] = '\0'; break; } ++fs_resp; } ret = IMS_SUCCESS; } else { WARNING_LOG("fs_eval(%s) failed", key); } FUNC_END(); }
int32_t fs_opr_t::bridge(const char* uuid, const char* called_disp, const char* dnis) { FUNC_BEGIN(); if (set_channel_attribute(uuid, "bridge_early_media=true") && set_channel_attribute(uuid, "hangup_after_bridge=false") && set_channel_attribute(uuid, "bypass_media=false") && set_channel_attribute(uuid, "playback_terminators=none") && set_channel_attribute(uuid, "continue_on_fail=true")) { set_channel_attribute(uuid, "export_vars=IMSDATA"); snprintf(szcmd, LEN_512, "effective_caller_id_name=%s", called_disp); set_channel_attribute(uuid, szcmd); snprintf(szcmd, LEN_512, "effective_caller_id_number=%s", called_disp); set_channel_attribute(uuid, szcmd); if (esl_execute(&_handle, "bridge", dnis, uuid) == ESL_SUCCESS && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; break; } else { WARNING_LOG("fs:bridge(%s,%s,%s);ret(%s)", uuid, called_disp, dnis, fs_resp); } } FUNC_END(); }
int32_t fs_opr_t::get_var(const char* key, char* val, uint32_t val_len) { FUNC_BEGIN(); (void)fs_resp; snprintf(szcmd, LEN_512, "variable_%s", key); ret = get_head_val(szcmd, val, val_len); FUNC_END(); }
int32_t fs_opr_t::record(const char* uuid, const char* file, uint32_t time_s) { FUNC_BEGIN(); std::string full_file = _recordbase; full_file += "/"; full_file += file; TRACE_LOG("fs::record(%s) start.", full_file.c_str()); //set_channel_attribute(uuid,"playback_terminators=none"); //set_channel_attribute(uuid,"RECORD_HANGUP_ON_ERROR=false");//1.0.7的fs才有 //set_channel_attribute(uuid,"RECORD_MIN_SEC=0"); //TRACE_LOG("fs::record(%s) middle.",full_file.c_str()); snprintf(szcmd, LEN_512, CMD_RECORD_FMT, uuid, full_file.c_str(), time_s); //if(esl_send_recv(&_handle,szcmd)==ESL_SUCCESS){ // if(is_result_ok(fs_resp=esl_event_get_body(_handle.last_sr_event))){ // ret=IMS_SUCCESS; // } // else{ // WARNING_LOG("fs:record(%s,%s,%u);ret(%s)",uuid,full_file.c_str(),time_s,fs_resp); // } //} if (esl_send_recv(&_handle, szcmd) == ESL_SUCCESS && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; } else { WARNING_LOG("fs:record(%s,%s,%u) esl_send_recv != ESL_SUCCESS", uuid, full_file.c_str(), time_s); } //TRACE_LOG("fs::record(%s) done.",full_file.c_str()); FUNC_END(); }
bool proc_dump(const proc_t * const pproc, const void * const addr, long * const pword) { FUNC_BEGIN("%p,%p,%p", pproc, addr, pword); assert(pproc && addr && pword); if ((pproc == NULL) || (addr == NULL) || (pword == NULL)) { FUNC_RET("%d", false); } trace_proxy_t __trace = TRACE_PROXY(pproc); long data = (long)addr; if (__trace(T_GETDATA, &data, (proc_t *)pproc) != 0) { FUNC_RET("%d", false); } *pword = data; #ifdef DELETED #ifdef HAVE_PROCFS /* Access the memory of targeted process via procfs */ char buffer[4096]; sprintf(buffer, PROCFS "/%d/mem", pproc->pid); if (access(buffer, R_OK | F_OK) < 0) { WARNING("procfs entries missing or invalid"); FUNC_RET("%d", false); } /* Copy a word from targeted address */ int fd = open(buffer, O_RDONLY); if (lseek(fd, (off_t)addr, SEEK_SET) < 0) { extern int errno; WARNING("lseek(%d, %p, SEEK_SET) failes, ERRNO %d", fd, addr, errno); FUNC_RET("%d", false); } if (read(fd, (void *)pword, sizeof(unsigned long)) < 0) { WARNING("read"); FUNC_RET("%d", false); } close(fd); #else #warning "proc_dump() requires procfs" #endif /* HAVE_PROCFS */ #endif /* DELETED */ DBG("data.%p 0x%016lx", addr, *pword); FUNC_RET("%d", true); }
static long __trace_req(act_t action, long * const pdata, proc_t * const pproc) { FUNC_BEGIN("%d,%p,%p", action, pdata, pproc); assert(!NO_ACTION(action)); assert(pproc); long res = 0; P(&trace_mutex); /* Wait while an existing action is being performed */ while (trace_info.action != T_NOP) { DBG("waiting for slot"); pthread_cond_wait(&trace_notice, &trace_mutex); } DBG("obtained slot"); /* Propose the request */ trace_info.action = action; trace_info.pproc = pproc; trace_info.data = ((pdata != NULL)?(*pdata):(0)); trace_info.result = 0; /* Wait while the action is being performed */ while (trace_info.action != T_ACK) { DBG("requesting action %s", trace_act_name(trace_info.action)); pthread_cond_broadcast(&trace_notice); pthread_cond_wait(&trace_notice, &trace_mutex); } if (pdata != NULL) { *pdata = trace_info.data; } res = trace_info.result; DBG("collected results"); /* Release slot */ trace_info.action = T_NOP; trace_info.pproc = NULL; trace_info.data = 0; trace_info.result = 0; pthread_cond_broadcast(&trace_notice); DBG("released slot"); V(&trace_mutex); FUNC_RET("%ld", res); }
bool proc_dump(const proc_t * const pproc, const void * const addr, long * const pword) { FUNC_BEGIN("proc_dump(%p,%p,%p)", pproc, addr, pword); assert(pproc); assert(addr); assert(pword); #ifdef __linux__ /* Current instruction */ *pword = ptrace(PTRACE_PEEKDATA, pproc->pid, addr, NULL); if (errno != 0) { WARNING("ptrace:PTRACE_PEEKDATA"); FUNC_RET(false, "proc_dump()"); } #else #warning "proc_dump is not implemented for this platform" #endif #ifdef DELETED /* Access the memory of targeted process via procfs */ char buffer[4096]; sprintf(buffer, PROCFS "/%d/mem", pproc->pid); if (access(buffer, R_OK | F_OK) < 0) { WARNING("procfs entries missing or invalid"); FUNC_RET(false, "proc_dump()"); } /* Copy a word from targeted address */ int fd = open(buffer, O_RDONLY); if (lseek(fd, (off_t)addr, SEEK_SET) < 0) { extern int errno; WARNING("lseek(%d, %p, SEEK_SET) failes, ERRNO %d", fd, addr, errno); FUNC_RET(false, "proc_dump()"); } if (read(fd, (void *)pword, sizeof(unsigned long)) < 0) { WARNING("read"); FUNC_RET(false, "proc_dump()"); } close(fd); #endif /* DELETED */ DBG("data.%p 0x%08lx", addr, *pword); FUNC_RET(true, "proc_dump()"); }
bool trace_end(const proc_t * const pproc) { FUNC_BEGIN("%p", pproc); assert(pproc); trace_proxy_t __trace = TRACE_PROXY(pproc); bool res = (__trace(T_END, NULL, (proc_t *)pproc) == 0); FUNC_RET("%d", res); }
bool trace_hack(proc_t * const pproc) { FUNC_BEGIN("%p", pproc); assert(pproc); trace_proxy_t __trace = TRACE_PROXY(pproc); bool res = (__trace(T_SETREGS, NULL, pproc) == 0); FUNC_RET("%d", res); }
bool trace_self(void) { FUNC_BEGIN("trace_self()"); bool res = false; #ifdef __linux__ res = (ptrace(PTRACE_TRACEME, 0, NULL, NULL) == 0); #else #warning "trace_self is not implemented for this platform" #endif /* __linux__ */ FUNC_RET(res, "trace_self()"); }
int32_t fs_opr_t::mark_sessionid(const char* uuid, uint64_t sid) { FUNC_BEGIN(); snprintf(szcmd, LEN_512, "IMSDATA=%lu", sid); if (set_channel_attribute(uuid, szcmd) && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; } else { WARNING_LOG("fs_opr:mark_sessionid(%s,%lu);ret(%s)", uuid, sid, fs_resp); } FUNC_END(); }
int32_t fs_opr_t::conference(const char* uuid, const char* name) { FUNC_BEGIN(); (void)szcmd; if (esl_execute(&_handle, "conference", name, uuid) == ESL_SUCCESS && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; } else { WARNING_LOG("fs:conference(%s,%s);ret(%s)", uuid, name, fs_resp); } FUNC_END(); }
bool trace_kill(proc_t * const pproc, int signo) { FUNC_BEGIN("%p,%d", pproc, signo); assert(pproc); trace_proxy_t __trace = TRACE_PROXY(pproc); long data = (long)(signo); bool res = (__trace(T_KILL, &data, (proc_t *)pproc) == 0); FUNC_RET("%d", res); }
bool trace_next(proc_t * const pproc, trace_type_t type) { FUNC_BEGIN("%p,%d", pproc, type); assert(pproc); trace_proxy_t __trace = TRACE_PROXY(pproc); long data = (long)type; bool res = (__trace(T_NEXT, &data, pproc) == 0); FUNC_RET("%d", res); }
/////////////////////////////////////媒体START///////////////////////////////////////////////// int32_t fs_opr_t::stop_media(const char* uuid) { FUNC_BEGIN(); (void)szcmd; if (esl_execute(&_handle, "break", NULL, uuid) == ESL_SUCCESS && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; } else { WARNING_LOG("fs:stop_media(%s);ret(%s)", uuid, fs_resp); } FUNC_END(); }
//============================= // MotorTest // // Turn a motor connected to port // armPort at a speed of armSpeed // for waitTime seconds //============================= void MotorTest( int portNum, int motorSpeed, float waitTime ) { FUNC_BEGIN("MotorTest"); if (waitTime < 1) printf("WARNING: waitTime is lower than 1 second: %f\n", waitTime); Motor(portNum, motorSpeed); wait( waitTime ); Motor(portNum, MOTOR_OFF); FUNC_END("MotorTest"); }
bool trace_self(void) { FUNC_BEGIN(); bool res = false; #ifdef HAVE_PTRACE res = (ptrace(PTRACE_TRACEME, 0, NULL, NULL) == 0); #else #warning "trace_self() is not implemented for this platform" #endif /* HAVE_PTRACE */ FUNC_RET("%d", res); }
int32_t fs_opr_t::unbridge(const char* uuid) { FUNC_BEGIN(); snprintf(szcmd, LEN_512, CMD_UNBRIDGE_FMT, uuid); TRACE_LOG("unbridge(%s)", szcmd); if (esl_send_recv(&_handle, szcmd) == ESL_SUCCESS) { if (is_result_ok(fs_resp = esl_event_get_body(_handle.last_sr_event))) { ret = IMS_SUCCESS; } else { WARNING_LOG("fs:unbridge(%s);ret(%s)", uuid, fs_resp); } } FUNC_END(); }
int32_t fs_opr_t::play(const char* uuid, const char* file, uint32_t count) { FUNC_BEGIN(); (void)szcmd; if (set_channel_attribute(uuid, "playback_terminators=none") && esl_execute(&_handle, "playback", file, uuid) == ESL_SUCCESS && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; TRACE_LOG("fs:play(%s,%s,%u) success.", uuid, file, count); } else { WARNING_LOG("fs:play(%s,%s,%u);ret(%s)", uuid, file, count, fs_resp); } FUNC_END(); }
bool proc_bind(const void * const dummy, proc_t * const pproc) { FUNC_BEGIN("%p,%p", dummy, pproc); assert(dummy && pproc); if ((dummy == NULL) || (pproc == NULL)) { FUNC_RET("%d", false); } pproc->tflags.trace_id = ((sandbox_t *)dummy)->ctrl.tid; FUNC_RET("%d", true); }
int32_t fs_opr_t::conference_mute(const char* name, const char* member) { FUNC_BEGIN(); snprintf(szcmd, LEN_512, "api conference %s mute %s\n\n", name, member); TRACE_LOG("conference_mute(%s)", szcmd); if (esl_send_recv(&_handle, szcmd) == ESL_SUCCESS) { if (is_result_ok(fs_resp = esl_event_get_body(_handle.last_sr_event))) { ret = IMS_SUCCESS; } else { WARNING_LOG("fs:conference_mute (%s,%s);ret(%s)", name, member, fs_resp); } } FUNC_END(); }
bool trace_next(proc_t * const pproc, trace_type_t type) { FUNC_BEGIN("trace_next(%p,%d)", pproc, type); assert(pproc); bool res = false; #ifdef __linux__ pproc->tflags &= ~TFLAGS_SINGLE_STEP; pproc->tflags |= (type == TRACE_SINGLE_STEP)?(TFLAGS_SINGLE_STEP):(0U); DBG("proc.tflags 0x%08x", pproc->tflags); res = (ptrace(type, pproc->pid, NULL, NULL) == 0); #else #warning "trace_next is not implemented for this platform" #endif /* __linux__ */ FUNC_RET(res, "trace_next()"); }
int32_t fs_opr_t::bridge_ex(const char* uuid, const char* called_disp, const char* dnis, bool isAsync, bool return_ring_ready) { FUNC_BEGIN(); if (set_channel_attribute(uuid, "bridge_early_media=true") && set_channel_attribute(uuid, "hangup_after_bridge=false") && set_channel_attribute(uuid, "bypass_media=false") && set_channel_attribute(uuid, "playback_terminators=none") && set_channel_attribute(uuid, "continue_on_fail=true")) { set_channel_attribute(uuid, "export_vars=IMSDATA"); snprintf(szcmd, LEN_512, "effective_caller_id_name=%s", called_disp); set_channel_attribute(uuid, szcmd); snprintf(szcmd, LEN_512, "effective_caller_id_number=%s", called_disp); set_channel_attribute(uuid, szcmd); //char param[LEN_512+1]={0}; //snprintf(param, LEN_512, "[return_ring_ready=%s]%s", return_ring_ready ? "true" : "false", dnis); esl_status_t esl_ret = ESL_GENERR; TRACE_LOG("before bridge %s", isAsync ? "async" : "sync"); if (isAsync) { int async = _handle.async_execute; _handle.async_execute = 1; esl_ret = esl_execute(&_handle, "bridge", dnis, uuid); _handle.async_execute = async; } else { esl_ret = esl_execute(&_handle, "bridge", dnis, uuid); } TRACE_LOG("after bridge %s", isAsync ? "async" : "sync"); if (esl_ret == ESL_SUCCESS && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; break; } else { WARNING_LOG("fs:bridge(%s,%s,%s,%s);ret(%s)", uuid, called_disp, dnis, fs_resp, isAsync ? "async" : "sync"); } } FUNC_END(); }
int32_t fs_opr_t::send_dtmf(const char* uuid, const char* keys) { FUNC_BEGIN(); (void)szcmd; //snprintf(szcmd,LEN_512,CMD_UUIDSENDDTMF_FMT,uuid,keys); //TRACE_LOG("send_dtmf(%s)",szcmd); //if(esl_send_recv(&_handle,szcmd)==ESL_SUCCESS){ if (esl_execute(&_handle, "send_dtmf", keys, uuid) == ESL_SUCCESS && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; } else { WARNING_LOG("fs:send_dtmf(%s,%s);ret(%s)", uuid, keys, fs_resp); } FUNC_END(); }
//============================ // MotorTestMultiple // // Test every motor connected on // startPort to (startPort + numMotors - 1) //============================ void MotorTestMultiple( int startPort, int numMotors, int motorSpeed, float waitTime ) { int i; FUNC_BEGIN("MotorTestMultiple"); if (waitTime < 1) printf("WARNING: waitTime is lower than 1 second: %f\n", waitTime); for (i = 0; i < numMotors; i++) Motor(startPort + i, motorSpeed); wait( waitTime ); for (i = 0; i < numMotors; i++) Motor(startPort + i, MOTOR_OFF); FUNC_END("MotorTestMultiple"); }
int32_t fs_opr_t::join_conference(const char* name, const char* dest_disp, const char* destno, CONF_MODE mode, uint64_t sessionid) { FUNC_BEGIN(); snprintf(szcmd, LEN_512, CMD_JOINCONFERENCE_FMT, dest_disp, dest_disp, sessionid, destno, name, ((CONF_LISTEN == mode) ? "+flags{mute}" : "")); TRACE_LOG("join_conference(%s)", szcmd); if (esl_send_recv(&_handle, szcmd) == ESL_SUCCESS) { if (is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; } else { WARNING_LOG("fs:join_conference(%s,%s,%s,%u,%lu);ret(%s)", name, dest_disp, destno, mode, sessionid, fs_resp); } } FUNC_END(); }
int32_t fs_opr_t::unjoin_conference(const char* name, const char* uuid) { FUNC_BEGIN(); snprintf(szcmd, LEN_512, "api uuid_transfer %s -aleg 'set:hangup_after_bridge=false,set:park_after_bridge=true,park:' inline \n\n", uuid); TRACE_LOG("unjoin_conference(%s)", szcmd); if (esl_send_recv(&_handle, szcmd) == ESL_SUCCESS) { if (is_result_ok(fs_resp = esl_event_get_body(_handle.last_sr_event))) { ret = IMS_SUCCESS; } else { WARNING_LOG("fs:unjoin_conference(%s,%s);ret(%s)", name, uuid, fs_resp); } } FUNC_END(); }