Ignore:
Timestamp:
Oct 23, 2013 5:34:48 AM (10 years ago)
Author:
bennylp
Message:

More re #1519:

  • account API implementation (incomplete, callback is still not called)
  • using callback class design pattern (observer?)
  • after this, it might be changed to use inheritance pattern instead
Location:
pjproject/branches/projects/pjsua2
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/pjsua2/build.mak.in

    r3999 r4631  
    123123        $(PJ_VIDEO_LDFLAGS) \ 
    124124        @LDFLAGS@ 
    125 export APP_LDLIBS := -lpjsua-$(TARGET_NAME)\ 
     125#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x 
     126# 
     127# FIX THIS 
     128# 
     129# pjsua2 is c++ library hence maybe needs to be put in separate 
     130# variables. it will also require -lstdc++ 
     131#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x 
     132export APP_LDLIBS := \  
     133        -lpjsua2-$(TARGET_NAME)\ 
     134        -lpjsua-$(TARGET_NAME)\ 
    126135        -lpjsip-ua-$(TARGET_NAME)\ 
    127136        -lpjsip-simple-$(TARGET_NAME)\ 
     
    137146        -lpj-$(TARGET_NAME)\ 
    138147        @LIBS@ 
    139 export APP_LIB_FILES = $(PJ_DIR)/pjsip/lib/libpjsua-$(LIB_SUFFIX) \ 
     148#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x 
     149# 
     150# FIX THIS 
     151# 
     152# pjsua2 is c++ library hence maybe needs to be put in separate 
     153# variables. it will also require -lstdc++ 
     154#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x 
     155export APP_LIB_FILES = \  
     156        $(PJ_DIR)/pjsip/lib/libpjsua2-$(LIB_SUFFIX) \ 
     157        $(PJ_DIR)/pjsip/lib/libpjsua-$(LIB_SUFFIX) \ 
    140158        $(PJ_DIR)/pjsip/lib/libpjsip-ua-$(LIB_SUFFIX) \ 
    141159        $(PJ_DIR)/pjsip/lib/libpjsip-simple-$(LIB_SUFFIX) \ 
  • pjproject/branches/projects/pjsua2/pjsip-apps/build/Makefile

    r4597 r4631  
    5757# 
    5858# 
     59 
     60#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x 
     61# 
     62#                FIX THIS 
     63# 
     64#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x 
    5965#TARGETS := swig pjsua pjsystest samples 
    60 TARGETS := swig 
     66TARGETS := swig samples 
    6167 
    6268.PHONY: $(TARGETS) 
  • pjproject/branches/projects/pjsua2/pjsip-apps/build/Samples.mak

    r4440 r4631  
    2929           pjsip-perf \ 
    3030           pcaputil \ 
     31           pjsua2_demo \ 
    3132           playfile \ 
    3233           playsine \ 
     
    4647           vid_streamutil 
    4748 
     49#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x 
     50# 
     51# FIX THIS 
     52# 
     53# Only pjsua2_demo is built, and also -lstdc++ is added for all 
     54# samples 
     55#  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x  x   x  x  x  x  x 
     56SAMPLES := pjsua2_demo 
     57 
    4858EXES := $(foreach file, $(SAMPLES), $(BINDIR)/$(file)$(HOST_EXE)) 
    4959 
    5060all: $(BINDIR) $(OBJDIR) $(EXES) 
    5161 
    52 $(BINDIR)/%$(HOST_EXE): $(OBJDIR)/%$(OBJEXT) $(PJ_LIB_FILES) 
     62$(BINDIR)/%$(HOST_EXE): $(OBJDIR)/%$(OBJEXT) $(PJ_LIB_FILES)  
    5363        $(LD) $(LDOUT)$(subst /,$(HOST_PSEP),$@) \ 
    5464            $(subst /,$(HOST_PSEP),$<) \ 
    55             $(_LDFLAGS) 
     65             $(_LDFLAGS) -lstdc++ 
    5666 
    5767$(OBJDIR)/%$(OBJEXT): $(SRCDIR)/%.c 
     68        $(CC) $(_CFLAGS) \ 
     69          $(CC_OUT)$(subst /,$(HOST_PSEP),$@) \ 
     70          $(subst /,$(HOST_PSEP),$<)  
     71 
     72$(OBJDIR)/%$(OBJEXT): $(SRCDIR)/%.cpp 
    5873        $(CC) $(_CFLAGS) \ 
    5974          $(CC_OUT)$(subst /,$(HOST_PSEP),$@) \ 
  • pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/account.hpp

    r4608 r4631  
    799799}; 
    800800 
     801 
    801802/** 
    802803 * Account information. Application can query the account information 
     
    824825     * (reg_uri is not empty). 
    825826     */ 
    826     bool                hasRegistration; 
     827    bool                regIsConfigured; 
    827828 
    828829    /** 
     
    830831     * (has active registration session). 
    831832     */ 
    832     bool                isRegistered; 
     833    bool                regIsActive; 
    833834 
    834835    /** 
    835836     * An up to date expiration interval for account registration session. 
    836837     */ 
    837     int                 expiresSec; 
     838    int                 regExpiresSec; 
    838839 
    839840    /** 
     
    842843     * status code of the registration. 
    843844     */ 
    844     pjsip_status_code   status; 
     845    pjsip_status_code   regStatus; 
    845846 
    846847    /** 
    847848     * String describing the registration status. 
    848849     */ 
    849     string              statusText; 
     850    string              regStatusText; 
    850851 
    851852    /** 
     
    867868    string              onlineStatusText; 
    868869 
     870public: 
     871    void fromPj(const pjsua_acc_info &pai); 
    869872}; 
    870873 
     
    909912     * SIP status code received. 
    910913     */ 
    911     int                 code; 
     914    pjsip_status_code   code; 
    912915 
    913916    /** 
     
    10901093    /** Virtual destructor */ 
    10911094    virtual ~AccountCallback() {} 
     1095 
     1096    /** 
     1097     * Get the account associated with this callback. 
     1098     */ 
     1099    Account *account() 
     1100    { return acc; } 
    10921101 
    10931102    /** 
     
    11911200    virtual void onMwiInfo(OnMwiInfoParam &prm) 
    11921201    {} 
     1202 
     1203protected: 
     1204    AccountCallback() 
     1205    : acc(NULL) 
     1206    {} 
     1207 
     1208private: 
     1209    Account *acc; 
     1210 
     1211    /** Set the account. Must only be called by Account class */ 
     1212    void setAccount(Account *the_acc) 
     1213    { acc = the_acc; } 
     1214 
     1215    friend class Account; 
    11931216}; 
    11941217 
     
    12101233{ 
    12111234public: 
     1235    /** 
     1236     * Constructor. 
     1237     */ 
     1238    Account(AccountCallback *cb, Token user_data); 
     1239 
     1240    /** 
     1241     * Destructor. 
     1242     */ 
     1243    ~Account(); 
     1244 
     1245    /** 
     1246     * Create the account. 
     1247     * 
     1248     * @param cfg               The account config. 
     1249     * @param make_default      Make this the default account. 
     1250     */ 
     1251    void create(const AccountConfig &cfg, 
     1252                bool make_default=false) throw(Error); 
     1253 
     1254    /** 
     1255     * Modify the account to use the specified account configuration. 
     1256     * Depending on the changes, this may cause unregistration or 
     1257     * reregistration on the account. 
     1258     * 
     1259     * @param cfg               New account config to be applied to the account. 
     1260     */ 
     1261    void modify(const AccountConfig &acc) throw(Error); 
     1262 
    12121263    /** 
    12131264     * Check if this account is still valid. 
     
    12601311     * @return                  Account info. 
    12611312     */ 
    1262     AccountInfo getInfo() const; 
    1263  
    1264     /** 
    1265      * Modify the account to use the specified account configuration. 
    1266      * Depending on the changes, this may cause unregistration or 
    1267      * reregistration on the account. 
    1268      * 
    1269      * @param cfg               New account config to be applied to the account. 
    1270      */ 
    1271     void modify(const AccountConfig &acc) throw(Error); 
     1313    AccountInfo getInfo() const throw(Error); 
    12721314 
    12731315    /** 
     
    13111353    friend class Endpoint; 
    13121354 
    1313     Account(); 
     1355private: 
     1356    pjsua_acc_id         id; 
     1357    AccountCallback     *cb; 
     1358    Token                userData; 
    13141359}; 
    13151360 
  • pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/types.hpp

    r4608 r4631  
    7070typedef void *TransportHandle; 
    7171 
     72/* 
     73 * Forward declaration of Account, AccountCallback, AccountConfig, to be used 
     74 * by Endpoint. 
     75 */ 
     76class Account; 
     77class AccountCallback; 
     78class AccountConfig; 
     79 
    7280 
    7381/** 
     
    105113    /** The line number of PJSUA source file that throws the error */ 
    106114    int         srcLine; 
     115 
     116    /** Build error string. */ 
     117    string      info(bool multi_line=false) const; 
    107118 
    108119    /** Default constructor */ 
     
    156167        PJSUA2_CHECK_RAISE_ERROR2(status, "") 
    157168 
     169#define PJSUA2_CHECK_EXPR(expr)                 \ 
     170        do { \ 
     171            pj_status_t the_status = expr;      \ 
     172            PJSUA2_CHECK_RAISE_ERROR2(the_status, #expr); \ 
     173        } while (0) 
    158174 
    159175////////////////////////////////////////////////////////////////////////////// 
     
    166182{ 
    167183    /** 
     184     * The authentication scheme (e.g. "digest"). 
     185     */ 
     186    string      scheme; 
     187 
     188    /** 
    168189     * Realm on which this credential is to be used. Use "*" to make 
    169190     * a credential that can be used to authenticate against any challenges. 
    170191     */ 
    171192    string      realm; 
    172  
    173     /** 
    174      * The authentication scheme (e.g. "digest"). 
    175      */ 
    176     string      scheme; 
    177193 
    178194    /** 
     
    208224    string      akaAmf; 
    209225 
     226    /** Default constructor */ 
     227    AuthCredInfo(); 
     228 
     229    /** Construct a credential with the specified parameters */ 
     230    AuthCredInfo(const string &scheme, 
     231                 const string &realm, 
     232                 const string &user_name, 
     233                 const int data_type, 
     234                 const string data); 
    210235}; 
    211236 
  • pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/account.cpp

    r4608 r4631  
    1818 */ 
    1919#include <pjsua2/account.hpp> 
     20#include <pjsua2/endpoint.hpp> 
    2021#include <pj/ctype.h> 
    2122#include "util.hpp" 
     
    330331} 
    331332 
    332  
     333/////////////////////////////////////////////////////////////////////////////// 
     334 
     335void AccountInfo::fromPj(const pjsua_acc_info &pai) 
     336{ 
     337    id                  = pai.id; 
     338    isDefault           = pai.is_default != 0; 
     339    uri                 = pj2Str(pai.acc_uri); 
     340    regIsConfigured     = pai.has_registration != 0; 
     341    regIsActive         = pai.has_registration && pai.expires > 0 && 
     342                            (pai.status / 100 == 2); 
     343    regExpiresSec       = pai.expires; 
     344    regStatus           = pai.status; 
     345    regStatusText       = pj2Str(pai.status_text); 
     346    regLastErr          = pai.reg_last_err; 
     347    onlineStatus        = pai.online_status != 0; 
     348    onlineStatusText    = pj2Str(pai.online_status_text); 
     349} 
     350 
     351/////////////////////////////////////////////////////////////////////////////// 
     352 
     353Account::Account(AccountCallback *param_cb, Token user_data) 
     354: id(PJSUA_INVALID_ID), cb(param_cb), userData(user_data) 
     355{ 
     356    cb->setAccount(this); 
     357} 
     358 
     359Account::~Account() 
     360{ 
     361    delete cb; 
     362} 
     363 
     364void Account::create(const AccountConfig &acc_cfg, 
     365                     bool make_default) throw(Error) 
     366{ 
     367    pjsua_acc_config pj_acc_cfg = acc_cfg.toPj(); 
     368 
     369    PJSUA2_CHECK_EXPR( pjsua_acc_add(&pj_acc_cfg, make_default, &id) ); 
     370} 
     371 
     372void Account::modify(const AccountConfig &acc_cfg) throw(Error) 
     373{ 
     374    pjsua_acc_config pj_acc_cfg = acc_cfg.toPj(); 
     375 
     376    PJSUA2_CHECK_EXPR( pjsua_acc_modify(id, &pj_acc_cfg) ); 
     377} 
     378 
     379bool Account::isValid() const 
     380{ 
     381    return pjsua_acc_is_valid(id) != 0; 
     382} 
     383 
     384void Account::setDefault() throw(Error) 
     385{ 
     386    PJSUA2_CHECK_EXPR( pjsua_acc_set_default(id) ); 
     387} 
     388 
     389bool Account::isDefault() const 
     390{ 
     391    return pjsua_acc_get_default() == id; 
     392} 
     393 
     394int Account::getIndex() const 
     395{ 
     396    return id; 
     397} 
     398 
     399void Account::setUserData(Token user_data) 
     400{ 
     401    userData = user_data; 
     402} 
     403 
     404Token Account::getUserData() const 
     405{ 
     406    return userData; 
     407} 
     408 
     409AccountInfo Account::getInfo() const throw(Error) 
     410{ 
     411    pjsua_acc_info pj_ai; 
     412    AccountInfo ai; 
     413 
     414    PJSUA2_CHECK_EXPR( pjsua_acc_get_info(id, &pj_ai) ); 
     415    ai.fromPj(pj_ai); 
     416    return ai; 
     417} 
     418 
     419void Account::setRegistration(bool renew) throw(Error) 
     420{ 
     421    PJSUA2_CHECK_EXPR( pjsua_acc_set_registration(id, renew) ); 
     422} 
     423 
     424void 
     425Account::setOnlineStatus(const AccountPresenceStatus &pres_st) throw(Error) 
     426{ 
     427    pjrpid_element pj_rpid; 
     428 
     429    pj_bzero(&pj_rpid, sizeof(pj_rpid)); 
     430    pj_rpid.type        = PJRPID_ELEMENT_TYPE_PERSON; 
     431    pj_rpid.activity    = pres_st.activity; 
     432    pj_rpid.id          = str2Pj(pres_st.rpidId); 
     433    pj_rpid.note        = str2Pj(pres_st.note); 
     434 
     435    PJSUA2_CHECK_EXPR( pjsua_acc_set_online_status2(id, pres_st.isOnline, 
     436                                                    &pj_rpid) ); 
     437} 
     438 
     439void Account::setTransport(TransportId tp_id) throw(Error) 
     440{ 
     441    PJSUA2_CHECK_EXPR( pjsua_acc_set_transport(id, tp_id) ); 
     442} 
     443 
  • pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/endpoint.cpp

    r4608 r4631  
    384384} 
    385385 
    386  
    387386/////////////////////////////////////////////////////////////////////////////// 
    388387/* 
     
    589588} 
    590589 
     590/////////////////////////////////////////////////////////////////////////////// 
     591 
  • pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/types.cpp

    r4608 r4631  
    4545} 
    4646 
     47string Error::info(bool multi_line) const 
     48{ 
     49    string output; 
     50 
     51    if (status==PJ_SUCCESS) { 
     52        output = "No error"; 
     53    } else if (!multi_line) { 
     54        char temp[80]; 
     55 
     56        if (!title.empty()) { 
     57            output += title + " error: "; 
     58        } 
     59        snprintf(temp, sizeof(temp), " (status=%d)", status); 
     60        output += reason + temp; 
     61        if (!srcFile.empty()) { 
     62            output += " ["; 
     63            output += srcFile; 
     64            snprintf(temp, sizeof(temp), ":%d]", srcLine); 
     65            output += temp; 
     66        } 
     67    } else { 
     68        char temp[80]; 
     69 
     70        if (!title.empty()) { 
     71            output += string("Title:       ") + title + "\n"; 
     72        } 
     73 
     74        snprintf(temp, sizeof(temp), "%d\n", status); 
     75        output += string("Code:        ") + temp; 
     76        output += string("Description: ") + reason + "\n"; 
     77        if (!srcFile.empty()) { 
     78            snprintf(temp, sizeof(temp), ":%d\n", srcLine); 
     79            output += string("Location:    ") + srcFile + temp; 
     80        } 
     81    } 
     82 
     83    return output; 
     84} 
     85 
     86/////////////////////////////////////////////////////////////////////////////// 
     87 
     88AuthCredInfo::AuthCredInfo() 
     89: dataType(0) 
     90{ 
     91} 
     92 
     93AuthCredInfo::AuthCredInfo(const string &param_scheme, 
     94                           const string &param_realm, 
     95                           const string &param_user_name, 
     96                           const int param_data_type, 
     97                           const string param_data) 
     98: scheme(param_scheme), realm(param_realm), username(param_user_name), 
     99  dataType(param_data_type), data(param_data) 
     100{ 
     101} 
     102 
    47103 
    48104/////////////////////////////////////////////////////////////////////////////// 
Note: See TracChangeset for help on using the changeset viewer.