#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), _tcreate(GetTickCount()), _trequest_start(0), _trequest_end(0), _treply(0) { } ~requesthandler() { //logstamps(); } void logstamps() { debug("RQ[%p]: %08lx rq:%+d .. %+d, rp: %+d\n", this, _tcreate, _trequest_start ? (_trequest_start-_tcreate) : -1, (_trequest_end && _trequest_start) ? (_trequest_end-_trequest_start) : -1, (_treply && _trequest_end) ? _treply-_trequest_end : -1); } 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; void recordstart() { _trequest_start= GetTickCount(); } void recordend() { _trequest_end= GetTickCount(); } void recordreply() { _treply= GetTickCount(); } DWORD trequest() const { return _trequest_end; } private: waitvariable _ready; DWORD _errorcode; DWORD _lineerror; DWORD _tcreate; DWORD _trequest_start; DWORD _trequest_end; DWORD _treply; }; 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 ByteVector& data, DWORD nParams, int p1, int p2, int p3); requesthandler_ptr SendRestrictedSimCmd(DWORD dwCommand, DWORD dwFileId, DWORD nParams, int p1, int p2, int p3); requesthandler_ptr SendSimCmd(const ByteVector& cmd, ByteVector& reply); requesthandler_ptr SendSimCmd(BYTE cls, BYTE ins, BYTE p1, BYTE p2, const ByteVector& data, size_t retsize, ByteVector &reply); 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(); // note: these don't return anything yet, just for debugging requesthandler_ptr GetHSCSDOptions(); requesthandler_ptr GetHSCSDCallSettings(); 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