The Qt based Network Manager is a simple network services module which
can be expanded upon and customized by the developer. The heart of the
manager is the NetMngr class implemented on top of the Qt based
QNetworkAccessManager class. The primary function of the added layering is to
provide a means whereby the NetMngr class can provide network services without
special regard to whom or how many users are making web requests.
The Qt based Network Manager is written in C++ and compiles and runs under
either Qt4 or Qt5. There are no dependencies on operating system, compiler,
or linker. A sample application with code and Makefile is provided. This code
is provided as is and may be freely used by anyone without any restriction.
Given that the class NetMngr is instantiated as a globally visible object,
the NetMngr class is used as follows:
mMyID = pNetMngr->registerRequestor(this);
where mMyID is data member of the requesting object, this.
this->RequestingObject::setProperty(SIGEMIT, QVariant(mMyID));
It is required that the requesting object inherit from the RequestingObject
class which is defined in netmngr.hh.
void replyReceived(QNetworkReply *);
replyReceived() is effectively a signal handling slot, however, it is not
declared as such and not 'connected' as such to the network manager's
reply received slot.
pNetMngr->requestInitiate(&netRequest, this);
where
QNetworkRequest netRequest;
this - pointer to requesting object
Behind the scenes the network manager is handling multiple requests from
multiple objects. The following describes how this is managed.
The mMyID is a random number generated by the network manager and handed back
to the requesting object. mMyID serves as a unique identifier of the requesting
object. The requesting object also passes it's this pointer to the network
manager when registering. The network manager takes both the mMyID and this
and adds them as a pair to a STL based map object, mMyID being the key and
this being the value. The network manager also adds the mMyID as a dynamic property
to the network reply. Upon receiving the network reply, the network
manager extracts the mMyID key from the reply, looks up the corresponding
this pointer to the requesting object, and calls the requesting object's
replyReceived() member function. Since mMyID is unique, the proper requesting
object will be called irregardless of the order in which replies are received.
The prospective user may wish to peruse the sample application code provided
to clarify details and inner workings. For example, see usIRSatellite.cc/hh
and usRadar.cc/hh which are examples of requesting objects.