author | zecke <zecke> | 2004-02-19 20:29:53 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-19 20:29:53 (UTC) |
commit | f6f89c9fad356f91f1ad63402757335f7fb4fed2 (patch) (side-by-side diff) | |
tree | 9646358fb1b6bdec12fa29971936cbe63ad8f06b | |
parent | c2eb77f6b8933b02bd8bd59ec7325da0bfc956cb (diff) | |
download | opie-f6f89c9fad356f91f1ad63402757335f7fb4fed2.zip opie-f6f89c9fad356f91f1ad63402757335f7fb4fed2.tar.gz opie-f6f89c9fad356f91f1ad63402757335f7fb4fed2.tar.bz2 |
Restore binary compatibility and make use of the virtual_hook
Yeah it is ugly... but will work for libopie...
Now onto libopie2! development
-rw-r--r-- | libopie/odevice.cpp | 112 | ||||
-rw-r--r-- | libopie/odevice.h | 24 |
2 files changed, 107 insertions, 29 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index c5a916b..c5342e1 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp @@ -54,48 +54,49 @@ #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) using namespace Opie; class ODeviceData { public: QString m_vendorstr; OVendor m_vendor; QString m_modelstr; OModel m_model; QString m_systemstr; OSystem m_system; QString m_sysverstr; Transformation m_rotation; ODirection m_direction; QValueList <ODeviceButton> *m_buttons; uint m_holdtime; QStrList *m_cpu_frequencies; + }; class iPAQ : public ODevice, public QWSServer::KeyboardFilter { protected: virtual void init ( ); virtual void initButtons ( ); public: virtual bool setSoftSuspend ( bool soft ); virtual bool setDisplayBrightness ( int b ); virtual int displayBrightnessResolution ( ) const; virtual void alarmSound ( ); virtual QValueList <OLed> ledList ( ) const; virtual QValueList <OLedState> ledStateList ( OLed led ) const; virtual OLedState ledState ( OLed led ) const; virtual bool setLedState ( OLed led, OLedState st ); virtual bool hasLightSensor ( ) const; virtual int readLightSensor ( ); virtual int lightSensorResolution ( ) const; @@ -119,63 +120,64 @@ public: static bool isJornada(); }; class Zaurus : public ODevice { protected: virtual void init ( ); virtual void initButtons ( ); public: virtual bool setSoftSuspend ( bool soft ); virtual bool setDisplayBrightness ( int b ); virtual int displayBrightnessResolution ( ) const; virtual void alarmSound ( ); virtual void keySound ( ); virtual void touchSound ( ); virtual QValueList <OLed> ledList ( ) const; virtual QValueList <OLedState> ledStateList ( OLed led ) const; virtual OLedState ledState ( OLed led ) const; virtual bool setLedState ( OLed led, OLedState st ); - virtual bool hasHingeSensor() const; - virtual OHingeStatus readHingeSensor(); + bool hasHingeSensor() const; + OHingeStatus readHingeSensor(); static bool isZaurus(); // Does this break BC? virtual bool suspend ( ); - virtual Transformation rotation ( ) const; - virtual ODirection direction ( ) const; + Transformation rotation ( ) const; + ODirection direction ( ) const; protected: virtual void buzzer ( int snd ); OLedState m_leds [1]; bool m_embedix; + void virtual_hook( int id, void *data ); }; class SIMpad : public ODevice, public QWSServer::KeyboardFilter { protected: virtual void init ( ); virtual void initButtons ( ); public: virtual bool setSoftSuspend ( bool soft ); virtual bool suspend(); virtual bool setDisplayStatus( bool on ); virtual bool setDisplayBrightness ( int b ); virtual int displayBrightnessResolution ( ) const; virtual void alarmSound ( ); virtual QValueList <OLed> ledList ( ) const; virtual QValueList <OLedState> ledStateList ( OLed led ) const; virtual OLedState ledState ( OLed led ) const; virtual bool setLedState ( OLed led, OLedState st ); protected: virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); @@ -423,49 +425,49 @@ struct yopy_button { "addressbook", "beamBusinessCard()" }, { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "End Button"), "devicebuttons/yopy_end", "QPE/Launcher", "home()", "buttonsettings", "raise()" }, }; static QCString makeChannel ( const char *str ) { if ( str && !::strchr ( str, '/' )) return QCString ( "QPE/Application/" ) + str; else return str; } static inline bool isQWS() { return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; } ODevice *ODevice::inst ( ) { static ODevice *dev = 0; - if ( !dev ) { + if ( !dev ) { if ( QFile::exists ( "/proc/hal/model" )) dev = new iPAQ ( ); else if ( Zaurus::isZaurus() ) dev = new Zaurus ( ); else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" )) dev = new SIMpad ( ); else if ( QFile::exists ( "/proc/sys/board/name" )) dev = new Ramses ( ); else if ( Yopy::isYopy() ) dev = new Yopy ( ); else if ( Jornada::isJornada() ) dev = new Jornada ( ); else dev = new ODevice ( ); dev-> init ( ); } return dev; } /************************************************** * * common * @@ -707,57 +709,63 @@ QString ODevice::systemString ( ) const return d-> m_systemstr; } /** * Return System as OSystem value */ OSystem ODevice::system ( ) const { return d-> m_system; } /** * @return the version string of the base system */ QString ODevice::systemVersionString ( ) const { return d-> m_sysverstr; } /** * @return the current Transformation */ Transformation ODevice::rotation ( ) const { - return d-> m_rotation; + VirtRotation rot; + ODevice* that =(ODevice* )this; + that->virtual_hook( VIRTUAL_ROTATION, &rot ); + return rot.trans; } /** * @return the current rotation direction */ ODirection ODevice::direction ( ) const { - return d-> m_direction; + VirtDirection dir; + ODevice* that =(ODevice* )this; + that->virtual_hook( VIRTUAL_DIRECTION, &dir ); + return dir.direct; } /** * This plays an alarmSound */ void ODevice::alarmSound ( ) { #ifndef QT_NO_SOUND static Sound snd ( "alarm" ); if ( snd. isFinished ( )) snd. play ( ); #endif } /** * This plays a key sound */ void ODevice::keySound ( ) { #ifndef QT_NO_SOUND static Sound snd ( "keysound" ); if ( snd. isFinished ( )) @@ -825,57 +833,62 @@ bool ODevice::hasLightSensor ( ) const return false; } /** * @return a value from the light sensor */ int ODevice::readLightSensor ( ) { return -1; } /** * @return the light sensor resolution */ int ODevice::lightSensorResolution ( ) const { return 0; } /** * @return if the device has a hinge sensor */ bool ODevice::hasHingeSensor ( ) const { - return false; + VirtHasHinge hing; + ODevice* that =(ODevice* )this; + that->virtual_hook( VIRTUAL_HAS_HINGE, &hing ); + return hing.hasHinge; } /** * @return a value from the hinge sensor */ OHingeStatus ODevice::readHingeSensor ( ) { - return CASE_UNKNOWN; + VirtHingeStatus hing; + virtual_hook( VIRTUAL_HINGE, &hing ); + return hing.hingeStat; } /** * @return a list with CPU frequencies supported by the hardware */ const QStrList &ODevice::allowedCpuFrequencies ( ) const { return *d->m_cpu_frequencies; } /** * Set desired CPU frequency * * @param index index into d->m_cpu_frequencies of the frequency to be set */ bool ODevice::setCurrentCpuFrequency(uint index) { if (index >= d->m_cpu_frequencies->count()) return false; char *freq = d->m_cpu_frequencies->at(index); qWarning("set freq to %s", freq); @@ -982,132 +995,153 @@ void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) // buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); } void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) { initButtons ( ); if ( button >= (int) d-> m_buttons-> count ( )) return; ODeviceButton &b = ( *d-> m_buttons ) [button]; b. setHeldAction ( action ); Config buttonFile ( "ButtonSettings" ); buttonFile. setGroup ( "Button" + QString::number ( button )); buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( )); buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( )); // buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( ))); QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); } -void ODevice::virtual_hook(int, void* ){ - +void ODevice::virtual_hook(int id, void* data){ + switch( id ) { + case VIRTUAL_ROTATION:{ + VirtRotation* rot = reinterpret_cast<VirtRotation*>( data ); + rot->trans = d->m_rotation; + break; + } + case VIRTUAL_DIRECTION:{ + VirtDirection *dir = reinterpret_cast<VirtDirection*>( data ); + dir->direct = d->m_direction; + break; + } + case VIRTUAL_HAS_HINGE:{ + VirtHasHinge *hin = reinterpret_cast<VirtHasHinge*>( data ); + hin->hasHinge = false; + break; + } + case VIRTUAL_HINGE:{ + VirtHingeStatus *hin = reinterpret_cast<VirtHingeStatus*>( data ); + hin->hingeStat = CASE_UNKNOWN; + break; + } + } } /************************************************** * * Yopy 3500/3700 * **************************************************/ bool Yopy::isYopy ( ) { QFile f( "/proc/cpuinfo" ); if ( f. open ( IO_ReadOnly ) ) { QTextStream ts ( &f ); QString line; while( line = ts. readLine ( ) ) { if ( line. left ( 8 ) == "Hardware" ) { int loc = line. find ( ":" ); if ( loc != -1 ) { QString model = line. mid ( loc + 2 ). simplifyWhiteSpace( ); return ( model == "Yopy" ); } } } } return false; } void Yopy::init ( ) { d-> m_vendorstr = "G.Mate"; d-> m_vendor = Vendor_GMate; d-> m_modelstr = "Yopy3700"; d-> m_model = Model_Yopy_3700; d-> m_rotation = Rot0; - + d-> m_systemstr = "Linupy"; d-> m_system = System_Linupy; - + QFile f ( "/etc/issue" ); if ( f. open ( IO_ReadOnly )) { QTextStream ts ( &f ); ts.readLine(); d-> m_sysverstr = ts. readLine ( ); f. close ( ); } } void Yopy::initButtons ( ) { if ( d-> m_buttons ) return; d-> m_buttons = new QValueList <ODeviceButton>; for (uint i = 0; i < ( sizeof( yopy_buttons ) / sizeof(yopy_button)); i++) { yopy_button *ib = yopy_buttons + i; - + ODeviceButton b; b. setKeycode ( ib-> code ); b. setUserText ( QObject::tr ( "Button", ib-> utext )); b. setPixmap ( Resource::loadPixmap ( ib-> pix )); b. setFactoryPresetPressedAction (OQCopMessage(makeChannel(ib->fpressedservice), ib->fpressedaction)); b. setFactoryPresetHeldAction (OQCopMessage(makeChannel(ib->fheldservice), ib->fheldaction)); d-> m_buttons-> append ( b ); } reloadButtonMapping ( ); - + QCopChannel *sysch = new QCopChannel("QPE/System", this); - connect(sysch, SIGNAL(received(const QCString &, const QByteArray & )), + connect(sysch, SIGNAL(received(const QCString &, const QByteArray & )), this, SLOT(systemMessage(const QCString &, const QByteArray & ))); } bool Yopy::suspend() { - /* Opie for Yopy does not implement its own power management at the - moment. The public version runs parallel to X, and relies on the + /* Opie for Yopy does not implement its own power management at the + moment. The public version runs parallel to X, and relies on the existing power management features. */ return false; } bool Yopy::setDisplayBrightness(int bright) { /* The code here works, but is disabled as the current version runs parallel to X, and relies on the existing backlight demon. */ #if 0 if ( QFile::exists("/proc/sys/pm/light") ) { int fd = ::open("/proc/sys/pm/light", O_WRONLY); if (fd >= 0 ) { if (bright) ::write(fd, "1\n", 2); else ::write(fd, "0\n", 2); ::close(fd); return true; } } #endif return false; } @@ -1522,49 +1556,49 @@ int iPAQ::lightSensorResolution ( ) const * Zaurus * **************************************************/ // Check whether this device is the sharp zaurus.. // FIXME This gets unnecessary complicated. We should think about splitting the Zaurus // class up into individual classes. We need three classes // // Zaurus-Collie (SA-model w/ 320x240 lcd, for SL5500 and SL5000) // Zaurus-Poodle (PXA-model w/ 320x240 lcd, for SL5600) // Zaurus-Corgi (PXA-model w/ 640x480 lcd, for C700, C750, C760, and C860) // // Only question right now is: Do we really need to do it? Because as soon // as the OpenZaurus kernel is ready, there will be a unified interface for all // Zaurus models (concerning apm, backlight, buttons, etc.) // // Comments? - mickeyl. bool Zaurus::isZaurus() { // If the special devices by embedix exist, it is quite simple: it is a Zaurus ! if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ) ){ return true; - } + } // On non-embedix kernels, we have to look closer. bool is_zaurus = false; QFile f ( "/proc/cpuinfo" ); if ( f. open ( IO_ReadOnly ) ) { QString model; QFile f ( "/proc/cpuinfo" ); QTextStream ts ( &f ); QString line; while( line = ts. readLine ( ) ) { if ( line. left ( 8 ) == "Hardware" ) break; } int loc = line. find ( ":" ); if ( loc != -1 ) model = line. mid ( loc + 2 ). simplifyWhiteSpace( ); if ( model == "Sharp-Collie" || model == "Collie" || model == "SHARP Corgi" || model == "SHARP Shepherd" || model == "SHARP Poodle" || model == "SHARP Husky" @@ -1800,84 +1834,84 @@ void Zaurus::buzzer ( int sound ) case SHARP_BUZ_SCHEDULE_ALARM: soundname = "alarm"; break; case SHARP_BUZ_TOUCHSOUND: soundname = "touchsound"; break; case SHARP_BUZ_KEYSOUND: soundname = "keysound"; break; default: soundname = "alarm"; } } // If a soundname is defined, we expect that this device has // sound capabilities.. Otherwise we expect to have the buzzer // device.. if ( !soundname.isEmpty() ){ int fd; int vol; bool vol_reset = false; Sound snd ( soundname ); - + if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { Config cfg ( "qpe" ); cfg. setGroup ( "Volume" ); int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); if ( volalarm < 0 ) volalarm = 0; else if ( volalarm > 100 ) volalarm = 100; volalarm |= ( volalarm << 8 ); if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) vol_reset = true; } } snd. play ( ); while ( !snd. isFinished ( )) qApp-> processEvents ( ); if ( fd >= 0 ) { if ( vol_reset ) ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); ::close ( fd ); } - } else { + } else { int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK ); - + if ( fd >= 0 ) { ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); ::close ( fd ); } - } + } #endif } void Zaurus::alarmSound ( ) { buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); } void Zaurus::touchSound ( ) { buzzer ( SHARP_BUZ_TOUCHSOUND ); } void Zaurus::keySound ( ) { buzzer ( SHARP_BUZ_KEYSOUND ); } QValueList <OLed> Zaurus::ledList ( ) const { QValueList <OLed> vl; vl << Led_Mail; @@ -2045,51 +2079,51 @@ bool Zaurus::suspend ( ) ::gettimeofday ( &tvn, 0 ); } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 15000 ); } QCopEnvelope ( "QPE/Rotation", "rotateDefault()" ); return res; } Transformation Zaurus::rotation ( ) const { Transformation rot; int handle = 0; int retval = 0; switch ( d-> m_model ) { case Model_Zaurus_SLC7x0: handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); if (handle == -1) { return Rot270; } else { retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); ::close (handle); - if (retval == 2 ) + if (retval == 2 ) rot = Rot0; - else + else rot = Rot270; } break; case Model_Zaurus_SLA300: case Model_Zaurus_SLB600: case Model_Zaurus_SL5500: case Model_Zaurus_SL5000: default: rot = d-> m_rotation; break; } return rot; } ODirection Zaurus::direction ( ) const { ODirection dir; int handle = 0; int retval = 0; switch ( d-> m_model ) { case Model_Zaurus_SLC7x0: handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); if (handle == -1) { dir = CW; @@ -2132,48 +2166,76 @@ OHingeStatus Zaurus::readHingeSensor() int handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); if (handle == -1) { qWarning("Zaurus::readHingeSensor() - failed (%s)", "unknown reason" ); //FIXME: use strerror return CASE_UNKNOWN; } else { int retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); ::close (handle); if ( retval == CASE_CLOSED || retval == CASE_PORTRAIT || retval == CASE_LANDSCAPE ) { qDebug( "Zaurus::readHingeSensor() - result = %d", retval ); return static_cast<OHingeStatus>( retval ); } else { qWarning("Zaurus::readHingeSensor() - couldn't compute hinge status!" ); return CASE_UNKNOWN; } } } +void Zaurus::virtual_hook( int id, void *data ) { + switch( id ) { + case VIRTUAL_ROTATION:{ + VirtRotation* rot = reinterpret_cast<VirtRotation*>( data ); + rot->trans = rotation(); + break; + } + case VIRTUAL_DIRECTION:{ + VirtDirection *dir = reinterpret_cast<VirtDirection*>( data ); + dir->direct = direction(); + break; + } + case VIRTUAL_HAS_HINGE:{ + VirtHasHinge *hin = reinterpret_cast<VirtHasHinge*>( data ); + hin->hasHinge = hasHingeSensor(); + break; + } + case VIRTUAL_HINGE:{ + VirtHingeStatus *hin = reinterpret_cast<VirtHingeStatus*>( data ); + hin->hingeStat = readHingeSensor(); + break; + } + default: + ODevice::virtual_hook( id, data ); + break; + } +} + /************************************************** * * SIMpad * **************************************************/ void SIMpad::init ( ) { d-> m_vendorstr = "SIEMENS"; d-> m_vendor = Vendor_SIEMENS; QFile f ( "/proc/hal/model" ); //TODO Implement model checking //FIXME For now we assume an SL4 d-> m_modelstr = "SL4"; d-> m_model = Model_SIMpad_SL4; switch ( d-> m_model ) { default: d-> m_rotation = Rot0; d-> m_direction = CCW; d-> m_holdtime = 1000; // 1000ms diff --git a/libopie/odevice.h b/libopie/odevice.h index 791d358..fc41079 100644 --- a/libopie/odevice.h +++ b/libopie/odevice.h @@ -173,114 +173,130 @@ protected: virtual void initButtons ( ); ODeviceData *d; public: // sandman do we want to allow destructions? -zecke? virtual ~ODevice ( ); static ODevice *inst ( ); // information QString modelString ( ) const; OModel model ( ) const; inline OModel series ( ) const { return (OModel) ( model ( ) & Model_Series_Mask ); } QString vendorString ( ) const; OVendor vendor ( ) const; QString systemString ( ) const; OSystem system ( ) const; QString systemVersionString ( ) const; - virtual Transformation rotation ( ) const; - virtual ODirection direction ( ) const; + /*virtual*/ Transformation rotation ( ) const; + /*virtual*/ ODirection direction ( ) const; // system virtual bool setSoftSuspend ( bool on ); virtual bool suspend ( ); virtual bool setDisplayStatus ( bool on ); virtual bool setDisplayBrightness ( int brightness ); virtual int displayBrightnessResolution ( ) const; virtual bool setDisplayContrast ( int contrast ); virtual int displayContrastResolution ( ) const; // don't add new virtual methods, use this: // /*virtual */ void boo(int i ) { return virtual_hook(1,&i); }; // and in your subclass do do overwrite // protected virtual int virtual_hook(int, void *) // which is defined below // input / output //FIXME playAlarmSound and al might be better -zecke virtual void alarmSound ( ); virtual void keySound ( ); virtual void touchSound ( ); virtual QValueList <OLed> ledList ( ) const; virtual QValueList <OLedState> ledStateList ( OLed led ) const; virtual OLedState ledState ( OLed led ) const; virtual bool setLedState ( OLed led, OLedState st ); virtual bool hasLightSensor ( ) const; virtual int readLightSensor ( ); virtual int lightSensorResolution ( ) const; - virtual bool hasHingeSensor ( ) const; - virtual OHingeStatus readHingeSensor ( ); + /*virtual*/ bool hasHingeSensor ( ) const; + /*virtual*/ OHingeStatus readHingeSensor ( ); const QStrList &allowedCpuFrequencies() const; bool setCurrentCpuFrequency(uint index); /** * Returns the available buttons on this device. The number and location * of buttons will vary depending on the device. Button numbers will be assigned * by the device manufacturer and will be from most preferred button to least preffered * button. Note that this list only contains "user mappable" buttons. * * @todo ### make const */ const QValueList<ODeviceButton> &buttons ( ) /** /todo ### make const */; /** * Returns the DeviceButton for the \a keyCode. If \a keyCode is not found, it * returns 0L */ const ODeviceButton *buttonForKeycode ( ushort keyCode ); /** * Reassigns the pressed action for \a button. To return to the factory * default pass an empty string as \a qcopMessage. */ void remapPressedAction ( int button, const OQCopMessage &qcopMessage ); /** * Reassigns the held action for \a button. To return to the factory * default pass an empty string as \a qcopMessage. */ void remapHeldAction ( int button, const OQCopMessage &qcopMessage ); /** * How long (in ms) you have to press a button for a "hold" action */ uint buttonHoldTime ( ) const; signals: void buttonMappingChanged ( ); private slots: void systemMessage ( const QCString &, const QByteArray & ); protected: void reloadButtonMapping ( ); /* ugly virtual hook */ virtual void virtual_hook( int id, void* data ); + +protected: + enum { VIRTUAL_ROTATION = 0x200, VIRTUAL_DIRECTION, + VIRTUAL_HAS_HINGE, VIRTUAL_HINGE }; + struct VirtRotation { + Transformation trans; + }; + struct VirtDirection { + ODirection direct; + }; + struct VirtHasHinge { + bool hasHinge; + }; + struct VirtHingeStatus { + OHingeStatus hingeStat; + }; }; } #endif |