Diffstat (limited to 'noncore/net/opietooth/lib/obexpush.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opietooth/lib/obexpush.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/noncore/net/opietooth/lib/obexpush.cpp b/noncore/net/opietooth/lib/obexpush.cpp new file mode 100644 index 0000000..e0a4bee --- a/dev/null +++ b/noncore/net/opietooth/lib/obexpush.cpp | |||
@@ -0,0 +1,108 @@ | |||
1 | /* $Id$ */ | ||
2 | /* OBEX push functions implementation */ | ||
3 | /*************************************************************************** | ||
4 | * * | ||
5 | * This program is free software; you can redistribute it and/or modify * | ||
6 | * it under the terms of the GNU General Public License as published by * | ||
7 | * the Free Software Foundation; either version 2 of the License, or * | ||
8 | * (at your option) any later version. * | ||
9 | * * | ||
10 | ***************************************************************************/ | ||
11 | #include "obexpush.h" | ||
12 | |||
13 | #include <qfileinfo.h> | ||
14 | #include <qfile.h> | ||
15 | |||
16 | #include <opie2/odebug.h> | ||
17 | #include <opie2/odebug.h> | ||
18 | |||
19 | using namespace Opie::Core; | ||
20 | using namespace OpieTooth; | ||
21 | |||
22 | ObexPush::ObexPush() | ||
23 | { | ||
24 | pushProc = new OProcess(); | ||
25 | connect(pushProc, SIGNAL(processExited(Opie::Core::OProcess*)), | ||
26 | this, SLOT(slotPushExited(Opie::Core::OProcess*))); | ||
27 | connect(pushProc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int)), | ||
28 | this, SLOT(slotPushOut(Opie::Core::OProcess*, char*, int))); | ||
29 | connect(pushProc, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int)), | ||
30 | this, SLOT(slotPushErr(Opie::Core::OProcess*, char*, int))); | ||
31 | |||
32 | } | ||
33 | |||
34 | ObexPush::~ObexPush() | ||
35 | { | ||
36 | if (pushProc->isRunning()) | ||
37 | pushProc->kill(); | ||
38 | delete pushProc; | ||
39 | pushProc = NULL; | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Function that sends a file | ||
44 | * @param mac destination device MAC address | ||
45 | * @param port service port number | ||
46 | * @param src source file name | ||
47 | * @param dst destination file name | ||
48 | * @return 0 on success, -1 on error, 1 if sending process is running | ||
49 | */ | ||
50 | int ObexPush::send(QString& mac, int port, QString& src, QString& dst) | ||
51 | { | ||
52 | QString dev = mac; | ||
53 | QString execName = "ussp-push"; | ||
54 | if (pushProc->isRunning()) | ||
55 | return 1; | ||
56 | pushProc->clearArguments(); | ||
57 | dev += "@"; | ||
58 | dev += QString::number(port); | ||
59 | if (!dst.isEmpty()) | ||
60 | *pushProc << execName << "--timeo 30" << dev | ||
61 | << QFile::encodeName(src) << QFile::encodeName(dst); | ||
62 | else | ||
63 | *pushProc << execName << "--timeo 30" << dev | ||
64 | << QFile::encodeName(src) | ||
65 | << QFile::encodeName(QFileInfo(src).fileName()); | ||
66 | odebug << execName << " " << dev << " " << src << " " | ||
67 | << ((!dst.isEmpty())? dst: QFileInfo(src).fileName()) << oendl; | ||
68 | pushProc->setUseShell(true); | ||
69 | if (!pushProc->start(OProcess::NotifyOnExit, OProcess::All)) | ||
70 | return -1; | ||
71 | else | ||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | void ObexPush::slotPushExited(Opie::Core::OProcess* proc) | ||
76 | { | ||
77 | if (pushProc != proc) | ||
78 | return; | ||
79 | odebug << "Process exited" << oendl; | ||
80 | if (pushProc->normalExit()) | ||
81 | emit sendComplete(pushProc->exitStatus()); | ||
82 | else | ||
83 | emit sendError(-1); | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * Function makes a notification from slotPushOut and slotPushErr | ||
88 | */ | ||
89 | void ObexPush::notifyInfo(Opie::Core::OProcess* proc, char* buf, int len) | ||
90 | { | ||
91 | if (proc != pushProc) | ||
92 | return; | ||
93 | QCString str(buf, len); | ||
94 | odebug << str << oendl; | ||
95 | emit status(str); | ||
96 | } | ||
97 | |||
98 | void ObexPush::slotPushOut(Opie::Core::OProcess* proc, char* buf, int len) | ||
99 | { | ||
100 | notifyInfo(proc, buf, len); | ||
101 | } | ||
102 | |||
103 | void ObexPush::slotPushErr(Opie::Core::OProcess* proc, char* buf, int len) | ||
104 | { | ||
105 | notifyInfo(proc, buf, len); | ||
106 | } | ||
107 | |||
108 | //eof | ||