mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-21 13:08:08 +00:00
New linphonec commands
git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@248 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
This commit is contained in:
parent
66e30529f7
commit
3db47f4720
6 changed files with 128 additions and 25 deletions
|
|
@ -46,6 +46,7 @@ static int lpc_cmd_help(LinphoneCore *, char *);
|
|||
static int lpc_cmd_proxy(LinphoneCore *, char *);
|
||||
static int lpc_cmd_call(LinphoneCore *, char *);
|
||||
static int lpc_cmd_answer(LinphoneCore *, char *);
|
||||
static int lpc_cmd_autoanswer(LinphoneCore *, char *);
|
||||
static int lpc_cmd_terminate(LinphoneCore *, char *);
|
||||
static int lpc_cmd_call_logs(LinphoneCore *, char *);
|
||||
static int lpc_cmd_ipv6(LinphoneCore *, char *);
|
||||
|
|
@ -61,6 +62,7 @@ static int lpc_cmd_record(LinphoneCore *, char *);
|
|||
static int lpc_cmd_register(LinphoneCore *, char *);
|
||||
static int lpc_cmd_unregister(LinphoneCore *, char *);
|
||||
static int lpc_cmd_duration(LinphoneCore *lc, char *args);
|
||||
static int lpc_cmd_status(LinphoneCore *lc, char *args);
|
||||
|
||||
/* Command handler helpers */
|
||||
static void linphonec_proxy_add(LinphoneCore *lc);
|
||||
|
|
@ -105,6 +107,9 @@ LPC_COMMAND commands[] = {
|
|||
{ "answer", lpc_cmd_answer, "Answer a call",
|
||||
"Accept an incoming call."
|
||||
},
|
||||
{ "autoanswer", lpc_cmd_autoanswer, "Enable auto-answer mode",
|
||||
"'autoanswer enable'\t: enable autoanswer mode\n"
|
||||
"'autoanswer disable'\t: disable autoanswer mode \n"},
|
||||
{ "proxy", lpc_cmd_proxy, "Manage proxies",
|
||||
"'proxy list' : list all proxy setups.\n"
|
||||
"'proxy add' : add a new proxy setup.\n"
|
||||
|
|
@ -165,6 +170,11 @@ LPC_COMMAND commands[] = {
|
|||
{ "register", lpc_cmd_register, "Register in one line to a proxy" , "register <sip identity> <sip proxy> <password>"},
|
||||
{ "unregister", lpc_cmd_unregister, "Unregister from default proxy", NULL },
|
||||
{ "duration", lpc_cmd_duration, "Print duration in seconds of the last call.", NULL },
|
||||
{ "status", lpc_cmd_status, "Print various status information",
|
||||
"'status register' \t: print status concerning registration\n"
|
||||
"'status autoanswer'\t: tell whether autoanswer mode is enabled\n"
|
||||
"'status hook' \t: print hook status\n" },
|
||||
|
||||
{ (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL }
|
||||
};
|
||||
|
||||
|
|
@ -306,6 +316,8 @@ lpc_cmd_help(LinphoneCore *lc, char *arg)
|
|||
|
||||
}
|
||||
|
||||
static char callee_name[256]={0};
|
||||
|
||||
static int
|
||||
lpc_cmd_call(LinphoneCore *lc, char *args)
|
||||
{
|
||||
|
|
@ -326,12 +338,16 @@ lpc_cmd_call(LinphoneCore *lc, char *args)
|
|||
}
|
||||
else
|
||||
{
|
||||
/* current_call=args; */
|
||||
snprintf(callee_name,sizeof(callee_name),"%s",args);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *linphonec_get_callee(){
|
||||
return callee_name;
|
||||
}
|
||||
|
||||
static int
|
||||
lpc_cmd_refer(LinphoneCore *lc, char *args)
|
||||
{
|
||||
|
|
@ -363,6 +379,17 @@ lpc_cmd_answer(LinphoneCore *lc, char *args)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
lpc_cmd_autoanswer(LinphoneCore *lc, char *args)
|
||||
{
|
||||
if (strstr(args,"enable")){
|
||||
linphonec_set_autoanswer(TRUE);
|
||||
}else if (strstr(args,"disable")){
|
||||
linphonec_set_autoanswer(FALSE);
|
||||
}else return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
lpc_cmd_quit(LinphoneCore *lc, char *args)
|
||||
{
|
||||
|
|
@ -1197,7 +1224,7 @@ static int lpc_cmd_unregister(LinphoneCore *lc, char *args){
|
|||
return 1;
|
||||
}
|
||||
|
||||
int lpc_cmd_duration(LinphoneCore *lc, char *args){
|
||||
static int lpc_cmd_duration(LinphoneCore *lc, char *args){
|
||||
LinphoneCallLog *cl;
|
||||
const MSList *elem=linphone_core_get_call_logs(lc);
|
||||
for(;elem!=NULL;elem=elem->next){
|
||||
|
|
@ -1209,6 +1236,50 @@ int lpc_cmd_duration(LinphoneCore *lc, char *args){
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int lpc_cmd_status(LinphoneCore *lc, char *args){
|
||||
LinphoneProxyConfig *cfg;
|
||||
linphone_core_get_default_proxy(lc,&cfg);
|
||||
if (strstr(args,"register")){
|
||||
if (cfg){
|
||||
if (linphone_proxy_config_is_registered(cfg)){
|
||||
linphonec_out("identity=%s duration=%s",
|
||||
linphone_proxy_config_get_identity(cfg),
|
||||
linphone_proxy_config_get_expires(cfg));
|
||||
}else if (linphone_proxy_config_register_enabled(cfg)){
|
||||
linphonec_out("registered=-1");
|
||||
}else linphonec_out("registered=0");
|
||||
}else linphonec_out("registered=0");
|
||||
}else if (strstr(args,"autoanswer")){
|
||||
if (cfg && linphone_proxy_config_is_registered(cfg))
|
||||
linphonec_out("autoanswer=%i",linphonec_get_autoanswer());
|
||||
else linphonec_out("unregistered");
|
||||
}else if (strstr(args,"hook")){
|
||||
gstate_t call_state=linphone_core_get_state(lc,GSTATE_GROUP_CALL);
|
||||
if (!cfg || !linphone_proxy_config_is_registered(cfg)){
|
||||
linphonec_out("unregistered");
|
||||
}
|
||||
switch(call_state){
|
||||
case GSTATE_CALL_OUT_INVITE:
|
||||
linphonec_out("hook=dialing");
|
||||
break;
|
||||
case GSTATE_CALL_IDLE:
|
||||
linphonec_out("hook=offhook");
|
||||
break;
|
||||
case GSTATE_CALL_OUT_CONNECTED:
|
||||
linphonec_out("hook=%s duration=%i", linphonec_get_callee(),
|
||||
linphone_core_get_current_call_duration(lc));
|
||||
break;
|
||||
case GSTATE_CALL_IN_CONNECTED:
|
||||
linphonec_out("hook=answered duration=%i" ,
|
||||
linphone_core_get_current_call_duration(lc));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}else return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* Command table management funx
|
||||
|
|
|
|||
|
|
@ -498,7 +498,13 @@ void linphonec_command_finished(void){
|
|||
}
|
||||
}
|
||||
|
||||
void linphonec_set_autoanswer(bool_t enabled){
|
||||
auto_answer=enabled;
|
||||
}
|
||||
|
||||
bool_t linphonec_get_autoanswer(){
|
||||
return auto_answer;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -102,6 +102,9 @@ extern int linphonec_parse_command_line(LinphoneCore *lc, char *cl);
|
|||
extern char *linphonec_command_generator(const char *text, int state);
|
||||
extern void linphonec_finish(int exit_status);
|
||||
extern char *linphonec_readline(char *prompt);
|
||||
void linphonec_set_autoanswer(bool_t enabled);
|
||||
bool_t linphonec_get_autoanswer();
|
||||
|
||||
|
||||
#endif /* def LINPHONEC_H */
|
||||
|
||||
|
|
|
|||
|
|
@ -25,9 +25,6 @@
|
|||
|
||||
#include "linphonecore.h"
|
||||
|
||||
|
||||
static gstate_t _gstates[GSTATE_GROUP_CALL+1];
|
||||
|
||||
#if 0
|
||||
static const char *_gstates_text[] = {
|
||||
"GSTATE_POWER_OFF", /* 0 */
|
||||
|
|
@ -52,18 +49,37 @@ static const char *_gstates_text[] = {
|
|||
#endif
|
||||
|
||||
/* set the initial states */
|
||||
void gstate_initialize(void) {
|
||||
_gstates[GSTATE_GROUP_POWER] = GSTATE_POWER_OFF;
|
||||
_gstates[GSTATE_GROUP_REG] = GSTATE_REG_NONE;
|
||||
_gstates[GSTATE_GROUP_CALL] = GSTATE_CALL_IDLE;
|
||||
void gstate_initialize(LinphoneCore *lc) {
|
||||
lc->gstate_power = GSTATE_POWER_OFF;
|
||||
lc->gstate_reg = GSTATE_REG_NONE;
|
||||
lc->gstate_call = GSTATE_CALL_IDLE;
|
||||
}
|
||||
|
||||
|
||||
/* retrieve the current state of the specified state group */
|
||||
gstate_t gstate_get_state(gstate_group_t group) {
|
||||
return _gstates[group];
|
||||
gstate_t linphone_core_get_state(const LinphoneCore *lc, gstate_group_t group){
|
||||
switch(group){
|
||||
case GSTATE_GROUP_POWER:
|
||||
return lc->gstate_power;
|
||||
case GSTATE_GROUP_REG:
|
||||
return lc->gstate_reg;
|
||||
case GSTATE_GROUP_CALL:
|
||||
return lc->gstate_call;
|
||||
}
|
||||
return GSTATE_INVALID;
|
||||
}
|
||||
|
||||
static void linphone_core_set_state(LinphoneCore *lc, gstate_group_t group, gstate_t new_state){
|
||||
switch(group){
|
||||
case GSTATE_GROUP_POWER:
|
||||
lc->gstate_power=new_state;
|
||||
break;
|
||||
case GSTATE_GROUP_REG:
|
||||
lc->gstate_reg=new_state;
|
||||
break;
|
||||
case GSTATE_GROUP_CALL:
|
||||
lc->gstate_call=new_state;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void gstate_new_state(struct _LinphoneCore *lc,
|
||||
gstate_t new_state,
|
||||
|
|
@ -80,15 +96,15 @@ void gstate_new_state(struct _LinphoneCore *lc,
|
|||
|
||||
/* store the new state while remembering the old one */
|
||||
states_arg.new_state = new_state;
|
||||
states_arg.old_state = _gstates[states_arg.group];
|
||||
_gstates[states_arg.group] = new_state;
|
||||
states_arg.old_state = linphone_core_get_state(lc,states_arg.group);
|
||||
linphone_core_set_state(lc, states_arg.group,new_state);
|
||||
states_arg.message = message;
|
||||
|
||||
/*printf("gstate_new_state: %s\t-> %s\t(%s)\n",
|
||||
_gstates_text[states_arg.old_state],
|
||||
_gstates_text[states_arg.new_state],
|
||||
message);*/
|
||||
|
||||
|
||||
/* call the virtual method */
|
||||
if (lc->vtable.general_state)
|
||||
lc->vtable.general_state(lc, &states_arg);
|
||||
|
|
|
|||
|
|
@ -244,6 +244,12 @@ void linphone_call_log_destroy(LinphoneCallLog *cl){
|
|||
ms_free(cl);
|
||||
}
|
||||
|
||||
int linphone_core_get_current_call_duration(const LinphoneCore *lc){
|
||||
LinphoneCall *call=lc->call;
|
||||
if (call==NULL) return 0;
|
||||
return time(NULL)-call->start_time;
|
||||
}
|
||||
|
||||
void _osip_trace_func(char *fi, int li, osip_trace_level_t level, char *chfr, va_list ap){
|
||||
int ortp_level=ORTP_DEBUG;
|
||||
switch(level){
|
||||
|
|
@ -640,7 +646,7 @@ void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, co
|
|||
|
||||
memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
|
||||
|
||||
gstate_initialize();
|
||||
gstate_initialize(lc);
|
||||
gstate_new_state(lc, GSTATE_POWER_STARTUP, NULL);
|
||||
|
||||
ortp_init();
|
||||
|
|
|
|||
|
|
@ -377,7 +377,8 @@ typedef enum _gstate {
|
|||
GSTATE_CALL_IN_INVITE,
|
||||
GSTATE_CALL_IN_CONNECTED,
|
||||
GSTATE_CALL_END,
|
||||
GSTATE_CALL_ERROR
|
||||
GSTATE_CALL_ERROR,
|
||||
GSTATE_INVALID
|
||||
} gstate_t;
|
||||
|
||||
struct _LinphoneGeneralState {
|
||||
|
|
@ -388,14 +389,10 @@ struct _LinphoneGeneralState {
|
|||
};
|
||||
typedef struct _LinphoneGeneralState LinphoneGeneralState;
|
||||
|
||||
/* retrieve the current state of the specified state group */
|
||||
gstate_t gstate_get_state(gstate_group_t group);
|
||||
|
||||
/* private: set the initial states */
|
||||
void gstate_initialize(void);
|
||||
|
||||
/* private: set a new state */
|
||||
void gstate_new_state(struct _LinphoneCore *lc, gstate_t new_state, const char *message);
|
||||
/*private*/
|
||||
void gstate_initialize(struct _LinphoneCore *lc) ;
|
||||
|
||||
typedef void (*ShowInterfaceCb)(struct _LinphoneCore *lc);
|
||||
typedef void (*InviteReceivedCb)(struct _LinphoneCore *lc, const char *from);
|
||||
|
|
@ -495,6 +492,9 @@ typedef struct _LinphoneCore
|
|||
int up_video_bw;
|
||||
int audio_bw;
|
||||
int automatic_action;
|
||||
gstate_t gstate_power;
|
||||
gstate_t gstate_reg;
|
||||
gstate_t gstate_call;
|
||||
bool_t use_files;
|
||||
bool_t apply_nat_settings;
|
||||
#ifdef VINCENT_MAURY_RSVP
|
||||
|
|
@ -717,7 +717,8 @@ void linphone_core_use_files(LinphoneCore *lc, bool_t yesno);
|
|||
void linphone_core_set_play_file(LinphoneCore *lc, const char *file);
|
||||
void linphone_core_set_record_file(LinphoneCore *lc, const char *file);
|
||||
|
||||
|
||||
gstate_t linphone_core_get_state(const LinphoneCore *lc, gstate_group_t group);
|
||||
int linphone_core_get_current_call_duration(const LinphoneCore *lc);
|
||||
|
||||
int linphone_core_get_mtu(const LinphoneCore *lc);
|
||||
void linphone_core_set_mtu(LinphoneCore *lc, int mtu);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue