Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OTDriverList.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Mattia Merzi                                    *
00003  *   ottobit@ferrara.linux.it                                              *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include <malloc.h>
00012 #include <bluezlib.h>
00013 
00014 #include <opie2/odebug.h>
00015 
00016 #include <OTDriverList.h>
00017 #include <OTGateway.h>
00018 #include <OTDriver.h>
00019 
00020 using namespace Opietooth2;
00021 
00022 OTDriverList::OTDriverList( OTGateway * _OT ) : QVector<OTDriver>() {
00023 
00024     OT = _OT;
00025     setAutoDelete( true );
00026 }
00027 
00028 OTDriverList::~OTDriverList() {
00029 }
00030 
00031 void OTDriverList::update() {
00032 
00033     struct hci_dev_list_req *dl;
00034     struct hci_dev_req *dr;
00035     struct hci_dev_info di;
00036     int cur;
00037 
00038     dl = 0;
00039     cur = 0;
00040     do {
00041       cur += 5;
00042 
00043       dl = (struct hci_dev_list_req*)
00044           ::realloc( dl, sizeof( struct hci_dev_list_req ) +
00045                        ( cur * sizeof(struct hci_dev_req) )
00046                  );
00047 
00048       if( dl == 0 ) {
00049         // memory problem
00050         exit(1);
00051       }
00052 
00053       dl->dev_num = cur;
00054 
00055       if( ioctl( OT->getSocket(), HCIGETDEVLIST, (void*)dl) ) {
00056         odebug << "WARNING : cannot read device list. "
00057               << errno 
00058               << strerror( errno ) << oendl;
00059         return;
00060       }
00061 
00062       // if num == cur perhaps we did not get all devices yet
00063     } while( dl->dev_num == cur );
00064 
00065     if( dl->dev_num != count() ) {
00066       // new or missing devices
00067       clear();
00068 
00069       dr = dl->dev_req;
00070       resize( dl->dev_num );
00071 
00072       for( cur=0; cur < dl->dev_num; cur ++) {
00073           memset( &di, 0, sizeof( di ) );
00074           di.dev_id = (dr+cur)->dev_id;
00075 
00076           // get device info 
00077           if( ioctl( OT->getSocket(), HCIGETDEVINFO, (void*)&di) != 0 )
00078               continue;  // uh ?
00079           insert( cur, new OTDriver( OT, &di ) );
00080       }
00081 
00082       odebug << "Found " << count() << " devices" << oendl;
00083 
00084       ::free( dl );
00085     }
00086 }

Generated on Sat Nov 5 16:17:55 2005 for OPIE by  doxygen 1.4.2