1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
22 #include "tizen_log.h"
23 #include "tizen_CbleDevice.h"
25 #define TIME_LIMITE 5 // unit : second
27 CbleDevice::CbleDevice() : time_count(0) { clear(); }
28 CbleDevice::~CbleDevice() { clear(); }
30 int CbleDevice::insert( CbleDevice::ble_value *discovery_info )
33 std::string addr = std::string(discovery_info->remote_address);
35 if ( find(addr) == false )
37 device[addr] = *discovery_info;
39 device[addr].remote_address = new char[ strlen(discovery_info->remote_address) + 1 ];
40 strcpy( device[addr].remote_address, discovery_info->remote_address);
41 device[addr].remote_name = new char[ strlen(discovery_info->remote_name) + 1 ];
42 strcpy( device[addr].remote_name, discovery_info->remote_name);
43 device[addr].service_uuid = NULL;
44 device[addr].service_count = 0;
50 CbleDevice::ble_value *CbleDevice::getNext( int seq )
53 CbleDeviceMAP::iterator itr = device.begin();
55 if ( seq < 0 || seq >= device.size())
67 DBG("return %s pointer", itr->second.remote_address );
72 int CbleDevice::setRSSI( std::string addr, int rssi )
75 CbleDeviceMAP::iterator itr = device.find( addr );
77 if ( itr == device.end() )
80 ble_value *pdevice = &itr->second;
84 pdevice->service_count = NULL;
87 else if ( pdevice->service_count == NULL )
89 pdevice->service_count = 1;
98 CbleDevice::ble_value *CbleDevice::get( std::string addr )
101 CbleDeviceMAP::iterator itr = device.find( addr );
103 if ( itr == device.end() )
109 bool CbleDevice::find( std::string addr )
112 CbleDeviceMAP::iterator itr = device.find( addr );
114 if ( itr == device.end() )
120 int CbleDevice::size( void )
123 return device.size();
126 void CbleDevice::erase( CbleDeviceMAP::iterator itr )
128 ble_value *value = &itr->second;
130 if ( value->remote_address )
131 delete value->remote_address;
132 if ( value->remote_name )
133 delete value->remote_name;
134 if ( value->service_uuid )
135 delete [] value->service_uuid;
140 void CbleDevice::clear( void )
142 CbleDeviceMAP::iterator itr = device.begin();
144 if ( itr != device.end() )
151 bool CbleDevice::isTimeOut( void )
154 if ( time_count > TIME_LIMITE )