How to add a new service to Opera
We'll use the console logger as the example application, because
it's simplest. Have a look at the source files in scope/src:
scope_console_logger.h and scope_console_logger.cpp.
(This description is accurate but over-complex because
OpScopeService now has default implementations of OnClientConnected
and OnClientDisconnected that do the right thing.)
Receiving data
The class OpScopeConsoleLogger is derived from OpScopeService and
contains three methods of interest:
- OnClientConnected
- This is called by the framework whenever a new client connects to
the proxy and sends an "*enable" message. Its "service" argument
receives the name of the service being enabled. Your client should enable
itself if it provides this service.
- OnClientDisconnected
- This is called by the framework whenever a new client connects to
the proxy and sends a "*disable" message. Its "service" argument
receives the name of the service being disbled. Your client should disable
itself if it provides this service.
- OnReceive
- This is called every time data arrives from the proxy. The "service" argument
is the service name, and "data" is the data carried. If your client
recognizes the service it should do something with the data.
Sending data
The function OpScopeService::Transmit is used to send data to the
proxy. It prepends the name of the sending service and a blank to the message.