-rw-r--r-- | core/obex/obex.cpp | 3 | ||||
-rw-r--r-- | core/obex/obex.h | 4 |
2 files changed, 1 insertions, 6 deletions
diff --git a/core/obex/obex.cpp b/core/obex/obex.cpp index e4a3c31..670f1a5 100644 --- a/core/obex/obex.cpp +++ b/core/obex/obex.cpp | |||
@@ -1,147 +1,146 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the OPIE Project | 2 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de> | 3 | .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This library is free software; you can | 5 | _;:, .> :=|. This library is free software; you can |
6 | .> <, > . <= redistribute it and/or modify it under | 6 | .> <, > . <= redistribute it and/or modify it under |
7 | :=1 )Y*s>-.-- : the terms of the GNU Library General Public | 7 | :=1 )Y*s>-.-- : the terms of the GNU Library General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; version 2 of the License. | 9 | - . .-<_> .<> Foundation; version 2 of the License. |
10 | ._= =} : | 10 | ._= =} : |
11 | .%+i> _;_. | 11 | .%+i> _;_. |
12 | .i_,=:_. -<s. This library is distributed in the hope that | 12 | .i_,=:_. -<s. This library is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=| MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=| MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>: PARTICULAR PURPOSE. See the GNU | 16 | _.=:. : :=>: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
18 | ++= -. . .: details. | 18 | ++= -. . .: details. |
19 | : = ...= . :.=- | 19 | : = ...= . :.=- |
20 | -. .:....=;==+<; You should have received a copy of the GNU | 20 | -. .:....=;==+<; You should have received a copy of the GNU |
21 | -_. . . )=. = Library General Public License along with | 21 | -_. . . )=. = Library General Public License along with |
22 | -- :-= this library; see the file COPYING.LIB. | 22 | -- :-= this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 23 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 24 | Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | /* | 28 | /* |
29 | * The Infrared OBEX handling class implementation | 29 | * The Infrared OBEX handling class implementation |
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include "obex.h" | 32 | #include "obex.h" |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <opie2/oprocess.h> | 35 | #include <opie2/oprocess.h> |
36 | #include <opie2/odebug.h> | 36 | #include <opie2/odebug.h> |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | #include <qfileinfo.h> | 39 | #include <qfileinfo.h> |
40 | 40 | ||
41 | 41 | ||
42 | 42 | ||
43 | using namespace OpieObex; | 43 | using namespace OpieObex; |
44 | 44 | ||
45 | using namespace Opie::Core; | 45 | using namespace Opie::Core; |
46 | /* TRANSLATOR OpieObex::Obex */ | 46 | /* TRANSLATOR OpieObex::Obex */ |
47 | 47 | ||
48 | Obex::Obex( QObject *parent, const char* name ) | 48 | Obex::Obex( QObject *parent, const char* name ) |
49 | : ObexBase(parent, name ) | 49 | : ObexBase(parent, name ) |
50 | { | 50 | { |
51 | m_rec = 0; | 51 | m_rec = 0; |
52 | m_send=0; | 52 | m_send = 0; |
53 | }; | 53 | }; |
54 | Obex::~Obex() { | 54 | Obex::~Obex() { |
55 | delete m_rec; | 55 | delete m_rec; |
56 | delete m_send; | 56 | delete m_send; |
57 | } | 57 | } |
58 | void Obex::receive() { | 58 | void Obex::receive() { |
59 | ObexBase::receive(); | 59 | ObexBase::receive(); |
60 | m_rec = new ObexServer(OBEX_TRANS_IRDA); | 60 | m_rec = new ObexServer(OBEX_TRANS_IRDA); |
61 | // connect to the necessary slots | 61 | // connect to the necessary slots |
62 | connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), | 62 | connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), |
63 | this, SLOT(slotExited(Opie::Core::OProcess*) ) ); | 63 | this, SLOT(slotExited(Opie::Core::OProcess*) ) ); |
64 | 64 | ||
65 | connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), | 65 | connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), |
66 | this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); | 66 | this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); |
67 | 67 | ||
68 | if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 68 | if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
69 | emit done( false ); | 69 | emit done( false ); |
70 | delete m_rec; | 70 | delete m_rec; |
71 | m_rec = 0; | 71 | m_rec = 0; |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | // if currently receiving stop it send receive | 75 | // if currently receiving stop it send receive |
76 | void Obex::send(const QString& fileName, const QString& addr) { | 76 | void Obex::send(const QString& fileName, const QString& addr) { |
77 | ObexBase::send(fileName, addr); | 77 | ObexBase::send(fileName, addr); |
78 | if (m_rec != 0 ) { | 78 | if (m_rec != 0 ) { |
79 | if (m_rec->isRunning() ) { | 79 | if (m_rec->isRunning() ) { |
80 | emit error(-1 ); | 80 | emit error(-1 ); |
81 | delete m_rec; | 81 | delete m_rec; |
82 | m_rec = 0; | 82 | m_rec = 0; |
83 | |||
84 | }else{ | 83 | }else{ |
85 | emit error( -1 ); // we did not delete yet but it's not running slotExited is pending | 84 | emit error( -1 ); // we did not delete yet but it's not running slotExited is pending |
86 | return; | 85 | return; |
87 | } | 86 | } |
88 | } | 87 | } |
89 | sendNow(); | 88 | sendNow(); |
90 | } | 89 | } |
91 | void Obex::sendNow(){ | 90 | void Obex::sendNow(){ |
92 | if ( m_count >= 25 ) { // could not send | 91 | if ( m_count >= 25 ) { // could not send |
93 | emit error(-1 ); | 92 | emit error(-1 ); |
94 | emit sent(false); | 93 | emit sent(false); |
95 | return; | 94 | return; |
96 | } | 95 | } |
97 | // OProcess inititialisation | 96 | // OProcess inititialisation |
98 | m_send = new OProcess(); | 97 | m_send = new OProcess(); |
99 | m_send->setWorkingDirectory( QFileInfo(m_file).dirPath(true) ); | 98 | m_send->setWorkingDirectory( QFileInfo(m_file).dirPath(true) ); |
100 | 99 | ||
101 | *m_send << "irobex_palm3"; | 100 | *m_send << "irobex_palm3"; |
102 | *m_send << QFile::encodeName(QFileInfo(m_file).fileName()); | 101 | *m_send << QFile::encodeName(QFileInfo(m_file).fileName()); |
103 | 102 | ||
104 | // connect to slots Exited and and StdOut | 103 | // connect to slots Exited and and StdOut |
105 | connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ), | 104 | connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ), |
106 | this, SLOT(slotExited(Opie::Core::OProcess*)) ); | 105 | this, SLOT(slotExited(Opie::Core::OProcess*)) ); |
107 | connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int )), | 106 | connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int )), |
108 | this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); | 107 | this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); |
109 | 108 | ||
110 | // now start it | 109 | // now start it |
111 | if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) { | 110 | if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) { |
112 | m_count = 25; | 111 | m_count = 25; |
113 | emit error(-1 ); | 112 | emit error(-1 ); |
114 | delete m_send; | 113 | delete m_send; |
115 | m_send=0; | 114 | m_send=0; |
116 | } | 115 | } |
117 | // end | 116 | // end |
118 | m_count++; | 117 | m_count++; |
119 | emit currentTry( m_count ); | 118 | emit currentTry( m_count ); |
120 | } | 119 | } |
121 | 120 | ||
122 | void Obex::slotExited(OProcess* proc ){ | 121 | void Obex::slotExited(OProcess* proc ){ |
123 | if (proc == m_rec ) // receive process | 122 | if (proc == m_rec ) // receive process |
124 | received(); | 123 | received(); |
125 | else if ( proc == m_send ) | 124 | else if ( proc == m_send ) |
126 | sendEnd(); | 125 | sendEnd(); |
127 | 126 | ||
128 | } | 127 | } |
129 | void Obex::slotStdOut(OProcess* proc, char* buf, int len){ | 128 | void Obex::slotStdOut(OProcess* proc, char* buf, int len){ |
130 | if ( proc == m_rec ) { // only receive | 129 | if ( proc == m_rec ) { // only receive |
131 | QByteArray ar( len ); | 130 | QByteArray ar( len ); |
132 | memcpy( ar.data(), buf, len ); | 131 | memcpy( ar.data(), buf, len ); |
133 | m_outp.append( ar ); | 132 | m_outp.append( ar ); |
134 | } | 133 | } |
135 | } | 134 | } |
136 | 135 | ||
137 | void Obex::received() { | 136 | void Obex::received() { |
138 | if (m_rec->normalExit() ) { | 137 | if (m_rec->normalExit() ) { |
139 | if ( m_rec->exitStatus() == 0 ) { // we got one | 138 | if ( m_rec->exitStatus() == 0 ) { // we got one |
140 | QString filename = parseOut(); | 139 | QString filename = parseOut(); |
141 | emit receivedFile( filename ); | 140 | emit receivedFile( filename ); |
142 | } | 141 | } |
143 | }else{ | 142 | }else{ |
144 | emit done(false); | 143 | emit done(false); |
145 | }; | 144 | }; |
146 | delete m_rec; | 145 | delete m_rec; |
147 | m_rec = 0; | 146 | m_rec = 0; |
diff --git a/core/obex/obex.h b/core/obex/obex.h index b948ce4..745f1c2 100644 --- a/core/obex/obex.h +++ b/core/obex/obex.h | |||
@@ -20,96 +20,92 @@ | |||
20 | -. .:....=;==+<; You should have received a copy of the GNU | 20 | -. .:....=;==+<; You should have received a copy of the GNU |
21 | -_. . . )=. = Library General Public License along with | 21 | -_. . . )=. = Library General Public License along with |
22 | -- :-= this library; see the file COPYING.LIB. | 22 | -- :-= this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 23 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 24 | Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | /* | 28 | /* |
29 | * The Infrared OBEX handling class declaration | 29 | * The Infrared OBEX handling class declaration |
30 | */ | 30 | */ |
31 | 31 | ||
32 | #ifndef OpieObex_H | 32 | #ifndef OpieObex_H |
33 | #define OpieObex_H | 33 | #define OpieObex_H |
34 | 34 | ||
35 | #include "obexbase.h" | 35 | #include "obexbase.h" |
36 | #include <qobject.h> | 36 | #include <qobject.h> |
37 | #include "obexserver.h" | 37 | #include "obexserver.h" |
38 | 38 | ||
39 | namespace Opie {namespace Core {class OProcess;}} | 39 | namespace Opie {namespace Core {class OProcess;}} |
40 | class QCopChannel; | 40 | class QCopChannel; |
41 | namespace OpieObex { | 41 | namespace OpieObex { |
42 | class Obex : public ObexBase { | 42 | class Obex : public ObexBase { |
43 | Q_OBJECT | 43 | Q_OBJECT |
44 | public: | 44 | public: |
45 | /** | 45 | /** |
46 | * Obex c'tor look | 46 | * Obex c'tor look |
47 | */ | 47 | */ |
48 | Obex( QObject *parent, const char* name); | 48 | Obex( QObject *parent, const char* name); |
49 | /** | 49 | /** |
50 | * d'tor | 50 | * d'tor |
51 | */ | 51 | */ |
52 | ~Obex(); | 52 | ~Obex(); |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Starting listening to irda after enabled by the applet | 55 | * Starting listening to irda after enabled by the applet |
56 | * a signal gets emitted when received a file | 56 | * a signal gets emitted when received a file |
57 | */ | 57 | */ |
58 | virtual void receive(); | 58 | virtual void receive(); |
59 | virtual void send(const QString& filename, const QString& addr); | 59 | virtual void send(const QString& filename, const QString& addr); |
60 | virtual void setReceiveEnabled( bool = false ); | 60 | virtual void setReceiveEnabled( bool = false ); |
61 | signals: | 61 | signals: |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * a signal | 64 | * a signal |
65 | * @param path The path to the received file | 65 | * @param path The path to the received file |
66 | */ | 66 | */ |
67 | void receivedFile( const QString& path); | 67 | void receivedFile( const QString& path); |
68 | /** | 68 | /** |
69 | * error signal if the program couldn't be started or the | 69 | * error signal if the program couldn't be started or the |
70 | * the connection timed out | 70 | * the connection timed out |
71 | */ | 71 | */ |
72 | void error( int ); | 72 | void error( int ); |
73 | /** | 73 | /** |
74 | * The current try to receive data | 74 | * The current try to receive data |
75 | */ | 75 | */ |
76 | void currentTry(unsigned int); | 76 | void currentTry(unsigned int); |
77 | /** | 77 | /** |
78 | * signal sent The file got beamed to the remote location | 78 | * signal sent The file got beamed to the remote location |
79 | */ | 79 | */ |
80 | void sent(bool); | 80 | void sent(bool); |
81 | void done(bool); | 81 | void done(bool); |
82 | 82 | ||
83 | private: | 83 | private: |
84 | uint m_count; | ||
85 | QString m_file; | ||
86 | QString m_outp; | ||
87 | Opie::Core::OProcess *m_send; | 84 | Opie::Core::OProcess *m_send; |
88 | ObexServer* m_rec; //The OBEX server | 85 | ObexServer* m_rec; //The OBEX server |
89 | bool m_receive : 1; | ||
90 | void shutDownReceive(); | 86 | void shutDownReceive(); |
91 | 87 | ||
92 | private slots: | 88 | private slots: |
93 | 89 | ||
94 | /** | 90 | /** |
95 | * send over palm obex | 91 | * send over palm obex |
96 | */ | 92 | */ |
97 | 93 | ||
98 | //void send(const QString&); | 94 | //void send(const QString&); |
99 | 95 | ||
100 | // the process exited | 96 | // the process exited |
101 | void slotExited(Opie::Core::OProcess* proc) ; | 97 | void slotExited(Opie::Core::OProcess* proc) ; |
102 | void slotStdOut(Opie::Core::OProcess*, char*, int); | 98 | void slotStdOut(Opie::Core::OProcess*, char*, int); |
103 | virtual void slotError(); | 99 | virtual void slotError(); |
104 | 100 | ||
105 | private: | 101 | private: |
106 | void sendNow(); | 102 | void sendNow(); |
107 | QString parseOut(); | 103 | QString parseOut(); |
108 | void received(); | 104 | void received(); |
109 | void sendEnd(); | 105 | void sendEnd(); |
110 | 106 | ||
111 | }; | 107 | }; |
112 | }; | 108 | }; |
113 | 109 | ||
114 | 110 | ||
115 | #endif | 111 | #endif |