From 5521b2c0508cf6e6a390bd4796e8c9f2c7a6d05f Mon Sep 17 00:00:00 2001 From: korovkin Date: Wed, 10 May 2006 13:32:46 +0000 Subject: OBEX push functionality moved to libbluetooth1. Made some reformatting in device.cc In bluezapplet.cpp /etc/init.d/bluetooth is started synchronously if it's called from QCopMessage. --- (limited to 'noncore/net/opietooth/lib') diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index 40acbd2..2f04d46 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc @@ -16,33 +16,31 @@ using namespace OpieTooth; using Opie::Core::OProcess; namespace { - int parsePid( const QCString& par ) - { - int id=0; - QString string( par ); - QStringList list = QStringList::split( '\n', string ); + int parsePid( const QCString& par ) + { + int id = 0; + QString string( par ); + QStringList list = QStringList::split( '\n', string ); - for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) - { - owarn << "parsePID: " << (*it).latin1() << oendl; + for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { + owarn << "parsePID: " << (*it).latin1() << oendl; - // FIXME mbhaynie: Surely there is a better way to skip - // verbosity (E.g. the TI device configuration - // script). Apparently the PID is always on a line by - // itself, or is at least the first word of a line. Does - // QString have somethine like startsWithRegex("[0-9]+")? - if( (*it).startsWith("#") ) continue; - if( (*it).startsWith("TI") ) continue; - if( (*it).startsWith("Loading") ) continue; - if( (*it).startsWith("BTS") ) continue; - if( !(*it).startsWith("CSR") ) - { - id = (*it).toInt(); - break; - } - } - return id; + // FIXME mbhaynie: Surely there is a better way to skip + // verbosity (E.g. the TI device configuration + // script). Apparently the PID is always on a line by + // itself, or is at least the first word of a line. Does + // QString have somethine like startsWithRegex("[0-9]+")? + if( (*it).startsWith("#") ) continue; + if( (*it).startsWith("TI") ) continue; + if( (*it).startsWith("Loading") ) continue; + if( (*it).startsWith("BTS") ) continue; + if( !(*it).startsWith("CSR") ) { + id = (*it).toInt(); + break; + } } + return id; + } } Device::Device(const QString &device, const QString &mode, const QString &speed ) @@ -75,13 +73,9 @@ void Device::attach(){ // FIXME -- this is a hack for an odd hciattach interface. if ( ODevice::inst()->modelString() == "HX4700" ) - { - *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas"; - } + *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas"; else - { - *m_process << m_device << m_mode << m_speed; - } + *m_process << m_device << m_mode << m_speed; connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), @@ -93,16 +87,18 @@ void Device::attach(){ delete m_process; m_process = 0; } - }; + } } void Device::detach(){ delete m_hci; + m_hci = 0; delete m_process; + m_process = 0; // kill the pid we got if(m_attached ){ //kill the pid owarn << "killing" << oendl; - kill(pid, 9); + ::kill(pid, 9); } owarn << "detached" << oendl; } @@ -121,27 +117,27 @@ void Device::slotExited( OProcess* proc) owarn << "normalExit" << oendl; int ret = m_process->exitStatus(); if( ret == 0 ){ // attached - owarn << "attached" << oendl; - owarn << "Output: " << m_output.data() << oendl; - pid = parsePid( m_output ); - owarn << "Pid = " << pid << oendl; - // now hciconfig hci0 up ( determine hciX FIXME) - // and call hciconfig hci0 up - // FIXME hardcoded to hci0 now :( - m_hci = new OProcess( ); - *m_hci << "hciconfig"; - *m_hci << "hci0 up"; - connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), + owarn << "attached" << oendl; + owarn << "Output: " << m_output.data() << oendl; + pid = parsePid( m_output ); + owarn << "Pid = " << pid << oendl; + // now hciconfig hci0 up ( determine hciX FIXME) + // and call hciconfig hci0 up + // FIXME hardcoded to hci0 now :( + m_hci = new OProcess( ); + *m_hci << "hciconfig"; + *m_hci << "hci0 up"; + connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); - if(!m_hci->start() ){ - owarn << "could not start" << oendl; - m_attached = false; - emit device("hci0", false ); - } + if(!m_hci->start() ){ + owarn << "could not start" << oendl; + m_attached = false; + emit device("hci0", false ); + } }else{ owarn << "crass" << oendl; - m_attached = false; - emit device("hci0", false ); + m_attached = false; + emit device("hci0", false ); } } @@ -153,13 +149,13 @@ void Device::slotExited( OProcess* proc) owarn << "normal exit" << oendl; int ret = m_hci->exitStatus(); if( ret == 0 ){ - owarn << "attached really really attached" << oendl; - m_attached = true; - emit device("hci0", true ); + owarn << "attached really really attached" << oendl; + m_attached = true; + emit device("hci0", true ); }else{ - owarn << "failed" << oendl; - emit device("hci0", false ); - m_attached = false; + owarn << "failed" << oendl; + emit device("hci0", false ); + m_attached = false; } }// normal exit delete m_hci; diff --git a/noncore/net/opietooth/lib/lib.pro b/noncore/net/opietooth/lib/lib.pro index 781bf15..e11af9a 100644 --- a/noncore/net/opietooth/lib/lib.pro +++ b/noncore/net/opietooth/lib/lib.pro @@ -1,9 +1,12 @@ TEMPLATE = lib CONFIG += qte warn_on HEADERS = connection.h parser.h device.h manager.h remotedevice.h services.h \ - startpanconnection.h startdunconnection.h bt-serial.h forwarder.h + startpanconnection.h startdunconnection.h obexpush.h \ + bt-serial.h forwarder.h SOURCES = connection.cpp parser.cc device.cc manager.cc remotedevice.cc services.cc \ - startpanconnection.cpp startdunconnection.cpp bt-serial.c forwarder.cc + startpanconnection.cpp startdunconnection.cpp obexpush.cpp \ + bt-serial.c forwarder.cc + TARGET = opietooth1 INCLUDEPATH += $(OPIEDIR)/include . DESTDIR = $(OPIEDIR)/lib 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 @@ +/* $Id$ */ +/* OBEX push functions implementation */ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include "obexpush.h" + +#include +#include + +#include +#include + +using namespace Opie::Core; +using namespace OpieTooth; + +ObexPush::ObexPush() +{ + pushProc = new OProcess(); + connect(pushProc, SIGNAL(processExited(Opie::Core::OProcess*)), + this, SLOT(slotPushExited(Opie::Core::OProcess*))); + connect(pushProc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int)), + this, SLOT(slotPushOut(Opie::Core::OProcess*, char*, int))); + connect(pushProc, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int)), + this, SLOT(slotPushErr(Opie::Core::OProcess*, char*, int))); + +} + +ObexPush::~ObexPush() +{ + if (pushProc->isRunning()) + pushProc->kill(); + delete pushProc; + pushProc = NULL; +} + +/** + * Function that sends a file + * @param mac destination device MAC address + * @param port service port number + * @param src source file name + * @param dst destination file name + * @return 0 on success, -1 on error, 1 if sending process is running + */ +int ObexPush::send(QString& mac, int port, QString& src, QString& dst) +{ + QString dev = mac; + QString execName = "ussp-push"; + if (pushProc->isRunning()) + return 1; + pushProc->clearArguments(); + dev += "@"; + dev += QString::number(port); + if (!dst.isEmpty()) + *pushProc << execName << "--timeo 30" << dev + << QFile::encodeName(src) << QFile::encodeName(dst); + else + *pushProc << execName << "--timeo 30" << dev + << QFile::encodeName(src) + << QFile::encodeName(QFileInfo(src).fileName()); + odebug << execName << " " << dev << " " << src << " " + << ((!dst.isEmpty())? dst: QFileInfo(src).fileName()) << oendl; + pushProc->setUseShell(true); + if (!pushProc->start(OProcess::NotifyOnExit, OProcess::All)) + return -1; + else + return 0; +} + +void ObexPush::slotPushExited(Opie::Core::OProcess* proc) +{ + if (pushProc != proc) + return; + odebug << "Process exited" << oendl; + if (pushProc->normalExit()) + emit sendComplete(pushProc->exitStatus()); + else + emit sendError(-1); +} + +/** + * Function makes a notification from slotPushOut and slotPushErr + */ +void ObexPush::notifyInfo(Opie::Core::OProcess* proc, char* buf, int len) +{ + if (proc != pushProc) + return; + QCString str(buf, len); + odebug << str << oendl; + emit status(str); +} + +void ObexPush::slotPushOut(Opie::Core::OProcess* proc, char* buf, int len) +{ + notifyInfo(proc, buf, len); +} + +void ObexPush::slotPushErr(Opie::Core::OProcess* proc, char* buf, int len) +{ + notifyInfo(proc, buf, len); +} + +//eof diff --git a/noncore/net/opietooth/lib/obexpush.h b/noncore/net/opietooth/lib/obexpush.h new file mode 100644 index 0000000..8147643 --- a/dev/null +++ b/noncore/net/opietooth/lib/obexpush.h @@ -0,0 +1,77 @@ +/* $Id$ */ +/* OBEX push functions declarations */ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef _OBEXPUSH_H_ +#define _OBEXPUSH_H_ +#include +#include +#include "services.h" +#include +namespace OpieTooth { + class ObexPush : public QObject { + Q_OBJECT + public: + /** + * Constructor which creates an object + */ + ObexPush(); + + /** + * Public destructor + */ + ~ObexPush(); + + /** + * Function that sends a file + * @param mac destination device MAC address + * @param port service port number + * @param src source file name + * @param dst destination file name + * @return 0 on success, -1 on error, 1 if sending process is running + */ + int send(QString& mac, int port, QString& src, QString& dst); + + /** + * @return true if it's sending and false otherwise + */ + bool isSending() { return pushProc->isRunning(); } + signals: + /** + * Informs that the sending process has completed + * @param status the finish status + */ + void sendComplete(int); + + /** + * Informs that the sending process has finished with error + * @param status the finish status + */ + void sendError(int); + + /** + * Informs that we have a string status update + * @param str status string + */ + void status(QCString&); + protected slots: + void slotPushOut(Opie::Core::OProcess*, char*, int); + void slotPushErr(Opie::Core::OProcess*, char*, int); + void slotPushExited(Opie::Core::OProcess* proc); + protected: + /** + * Function makes a notification from slotPushOut and slotPushErr + */ + void notifyInfo(Opie::Core::OProcess*, char*, int); + protected: + Opie::Core::OProcess* pushProc; //The push process + }; +}; +#endif +//eof -- cgit v0.9.0.2