#ifndef __RILMONITOR_H__ #define __RILMONITOR_H__ // vim: ts=4 sw=4 et #include #include "waitvariable.h" #include "RilStructDecoder.h" #include "debug.h" #include "stringutils.h" // this is the baseclass for function result handlers // // handle() is called by the ril-stack ( in this case 'rilsimulate' ) // request() is called by rilmonitor_impl::process_request // error() is called by rilmonitor_impl::process_request ( passing RIL_RESULT_ERROR RIL_E_* codes ) // lineerror() is called by rilmonitor_impl::process_request ( passing RIL_RESULT_ codes ) // TODO: errcode||lineerror check should be made simpler. // return bool from 'wait' ? // // notify() is called after the handle() function // wait() is called by the caller of the request object class requesthandler { public: requesthandler() : _ready(false), _errorcode(0), _lineerror(0) { } void notify() { _ready.set(true); } void wait() { _ready.wait_equal(true); } DWORD errorcode() const { return _errorcode; } DWORD lineerror() const { return _lineerror; } virtual std::string name() const= 0; virtual void handle(long dwCode, const void *data, size_t size) throw()= 0; virtual void error(DWORD dwError) { _errorcode= dwError; } virtual void lineerror(DWORD dwCode) { _lineerror= dwCode; } virtual int request()= 0; private: waitvariable _ready; DWORD _errorcode; DWORD _lineerror; }; typedef boost::shared_ptr requesthandler_ptr; // this is the base class for event handlers // // todo: it needs to be able to do any of the following: // * set a waitvariable // * call a function // * add information to a queue class eventhandler { public: virtual std::string name() const= 0; virtual DWORD code() const=0; virtual void handle(const void *data, size_t size) throw()= 0; }; typedef boost::shared_ptr eventhandler_ptr; class HexdumpEventHandler : public eventhandler { public: HexdumpEventHandler(int code) : _code(code) { } virtual std::string name() const { return RilResultString(_code); } virtual DWORD code() const { return _code; } virtual void handle(const void *data, size_t size) throw() { debug("%s: %s\n", name().c_str(), (data && size)? hexdump(reinterpret_cast(data), size).c_str() : "-"); } private: int _code; }; // rilmonitor_impl talks to the RIL stack directly // it is seperate from rilmonitor so the user of rilmonitor.h // is not burdened with including all ril specific lowlevel details. class rilmonitor_impl; class rilmonitor { public: rilmonitor(); ~rilmonitor(); // ril functions requesthandler_ptr GetSignalQuality(long &level); requesthandler_ptr GetUserIdentity(std::string& imsi); requesthandler_ptr GetEquipmentInfo(std::string &imei); requesthandler_ptr GetEquipmentState(DWORD &state); requesthandler_ptr SetEquipmentState(DWORD state); requesthandler_ptr SendRestrictedSimCmd(DWORD dwCommand, DWORD dwFileId, const BYTE* lpbData, DWORD dwSize, DWORD nParams, int p1, int p2, int p3); requesthandler_ptr GetSimRecordStatus(DWORD dwFile, int& type, size_t& itemcount, size_t& itemsize); requesthandler_ptr DevSpecific(const ByteVector& request, ByteVector& response); requesthandler_ptr Dial(const std::string& nr, DWORD type, DWORD opts); requesthandler_ptr Answer(); requesthandler_ptr Hangup(); void registerhandler(eventhandler_ptr h); void deregisterhandler(eventhandler_ptr h); void DumpDriverInfo(); //void SetEqState(DWORD dwState); //void SetBearerServiceOptions(DWORD dwSpeed, DWORD dwName, DWORD dwCe); //void RegisterOnNetwork(); HANDLE GetSerialPort(); rilmonitor_impl *_; // todo: add r/w interface which returns amount actually read/written // and uses begin/end iterators, instead of the entire vector. void write(const ByteVector& data); void read(ByteVector& data, size_t n); HANDLE handle() const { return _handle; } HANDLE _handle; }; #endif