Changeset 3653


Ignore:
Timestamp:
Jul 15, 2011 6:37:07 AM (8 years ago)
Author:
bennylp
Message:

Re #1284 (event framework): unsubscribing does not need to know publisher

Location:
pjproject/branches/projects/2.0-dev/pjmedia
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/event.h

    r3642 r3653  
    261261    /** User data for this subscription */ 
    262262    void                *user_data; 
     263 
     264    /** Current publisher it is subscribed to */ 
     265    pjmedia_event_publisher *subscribe_to; 
    263266}; 
    264267 
     
    335338 
    336339/** 
    337  * Unsubscribe from the specified publisher. 
    338  * 
    339  * @param epub          The event publisher. 
     340 * Unsubscribe the specified subscription object from publisher it is 
     341 * currently subscribed to. If the subscription object is not currently 
     342 * subscribed to anything, the function will do nothing. 
     343 * 
    340344 * @param esub          The event subscription object, which must be the same 
    341345 *                      object that was given to #pjmedia_event_subscribe(). 
     
    343347 * @return              PJ_SUCCESS on success or the appropriate error code. 
    344348 */ 
    345 PJ_DECL(pj_status_t) pjmedia_event_unsubscribe(pjmedia_event_publisher *epub, 
    346                                                pjmedia_event_subscription *esub); 
     349PJ_DECL(pj_status_t) 
     350pjmedia_event_unsubscribe(pjmedia_event_subscription *esub); 
    347351 
    348352/** 
  • pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/event.c

    r3648 r3653  
    7474{ 
    7575    PJ_ASSERT_RETURN(epub && esub && esub->cb, PJ_EINVAL); 
     76    /* Must not currently subscribe to anything */ 
     77    PJ_ASSERT_RETURN(esub->subscribe_to == NULL, PJ_EINVALIDOP); 
     78 
    7679    pj_list_push_back(&epub->subscription_list, esub); 
     80    esub->subscribe_to = epub; 
    7781    return PJ_SUCCESS; 
    7882} 
    7983 
    80 PJ_DEF(pj_status_t) pjmedia_event_unsubscribe( pjmedia_event_publisher *epub, 
    81                                                pjmedia_event_subscription *esub) 
     84PJ_DEF(pj_status_t) pjmedia_event_unsubscribe(pjmedia_event_subscription *esub) 
    8285{ 
    83     PJ_ASSERT_RETURN(epub && esub, PJ_EINVAL); 
    84     PJ_ASSERT_RETURN(pj_list_find_node(&epub->subscription_list, esub)==esub, 
    85                      PJ_ENOTFOUND); 
    86     pj_list_erase(esub); 
     86    PJ_ASSERT_RETURN(esub, PJ_EINVAL); 
     87    if (esub->subscribe_to) { 
     88        PJ_ASSERT_RETURN( 
     89            pj_list_find_node(&esub->subscribe_to->subscription_list, 
     90                              esub)==esub, PJ_ENOTFOUND); 
     91        pj_list_erase(esub); 
     92        esub->subscribe_to = NULL; 
     93    } 
    8794    return PJ_SUCCESS; 
    8895} 
  • pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/vid_port.c

    r3640 r3653  
    439439 
    440440    if (vp->client_port) { 
    441         pjmedia_event_publisher *epub; 
    442  
    443         /* Unsubscribe event */ 
    444         epub = pjmedia_port_get_event_publisher(vp->client_port); 
    445         if (epub && vp->esub_client_port.user_data) { 
    446             pjmedia_event_unsubscribe(epub, &vp->esub_client_port); 
    447             pj_bzero(&vp->esub_client_port, sizeof(vp->esub_client_port)); 
    448         } 
     441        pjmedia_event_unsubscribe(&vp->esub_client_port); 
    449442        vp->client_port = NULL; 
    450443    } 
Note: See TracChangeset for help on using the changeset viewer.