Changeset 3339 for pjproject/trunk


Ignore:
Timestamp:
Oct 12, 2010 12:45:15 PM (14 years ago)
Author:
bennylp
Message:

Closed #1144: New presence callback to report subscription state (thanks Johan Lantz for the suggestion):

  • added on_buddy_evsub_state() callback
  • added sample implementation in pjsua_app.c
Location:
pjproject/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c

    r3323 r3339  
    27982798 
    27992799 
     2800/* 
     2801 * Subscription state has changed. 
     2802 */ 
     2803static void on_buddy_evsub_state(pjsua_buddy_id buddy_id, 
     2804                                 pjsip_evsub *sub, 
     2805                                 pjsip_event *event) 
     2806{ 
     2807    char event_info[80]; 
     2808 
     2809    PJ_UNUSED_ARG(sub); 
     2810 
     2811    event_info[0] = '\0'; 
     2812 
     2813    if (event->type == PJSIP_EVENT_TSX_STATE && 
     2814            event->body.tsx_state.type == PJSIP_EVENT_RX_MSG) 
     2815    { 
     2816        pjsip_rx_data *rdata = event->body.tsx_state.src.rdata; 
     2817        snprintf(event_info, sizeof(event_info), 
     2818                 " (RX %s)", 
     2819                 pjsip_rx_data_get_info(rdata)); 
     2820    } 
     2821 
     2822    PJ_LOG(4,(THIS_FILE, 
     2823              "Buddy %d: subscription state: %s (event: %s%s)", 
     2824              buddy_id, pjsip_evsub_get_state_name(sub), 
     2825              pjsip_event_str(event->type), 
     2826              event_info)); 
     2827 
     2828} 
     2829 
     2830 
    28002831/** 
    28012832 * Incoming IM message (i.e. MESSAGE request)! 
     
    46034634    app_config.cfg.cb.on_incoming_subscribe = &on_incoming_subscribe; 
    46044635    app_config.cfg.cb.on_buddy_state = &on_buddy_state; 
     4636    app_config.cfg.cb.on_buddy_evsub_state = &on_buddy_evsub_state; 
    46054637    app_config.cfg.cb.on_pager = &on_pager; 
    46064638    app_config.cfg.cb.on_typing = &on_typing; 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r3330 r3339  
    687687     */ 
    688688    void (*on_buddy_state)(pjsua_buddy_id buddy_id); 
     689 
     690 
     691    /** 
     692     * Notify application when the state of client subscription session 
     693     * associated with a buddy has changed. Application may use this 
     694     * callback to retrieve more detailed information about the state 
     695     * changed event. 
     696     * 
     697     * @param buddy_id      The buddy id. 
     698     * @param sub           Event subscription session. 
     699     * @param event         The event which triggers state change event. 
     700     */ 
     701    void (*on_buddy_evsub_state)(pjsua_buddy_id buddy_id, 
     702                                 pjsip_evsub *sub, 
     703                                 pjsip_event *event); 
    689704 
    690705    /** 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c

    r3190 r3339  
    15581558        } 
    15591559 
    1560         /* Call callback */ 
     1560        /* Call callbacks */ 
     1561        if (pjsua_var.ua_cfg.cb.on_buddy_evsub_state) 
     1562            (*pjsua_var.ua_cfg.cb.on_buddy_evsub_state)(buddy->index, sub, 
     1563                                                        event); 
     1564 
    15611565        if (pjsua_var.ua_cfg.cb.on_buddy_state) 
    15621566            (*pjsua_var.ua_cfg.cb.on_buddy_state)(buddy->index); 
     
    16571661 
    16581662 
    1659 /* Event subscription callback. */ 
    1660 static pjsip_evsub_user pres_callback =  
    1661 { 
    1662     &pjsua_evsub_on_state,   
    1663     &pjsua_evsub_on_tsx_state, 
    1664  
    1665     NULL,   /* on_rx_refresh: don't care about SUBSCRIBE refresh, unless  
    1666              * we want to authenticate  
    1667              */ 
    1668  
    1669     &pjsua_evsub_on_rx_notify, 
    1670  
    1671     NULL,   /* on_client_refresh: Use default behaviour, which is to  
    1672              * refresh client subscription. */ 
    1673  
    1674     NULL,   /* on_server_timeout: Use default behaviour, which is to send  
    1675              * NOTIFY to terminate.  
    1676              */ 
    1677 }; 
    1678  
    1679  
    16801663/* It does what it says.. */ 
    16811664static void subscribe_buddy_presence(pjsua_buddy_id buddy_id) 
    16821665{ 
     1666    pjsip_evsub_user pres_callback; 
    16831667    pj_pool_t *tmp_pool = NULL; 
    16841668    pjsua_buddy *buddy; 
     
    16881672    pjsip_tx_data *tdata; 
    16891673    pj_status_t status; 
     1674 
     1675    /* Event subscription callback. */ 
     1676    pj_bzero(&pres_callback, sizeof(pres_callback)); 
     1677    pres_callback.on_evsub_state = &pjsua_evsub_on_state; 
     1678    pres_callback.on_tsx_state = &pjsua_evsub_on_tsx_state; 
     1679    pres_callback.on_rx_notify = &pjsua_evsub_on_rx_notify; 
    16901680 
    16911681    buddy = &pjsua_var.buddy[buddy_id]; 
Note: See TracChangeset for help on using the changeset viewer.