Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Dear forum members,

I am new to BREW, and have been tasked with writing code that will transfer data (and eventualy files) between a PC and a mobile phone running BREW (in this case a Samsung phone).

After browsing the forums and the web in general, I have found a sample that lets me transfer data between the PC and phone and it kinda works... I have tried adding file handling to my test program using IFile and IFileMgr, and that seems to work OK as well, however, I do have some questions problems I would appreciate people pointing me in the right direction:

1) IPort_Writeable callback. When I look at the QXDM, I see that after I run my program, this callback is constantly called, even if my PC side test program hasn't run yet, any reason why this is happening?

2) IPort_Readable callback. Any reason why this callback won't be called even though my PC code writes data to the USB and doesn't receive any error message?

Your kind help is appreciated.

Thanks

AP

These methods are used to register a callback function to be called when IPORT_Read/Write() would return something other than WAIT. This is to read/write data which cannot be done at a time (needs to read/write more than once). You need to call these APIs to register callbacks.
something like:
void CApp_TryRead(void* po)
{
int ret;
CApp* pme = (CApp*)po;
// read the data from the server.
ret = IPORT_Read(pme->m_pIPort,
pme->m_caReadBuffer + pme->m_nBytesRead,
BUFFER_SIZE - pme->m_nBytesRead
);
// no data is available for reading at the moment.
if (AEEPORT_WAIT == ret) {
// call CApp_TryRead() again when the read operation may progress.
IPORT_Readable(pme->m_pIPort, &pme->m_cbReadCallback, CApp_TryRead, pme);
return;
}
// an error occurred. get the error code.
if (AEEPORT_ERROR == ret) {
ret = IPORT_GetLastError(pme->m_pIPort);
...
return;
}
// connection closed by the other side
if (AEEPORT_CLOSED == ret) {
// handle connection closure
...
return;
}
// some bytes were read.
pme->m_nBytesRead += ret;
// not all the bytes were read yet. call CApp_TryRead() again when the read operation may progress.
if (pme->m_nBytesRead < BUFFER_SIZE) {
IPORT_Readable(pme->m_pIPort, &pme->m_cbReadCallback, CApp_TryRead, pme);
return;
}
// (BUFFER_SIZE == ret) - all bytes were successfully read.
// reset the bytes counter for next read operation
pme->m_nBytesRead = 0;
...
}

These methods are used to register a callback function to be called when IPORT_Read/Write() would return something other than WAIT. This is to read/write data which cannot be done at a time (needs to read/write more than once). You need to call these APIs to register callbacks.
something like:
void CApp_TryRead(void* po)
{
int ret;
CApp* pme = (CApp*)po;
// read the data from the server.
ret = IPORT_Read(pme->m_pIPort,
pme->m_caReadBuffer + pme->m_nBytesRead,
BUFFER_SIZE - pme->m_nBytesRead
);
// no data is available for reading at the moment.
if (AEEPORT_WAIT == ret) {
// call CApp_TryRead() again when the read operation may progress.
IPORT_Readable(pme->m_pIPort, &pme->m_cbReadCallback, CApp_TryRead, pme);
return;
}
// an error occurred. get the error code.
if (AEEPORT_ERROR == ret) {
ret = IPORT_GetLastError(pme->m_pIPort);
...
return;
}
// connection closed by the other side
if (AEEPORT_CLOSED == ret) {
// handle connection closure
...
return;
}
// some bytes were read.
pme->m_nBytesRead += ret;
// not all the bytes were read yet. call CApp_TryRead() again when the read operation may progress.
if (pme->m_nBytesRead < BUFFER_SIZE) {
IPORT_Readable(pme->m_pIPort, &pme->m_cbReadCallback, CApp_TryRead, pme);
return;
}
// (BUFFER_SIZE == ret) - all bytes were successfully read.
// reset the bytes counter for next read operation
pme->m_nBytesRead = 0;
...
}