Brew

  Home  Smartphone OS  Brew


“Brew job preparation guide for freshers and experienced candidates. Number of Brew frequently asked questions(FAQs) asked in many interviews”



78 Brew Questions And Answers

41⟩ Why do we get the value of 0.0.0.0 in dnsresult.addrs when I use GetHostByName()?

This may be due to incorrect implementation of error handling in the GetHostByName() callback function. The error handling implementation in the GetHostByName() callback of the NetSocket example is incorrect. You can use the following sample implementation:

if(pMe->dnsresult.nResult > 0 && pMe->dnsresult.nResult

<= AEEDNSMAXADDRS) {

// DNS lookup success

// Process dnsresult.addrs

for(i = 0; i < pMe->dnsresult.nResult; i++) {

SPRINTF(szMsg,"Addr=: %x",pMe->dnsresult.addrs[i]);

DisplayOutput(pMe,i+4,szMsg);

}

} else {

// DNS Failure - error code is dnsresult.nResult

SPRINTF(szMsg, "DNS: error %d", pMe->dnsresult.nResult);

DisplayOutput(pMe, 2, szMsg);

}

 185 views

44⟩ When transmitting large files, do we have to break the file up into packets before sending, or does BREW do this for me?

You should simply send what you can, and ISOCKET_Write() will tell you how much data was actually sent. If there is data remaining to be sent, simply offset your data pointer by the amount indicated by your last call to ISOCKET_Write().

For Example:

void CommonWriteCB (void *pUser) {

char *psz = NULL;

int cbWrite;

… … …

SampleApp * pMe = (SampleApp*)pUser;

// pszData is the data to be written

psz = pszData;

cbWrite = STRLEN (pszData);

// Loop till all the bytes are written.

while (cbWrite > 0) {

rv = ISOCKET_Write(pMe->m_pISocket, (byte *)psz,

(uint16)cbWrite);

if (rv == AEE_NET_WOULDBLOCK) {

// No byte were written successfully. Register

// callback to try again later.

ISOCKET_Writeable(pMe->m_pISocket,

CommonWriteCB, (void *)pMe);

return;

} else if (rv == AEE_NET_ERROR) {

// Write Error.

ReleaseNetAndSocket(pMe);

return;

}

// In case of parital write, loop and write the rest

cbWrite -= rv;

psz += rv;

}

… … …

}

 202 views

46⟩ Are network callbacks invoked in the context of the main thread, and if so how is the data integrity preserved in the current context?

All network callbacks occur within the same thread context, at some point in time after the caller returns control to the AEE event loop. If your application is busy doing something, callbacks will be queued, then invoked once your application returns control to the AEE event loop, ensuring data integrity..

 216 views

48⟩ When reading from a socket the phone reads whatever it can in one go, while the emulator reads large packets in chunks. Why?

This is a limitation of the phone.

Program should call ISOCKET_Readable() to be informed when more data can be read from the stream. The callback routine registered by ISOCKET_Readable() will be invoked whenever data becomes available---you can usually call ISOCKET_Read() at this point. Continue calling ISOCKET_Readable() for as long as your program expects more data.

rv = ISOCKET_Read(piSock, (byte *)szBuf, sizeof(szBuf));

if (rv == AEE_NET_WOULDBLOCK) {

// WOULDBLOCK => no more data available at the moment

// Register the callback to read the data later.

ISOCKET_Readable(piSock, CommonReadCB, (void*)pMe);

return;

}

else if (rv == AEE_NET_ERROR) {

// error reading from socket

ReleaseNetAndSocket (pMe);

}

else if (rv > 0) {

// rv bytes of data has been read from the socket into

// szBuf

// Read remaining data

ISOCKET_Readable(piSock, CommonReadCB, (void*)pMe);

}

else { // rv == 0

// There is no more data to be received.

// The peer has shut down the connection.

ReleaseNetAndSocket (pMe);

}

 205 views

49⟩ What image formats are supported in BREW?

BREW supports any BMP file with a color depth up to that which is provided on the device it is running on. BREW does not yet support GIF and JPEG images. For now, you need to convert GIF and JPEG images into BMP images. PNG format and BREW Compressed Image (BCI) format will be supported in BREW SDK version 1.1.

In SDK versions prior to 1.1, the emulator is capable of emulating only 1, 4, and 8 bit color depth BMPs. In version 1.1, the emulator can also display 2 bit color depth BMPs.

 182 views

50⟩ How to move the cursor to the end of the text input?

The cursor can be moved to the end of the string by continuously invoking ITEXTCTL_HandleEvent() method n times on the string, where n is the length of the string.

For example:

while(len) {

ITEXTCTL_HandleEvent(pMe->m_pIText, EVT_KEY,

AVK_RIGHT, dwParam);

len--;

}

 195 views

53⟩ Why do we get memory errors such as "memheap.c 0696" when using IDISPLAY_BitBlt() to draw a bitmap image?

Ensure that you are freeing the memory allocated by CONVERTBMP. Check the last Boolean parameter of CONVERTBMP. If True, a reallocation was done and the memory must be freed using SYSFREE.

For example:

pBmp = CONVERTBMP (pDataBytes, &imageInfo, &bVal);

IDISPLAY_BitBlt (pIDisplay, xDest, yDest, cxDest,

cyDest, pBmp, xSrc, ySrc, dwRopCode);

IDISPLAY_Update (pIDisplay);

if(bVal) //free only if realloc was done

SYSFREE (pBmp);

 187 views

54⟩ How to determine the character limit for the display of application names on the phone?

Different phones have different display characteristics, so there is no unique answer to this question. You can determine whether your application name will fit on the phone's display by comparing the width of the application name to the width of the display.

Use IDISPLAY_MeasureText() to determine the pixel width of your application name string. Use ISHELL_GetDeviceInfo() to determine the pixel width of the screen

 214 views

55⟩ Does BREW support animation?

BREW SDK version 1.0 includes support for animated BMP. This is done by placing the frames side-by-side and specifying the width of each frame with IIMAGE_SetParm with the IPARM-CXFRAME flag. Please see the IIMAGE example in the Examples directory

BREW SDK Version 1.1 has added support for BREW Compressed Image (BCI) animation. A BCI file contains one or more compressed small graphic image(s), each with a specified duration in milliseconds. The duration represents how long you want each image to be shown before it is replaced by the next image in the series. You can use the BCI Authoring Tool included in BREW SDK Version 1.1 to create your BCI file. Please refer to 'Using the BREW Compressed Image Authoring Tool' document included in the SDK for more information.

 182 views

56⟩ How to control animation by time?

One way to do this is to use the IImage interface and set the rate of animation (IImage_SetParm). An example in which the animation rate is set to 750ms is shown below:

IIMAGE_SetParm(pMe->m_pIImage, IPARM_RATE, 750, 0);

You can also use a timer to trigger the image display function. Use ISHELL_SetTimer() to set a timer:

ISHELL_SetTimer(pMe->a.m_pIShell, TIMER_RATE,

(PFNNOTIFY)(ManipulateBitmap), pMe);

After TIMER_RATE ms expires, ManipulateBitmap function will be triggered, within which you can manipulate your image.

 183 views

57⟩ Can you please explain the difference between Multi-tap and T9 text entry modes for text input?

In Multi-tap mode, a key must be tapped several times in order to specify a letter. For example, to specify the letter 'r', tap the number '7' three times. In T9 mode, a key is tapped only once per letter. T9 Text Input determines the most commonly used word matching the input numeric sequence. If more than once word matches the sequence, the most common word is selected, with the ability to scroll to the next most commonly used word.

The default text entry mode is Multi-tap. T9 text entry mode is not supported on the emulator.

 206 views

58⟩ How to draw a line in a specific color?

IDISPLAY_DrawHLine() and IDISPLAY_DrawVLine() always draw lines in black. Therefore setting CLR_USER_LINE to the desired color and then invoking IDISPLAY_DrawHLine() or IDISPLAY_DrawVLine() will not work.

The definitions of these two IDISPLAY macros are below. To draw a line in a color other than black, use the code contained in the macro definition and change to the desired fill color.

#define IDISPLAY_DrawHLine(p,x,y,len)

{AEERect rc;SETAEERECT(&rc,(x),(y),(len),1); IDISPLAY_FillRect((p),&rc,

RGB_BLACK);}

#define IDISPLAY_DrawVLine(p,x,y,len)

{AEERect rc;SETAEERECT(&rc,(x),(y),1,(len)); IDISPLAY_FillRect((p),&rc,

RGB_BLACK);}

 187 views

59⟩ How to create a dialog?

Use the BREW Resource Editor to create a dialog. You can also construct the dialog manually by creating data structures in your application to define the contents of the dialog.

Note: If a bmp file is being used, make sure that the bmp format is supported and that the bmp file is a valid full path, all in lowercase.

Once the dialog has been created, it will have a resource ID and a resource file (.bar file). Use ISHELL_CreateDialog() to create the dialog:

ISHELL_CreateDialog(pMe->a.pIShell, SAMPLEAPP_RES_FILE,

RESOURCE_ID, NULL);

// SAMPLEAPP_RES_FILE is the resource file (.bar file) and

// RESOURCE_ID is the resource ID specified in the resource

// editor

Process the following events (return TRUE at the very least) in the app handler function:

case EVT_DIALOG_START:

return TRUE;

case EVT_DIALOG_INIT:

return TRUE;

case EVT_DIALOG_END:

return TRUE;

Call ISHELL_EndDialog when the dialog object is no longer needed.

ISHELL_EndDialog(pMe->a.pIShell);

 174 views