summaryrefslogtreecommitdiff
path: root/pjlib/src/pjlib-test/main_symbian.cpp
blob: e57b080d50a01cb2b5bab7bb61b72613ceabdc64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//Auto-generated file. Please do not modify.
//#include <e32cmn.h>

//#pragma data_seg(".SYMBIAN")
//__EMULATOR_IMAGE_HEADER2 (0x1000007a,0x00000000,0x00000000,EPriorityForeground,0x00000000u,0x00000000u,0x00000000,0x00000000,0x00000000,0)
//#pragma data_seg()

#include "test.h"
#include <stdlib.h>
#include <pj/errno.h>
#include <pj/os.h>
#include <pj/log.h>
#include <pj/unicode.h>
#include <stdio.h>

#include <e32std.h>

#if 0
int main()
{
    int err = 0;
    int exp = 0;

    err = test_main();
    //err = test_main();

    if (err)
	return err;
    return exp;
    //return 0;
}

#else
#include <pj/os.h>

#include <e32base.h>
#include <e32std.h>
#include <e32cons.h>            // Console



//  Global Variables

LOCAL_D CConsoleBase* console;  // write all messages to this


//  Local Functions

LOCAL_C void MainL()
{
    //
    // add your program code here, example code below
    //
    test_main();

    console->Printf(_L(" [press any key]\n"));
    console->Getch();

    CActiveScheduler::Stop();
}

class MyScheduler : public CActiveScheduler
{
public:
    MyScheduler()
    {}

    void Error(TInt aError) const;
};

void MyScheduler::Error(TInt aError) const
{
    PJ_UNUSED_ARG(aError);
}

class ProgramStarter : public CActive
{
public:
    static ProgramStarter *NewL();
    void Start();

protected:
    ProgramStarter();
    void ConstructL();
    virtual void RunL();
    virtual void DoCancel();
    TInt RunError(TInt aError);

private:
    RTimer timer_;
};

ProgramStarter::ProgramStarter()
: CActive(EPriorityNormal)
{
}

void ProgramStarter::ConstructL()
{
    timer_.CreateLocal();
    CActiveScheduler::Add(this);
}

ProgramStarter *ProgramStarter::NewL()
{
    ProgramStarter *self = new (ELeave) ProgramStarter;
    CleanupStack::PushL(self);

    self->ConstructL();

    CleanupStack::Pop(self);
    return self;
}

void ProgramStarter::Start()
{
    timer_.After(iStatus, 0);
    SetActive();
}

void ProgramStarter::RunL()
{
    MainL();
}

void ProgramStarter::DoCancel()
{
}

TInt ProgramStarter::RunError(TInt aError)
{
    PJ_UNUSED_ARG(aError);
    return KErrNone;
}


LOCAL_C void DoStartL()
    {
    // Create active scheduler (to run active objects)
    CActiveScheduler* scheduler = new (ELeave) MyScheduler;
    CleanupStack::PushL(scheduler);
    CActiveScheduler::Install(scheduler);

    ProgramStarter *starter = ProgramStarter::NewL();
    starter->Start();

    CActiveScheduler::Start();
    }


//  Global Functions

static void log_writer(int level, const char *buf, int len)
{
    wchar_t buf16[PJ_LOG_MAX_SIZE];

    PJ_UNUSED_ARG(level);
    
    pj_ansi_to_unicode(buf, len, buf16, PJ_ARRAY_SIZE(buf16));

    TPtrC16 aBuf((const TUint16*)buf16, (TInt)len);
    console->Write(aBuf);
}


GLDEF_C TInt E32Main()
    {
    // Create cleanup stack
    __UHEAP_MARK;
    CTrapCleanup* cleanup = CTrapCleanup::New();

    // Create output console
    TRAPD(createError, console = Console::NewL(_L("Console"), TSize(KConsFullScreen,KConsFullScreen)));
    if (createError)
        return createError;

    pj_log_set_log_func(&log_writer);

    // Run application code inside TRAP harness, wait keypress when terminated
    TRAPD(mainError, DoStartL());
    if (mainError)
        console->Printf(_L(" failed, leave code = %d"), mainError);
    console->Printf(_L(" [press any key]\n"));
    console->Getch();
    
    delete console;
    delete cleanup;
    __UHEAP_MARKEND;
    return KErrNone;
    }

#endif	/* if 0 */