# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import e32
import appuifw
import time
import thread

from pdis.lib.logging import *
from aosocket.MtFileLogger import *
init_logging(MtFileLogger("aosocket", "testapp"))


def tell(string):
    logwrite(string)
    if e32.is_ui_thread():
        print string
        e32.ao_yield()


# setup Exit key handler
old_title = appuifw.app.title
appuifw.app.title = u"TestApp"

# --------------------------------------------------------------------
"""
This program crashes if we use the logging routines.
Otherwise it does not. It may be that some file-related
resources do not get cleaned up if we do use logging
in a thread other than the main thread. This makes
it rather difficult for us to know what is going on
in threads other than the main thread, but we can
let things crash during development, and then when
things would seem to be working, disable logging.
"""

try:
    #raise Exception
    from pdis.lib.logging import *
    from aosocket.MtFileLogger import *
    init_logging(MtFileLogger("c:\\logs\\aosocket\\testapp"))
except:

    def logwrite(string):
        pass

    def log_exception():
        pass

    def finish_logging():
        pass


def tell(string):
    logwrite(string)
    if e32.is_ui_thread():