RFCOMMServer.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2006 Baylor University
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef _OASYS_RFCOMM_SERVER_H_
00018 #define _OASYS_RFCOMM_SERVER_H_
00019 
00020 #include "config.h"
00021 
00022 #ifdef OASYS_BLUETOOTH_ENABLED
00023 
00024 #include "BluetoothServer.h"
00025 #include "../thread/Thread.h"
00026 
00027 namespace oasys {
00028 
00029 class RFCOMMServer : public BluetoothServer {
00030 public:
00031     RFCOMMServer(char* logbase = "/rfcommserver")
00032     : BluetoothServer(SOCK_STREAM,BluetoothSocket::RFCOMM,logbase)
00033     {
00034     }
00035 };
00036 
00037 class RFCOMMServerThread : public BluetoothServerThread {
00038 public:
00039     RFCOMMServerThread(char * logbase = "/rfcommserver", int flags = 0)
00040     : BluetoothServerThread(SOCK_STREAM,
00041                      BluetoothSocket::RFCOMM,
00042                      "oasys::RFCOMMServerThread",
00043                      logbase,
00044                      flags)
00045     {
00046     }
00047 
00048     void set_accept_timeout(int ms) {
00049         accept_timeout_ = ms;
00050     }
00051 
00052 
00053     int rc_bind() {
00054         int res = -1;
00055         for (channel_ = 1; channel_ <= 30; channel_++) {
00056             if ((res = bind()) != 0) {
00057 
00058                 // something is borked
00059                 if (errno != EADDRINUSE) {
00060                     log_err("error binding to %s:%d: %s",
00061                             bd2str(local_addr_), channel_, strerror(errno));
00062                     if (errno == EBADFD) close();
00063                     return res;
00064                 }
00065             } else {
00066 
00067                 // bind succeeded
00068                 return res;
00069             }
00070 
00071         }
00072 
00073         log_err("Scanned all local RFCOMM channels but unable to bind to %s",
00074                 bd2str(local_addr_));
00075         return -1;
00076     }
00077 };
00078 
00079 } // namespace oasys
00080 
00081 #endif /* OASYS_BLUETOOTH_ENABLED */
00082 #endif /* _OASYS_RFCOMM_SERVER_H_ */

Generated on Thu Jun 7 12:54:29 2007 for DTN Reference Implementation by  doxygen 1.5.1