Changeset 4284 for pjproject


Ignore:
Timestamp:
Oct 18, 2012 8:36:13 AM (12 years ago)
Author:
ming
Message:

Re #1546: Fixed race condition in text i/o thread for apjsua

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/android/pjsip-apps/src/apjsua/src/org/pjsip/pjsua/ApjsuaActivity.java

    r4194 r4284  
    2222/* This class is for running pjsua in a secondary thread. */ 
    2323class PjsuaThread extends Thread { 
    24         public static Boolean finished; 
     24        public enum PjsuaState { 
     25                NULL, INITED, TERMINATED 
     26        }; 
     27        public static PjsuaState state; 
    2528         
    2629        public void run() { 
    27                 if (pjsua_app.initApp() != 0) 
    28                 return; 
     30                if (pjsua_app.initApp() != 0) { 
     31                        state = PjsuaState.TERMINATED; 
     32                        return; 
     33                } 
     34                state = PjsuaState.INITED; 
    2935                 
    3036        pjsua_app.startPjsua(ApjsuaActivity.CFG_FNAME); 
    31         finished = true; 
     37        state = PjsuaState.TERMINATED; 
     38         
     39        try { 
     40                Thread.sleep(200); 
     41        } catch(Exception e) { 
     42        } 
    3243        pjsua_app.deinitApp(); 
    3344        } 
     
    4253         
    4354        protected Void doInBackground(Void... args) { 
    44                 while (!PjsuaThread.finished) { 
    45                         publishProgress(pjsua_app.getMessage()); 
     55                while (PjsuaThread.state != PjsuaThread.PjsuaState.TERMINATED) { 
     56                        if (PjsuaThread.state == PjsuaThread.PjsuaState.INITED) 
     57                                publishProgress(pjsua_app.getMessage()); 
    4658                } 
    4759                return null; 
     
    116128                                (keyCode == KeyEvent.KEYCODE_ENTER)) 
    117129                        { 
    118                                 pjsua_app.setInput(cmd.getText().toString()); 
     130                                if (PjsuaThread.state == PjsuaThread.PjsuaState.INITED) 
     131                                        pjsua_app.setInput(cmd.getText().toString()); 
    119132                                cmd.setText(""); 
    120133                                return true; 
     
    136149         
    137150        /* Create pjsua and output thread */ 
    138         PjsuaThread.finished = false; 
     151        PjsuaThread.state = PjsuaThread.PjsuaState.NULL; 
    139152        TextOutTask outTask = new TextOutTask(); 
    140153        outTask.tv = tv; 
Note: See TracChangeset for help on using the changeset viewer.