Browse Source

modules/sca: track appearance times.

Include time of last state chance in sca.all_appearances output.
Andrew Mortensen 12 years ago
parent
commit
002dc46fee
4 changed files with 38 additions and 9 deletions
  1. 16 5
      modules/sca/sca_appearance.c
  2. 14 0
      modules/sca/sca_appearance.h
  3. 6 3
      modules/sca/sca_call_info.c
  4. 2 1
      modules/sca/sca_rpc.c

+ 16 - 5
modules/sca/sca_appearance.c

@@ -119,7 +119,9 @@ sca_appearance_create( int appearance_index, str *owner_uri )
     SCA_STR_COPY( &new_appearance->owner, owner_uri );
 
     new_appearance->index = appearance_index;
-    new_appearance->state = SCA_APPEARANCE_STATE_IDLE;
+    new_appearance->times.ctime = time( NULL );
+    sca_appearance_update_state_unsafe( new_appearance,
+				SCA_APPEARANCE_STATE_IDLE );
     new_appearance->next = NULL;
 
     return( new_appearance );
@@ -386,7 +388,7 @@ sca_appearance_seize_index_unsafe( sca_mod *scam, str *aor, str *owner_uri,
 	error = SCA_APPEARANCE_ERR_MALLOC;
         goto done;
     }
-    app->state = SCA_APPEARANCE_STATE_SEIZED;
+    sca_appearance_update_state_unsafe( app, SCA_APPEARANCE_STATE_SEIZED );
 
     sca_appearance_list_insert_appearance( app_list, app );
 
@@ -464,7 +466,7 @@ sca_appearance_seize_next_available_unsafe( sca_mod *scam, str *aor,
 		STR_FMT( owner_uri ), idx );
 	goto done;
     }
-    app->state = SCA_APPEARANCE_STATE_SEIZED;
+    sca_appearance_update_state_unsafe( app, SCA_APPEARANCE_STATE_SEIZED );
 
     sca_appearance_list_insert_appearance( app_list, app );
 
@@ -494,6 +496,15 @@ sca_appearance_seize_next_available_index( sca_mod *scam, str *aor,
     return( idx );
 }
 
+    void
+sca_appearance_update_state_unsafe( sca_appearance *app, int state )
+{
+    assert( app != NULL );
+
+    app->state = state;
+    app->times.mtime = time( NULL );
+}
+
     int
 sca_appearance_update_owner_unsafe( sca_appearance *app, str *owner )
 {
@@ -638,7 +649,7 @@ sca_appearance_update_unsafe( sca_appearance *app, int state, str *display,
     int			len;
 
     if ( state != SCA_APPEARANCE_STATE_UNKNOWN ) {
-	app->state = state;
+	sca_appearance_update_state_unsafe( app, state );
     }
 
     if ( !SCA_STR_EMPTY( uri )) {
@@ -911,7 +922,7 @@ sca_appearance_update_index( sca_mod *scam, str *aor, int idx,
     }
 
     if ( state != SCA_APPEARANCE_STATE_UNKNOWN && app->state != state ) {
-	app->state = state;
+	sca_appearance_update_state_unsafe( app, state );
     }
 
     if ( !SCA_STR_EMPTY( uri )) {

+ 14 - 0
modules/sca/sca_appearance.h

@@ -72,6 +72,18 @@ extern const str SCA_APPEARANCE_STATE_STR_HELD;
 extern const str SCA_APPEARANCE_STATE_STR_HELD_PRIVATE;
 
 
+struct _sca_appearance_times {
+    /* time of appearance creation */
+    time_t			ctime;
+
+    /* time of last appearance state change */
+    time_t			mtime;
+
+    /* time of last end-to-end activity */
+    time_t			atime;
+};
+typedef struct _sca_appearance_times	sca_appearance_times;
+
 struct _sca_appearance_list;
 struct _sca_appearance {
     int				index;
@@ -83,6 +95,7 @@ struct _sca_appearance {
     str				owner;
     str				callee;
     sca_dialog			dialog;
+    sca_appearance_times	times;
 
     str				prev_owner;
     str				prev_callee;
@@ -109,6 +122,7 @@ int	sca_appearance_seize_index( sca_mod *, str *, int, str * );
 int	sca_appearance_seize_next_available_index( sca_mod *, str *, str * );
 sca_appearance 	*sca_appearance_seize_next_available_unsafe( sca_mod *, str *,
 							     str *, int );
+void	sca_appearance_update_state_unsafe( sca_appearance *, int );
 int	sca_appearance_update_owner_unsafe( sca_appearance *, str * );
 int	sca_appearance_update_callee_unsafe( sca_appearance *, str * );
 int	sca_appearance_update_dialog_unsafe( sca_appearance *, str *,

+ 6 - 3
modules/sca/sca_call_info.c

@@ -695,7 +695,7 @@ sca_call_info_seize_held_call( sip_msg_t *msg, sca_call_info *call_info,
     }
 
     app->flags |= SCA_APPEARANCE_FLAG_OWNER_PENDING;
-    app->state = SCA_APPEARANCE_STATE_ACTIVE;
+    sca_appearance_update_state_unsafe( app, SCA_APPEARANCE_STATE_ACTIVE );
 
     sca_hash_table_unlock_index( sca->appearances, slot_idx );
     slot_idx = -1;
@@ -1105,7 +1105,9 @@ sca_call_info_invite_reply_18x_handler( sip_msg_t *msg,
     SCA_STR_COPY( &owner, &app->owner );
 
     notify = ( app->state != state );
-    app->state = state;
+    if ( notify ) {
+	sca_appearance_update_state_unsafe( app, state );
+    }
     rc = 1;
 
 done:
@@ -1415,7 +1417,8 @@ sca_call_info_ack_from_handler( sip_msg_t *msg, str *from_aor, str *to_aor )
 	 * as necessary.
 	 */
 	if ( sca_call_is_held( msg )) {
-	    app->state = state = SCA_APPEARANCE_STATE_HELD;
+	    state = SCA_APPEARANCE_STATE_HELD;
+	    sca_appearance_update_state_unsafe( app, state );
 
 	    /* can't send NOTIFYs until we unlock the slot below */
 	}

+ 2 - 1
modules/sca/sca_rpc.c

@@ -358,10 +358,11 @@ sca_rpc_show_all_appearances( rpc_t *rpc, void *ctx )
 	    app_list = (sca_appearance_list *)ent->value;
 	    for ( app = app_list->appearances; app != NULL; app = app->next ) {
 		sca_appearance_state_to_str( app->state, &state_str );
-		rc = rpc->printf( ctx, "%d: %.*s %d %.*s %.*s %.*s %.*s", i,
+		rc = rpc->printf( ctx, "%.*s %d %.*s %ld %.*s %.*s %.*s",
 				STR_FMT( &app_list->aor ),
 				app->index,
 				STR_FMT( &state_str ),
+				(long)app->times.mtime,
 				STR_FMT( &app->owner ),
 				STR_FMT( &app->callee ),
 				STR_FMT( &app->dialog.id ));