October 22, 2016
Hot Topics:

A Generic Connection Framework for BREW

  • July 30, 2003
  • By Radu Braniste
  • Send Email »
  • More Articles »

How to Use the Framework

The details are a little bit confusing, maybe, but the usage is very simple. Actually, a wrapper was provided:

template <class R, class S>
void CPPApp::initIO( FNC f, char* address, const String& param);

taking care of almost anything.

All we need is a ResourceRegistry, a Resource, and the associated data. A simple GenericResource and data structure (GDS) were created for this purpose. After GenericResource::initConnection() succeeds, an async call is made to asynchronously read some data from a resource.

User has to make one call, like:

initIO<GResource, GDS>(onReadCbk<GDS>,"San Diego",

and provide a member function as the callback:

template <class S>
void CPPApp::onReadCbk()
  S* ds = static_cast<S*>(rr_->getRegistered(S::getID()));
  if (ds->error == SUCCESS)
    if (! ds->data.isEmpty()
      //do something
    String e((long)ds->error);
    //deal with error


Playing with Compilers

VC 7.1 is now one of the most standard compliant compilers. At the lower end is VC6—and some additional techniques had to be used to accommodate the framework here. ADS 1.0.1 is somewhere in between and RealView C++ compiler is claiming to be on the high end.

One of the problems of VC6 is in the area of function templates, namely the "explicit template argument specification."

initIO< GenericResource, GDS>(onReadCbk<FDS>, ds->address,

is not possible. A technique described in [4] is the use of a "type vehicle"—Type2Type:

template <class T>
struct Type2Type
  typedef T TYPE;

so we can now rewrite the previous initIO call as:

tIO(&CPPApp::onReadFSCbk, ds->address, String(""),
    Type2Type< GenericResource>() , Type2Type<GDS>());

There are problems in using pointers to template member functions, too. One way to solve this is to use functions and another one to "unroll" the calls, like:

void CPPApp::onReadHttpCbk()
instead of simply:
initIO<HTTPpipe, HDS>(onReadCbk<HDS>,....);

Two versions of the code are provided—for VC7.1 and VC6.0, respectively.

In the next installment, we will try to use the framework with some "real-life" resources, such as files and sockets and discuss other useful features of the framework.


[1] Cooperative Multitasking in BREW: A Possible Solution—http://www.developer.com/ws/brew/article.php/1497121

[2] Bjarne Stroustrup—The C++ Programming Language, Addison-Wesley 1997

[3] The exception might be IShell_SetTimer with a too short timer interval

[4] Andrei Alexandrescu—Modern C++ Design, Addison-Wesley 2001

About the Author

Radu Braniste is Director of Technology at Epicad. He can be contacted at rbraniste@epicad.com

# # #

Page 3 of 3

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel