Listing 1310 Daytime application build script

arm-none-linux-gnueabi-gcc -c daytime.c <—O Compile daytime.c arm-none-linux-gnueabi-gcc -c -o crto.o crt.S <1—© Compile crt.S arm-none-linux-gnueabi-ld --entry=_start --dynamic-linker /system/bin/linker -nostdlib -rpath /system/lib -rpath-link \android\system\lib -L \android\system\lib -l c -l android_runtime -l sqlite -o daytime daytime.o crto.o <-1 _ _ _

C: \sof tware\google\<path to android sdk>\tools\adb © Link the application push daytime /data/ch13 <1-1

g:\tools\adb shell "chmod 777 /data/ch13/daytime" © 'nstaH application

The build script begins by compiling the main source file, daytime.c O- The next line compiles the crt.S file, which was introduced in listing 13.7 for our C runtime initialization Q. The linker command contains a number of switches to create the desired application. Note the parameter to the linker in G to include the sqlite library. Note also the inclusion of both daytime.o and crtO.o object files as inputs to the linker. Both are required to properly construct the Daytime Server application. The input files are found in local (to the development machine) copies of the libraries. adb is employed to push the executable file to the Android Emulator and to modify the permissions, saving a manual step Q.

Running the Daytime Server application is the easy and fun part of this exercise. Figure 13.9 shows our Daytime Server running.

cC C:\WINDOW5\sysfcem32\cmd.eHe

G:\too Is >adb shell

tt cd /dalochia

cd /ditaVchl3

tt ■f'daytifte

-✓(JaiPtime

Daytine Server

Waiting flit1 connection

T ill -.ii = : .

Incoming connection?

Calling accept:

Connecting

Isendina tWed Jul 30 09:35:85 2B0S1

RecordHit: insert into hits

values

<DnrETIME<'NOW >.MIed Jul 30 09:35:05 2008'>ï

Waitingr for connection

T imoout.

'C

G:xtools>adb shell

tt cd ^dataxclil3

cd /*dittaVchl3

tt sqlite3 daytinie_db.db

sqlite3 daytinje„dh.db

SQI.it® version 3.5.0

lEnter "_Jiclp" for instructions

sqlite} select * fron hits;

select * fron hits;

200B-0729 07=31=35¡Tue Jul

29

07

31:35 2B08

2008-07-29 07:56:27¡Tue Jul

29

07

56:27 2008

3008-07-29 07:56:28¡Tue Jul

29

07

56:28 2008

3008-07-29 07=56=29!Tue Jul

29

B7

56:28 2008

2008-07-29 07:56:29¡Tue Jul

29

07

56:29 2008

2008-07-29 07:56:29¡Tue Jul

29

07

56:29 2008

2008-07-29 07:56:29¡Tub Jul

29

07

56:29 2008

2008-37-29 07:56:29¡Tue Jul

29

07

56:29 2008

2008-07-29 07:56:30!Tue Jul

29

07

56:30 2008

2008-07-30 09:06:57¡Wed Jul

30

09

06:57 2008

2008-07-30 09:08:45 ¡tied Jul

30

09

08:44 2008

2008 07-30 09 :12 :34 !IJed Jul

30

09

12:34 2008

2008-07-30 09:33:45 ¡tied Jul

30

09

33:44 2008

2008-07-30 09:35:05¡Wed Jul

30

09

35:05 2008

sqlite> .exit

• exit

tt exit

exit

G:\toals>_

Figure 13.9 Daytime Server running in the shell

Here is a rundown of the sequence shown in figure 13.9:

1 Start the shell by running adb shell.

2 Change directories to /data/ch13, where our application resides, previously pushed there with an adb push command.

3 Run the ./daytime application.

4 The application binds to a port and begins listening for an incoming connection.

5 A timeout occurs prior to a connection being made. The application displays the timeout and returns to look for connections again.

6 A connection is detected and subsequently accepted.

7 The time string is constructed and sent to the client.

8 A record is inserted into the database with the shown sql statement.

9 We kill the application and restart the shell. Note that this is because we did not build a clean way of killing the Daytime Server. A proper version of the application would be to convert it to a daemon, which is beyond the scope of our interest here.

10 Run sqlite3 to examine the contents of our application's database.

11 Perform a select against the hits table, where we see the recently inserted record.

We have built an Android/Linux application that implements a variant of the traditional daytime server application as well as interacts with a SQL database. Not too shabby when you consider that this is a telephone platform! Let's move on to examine the Android/Java application used to exercise the Daytime Server, our Daytime Client.

0 0

Post a comment