25 #include "AampcliVirtualChannelMap.h"
31 if( !channelInfo.name.empty() )
33 if( !channelInfo.uri.empty() )
35 if( !VIRTUAL_CHANNEL_VALID(channelInfo.channelNumber) )
37 channelInfo.channelNumber = mAutoChannelNumber+1;
40 if (isPresent(channelInfo) ==
true)
44 mAutoChannelNumber = channelInfo.channelNumber;
47 mVirtualChannelMap.push_back(channelInfo);
53 for (std::list<VirtualChannelInfo>::iterator it = mVirtualChannelMap.begin(); it != mVirtualChannelMap.end(); ++it)
56 if (channelNumber == existingChannelInfo.channelNumber)
58 found = &existingChannelInfo;
66 for (std::list<VirtualChannelInfo>::iterator it = mVirtualChannelMap.begin(); it != mVirtualChannelMap.end(); ++it)
69 if(channelInfo.channelNumber == existingChannelInfo.channelNumber)
71 printf(
"[AAMPCLI] duplicate channel number: %d: '%s'\n", channelInfo.channelNumber, channelInfo.uri.c_str() );
74 if(channelInfo.uri == existingChannelInfo.uri )
76 printf(
"[AAMPCLI] duplicate URL: %d: '%s'\n", channelInfo.channelNumber, channelInfo.uri.c_str() );
90 bool prevFound =
false;
93 if (mCurrentlyTunedChannel == 0 && mVirtualChannelMap.size() > 0)
98 for(std::list<VirtualChannelInfo>::reverse_iterator it = mVirtualChannelMap.rbegin(); it != mVirtualChannelMap.rend(); ++it)
101 if (VIRTUAL_CHANNEL_VALID(existingChannelInfo.channelNumber) )
103 if ( pLastChannel == NULL )
105 pLastChannel = &existingChannelInfo;
109 pPrevChannel = &existingChannelInfo;
112 else if ( existingChannelInfo.channelNumber == mCurrentlyTunedChannel )
118 if (prevFound && pPrevChannel == NULL)
120 pPrevChannel = pLastChannel;
129 bool nextFound =
false;
132 if (mCurrentlyTunedChannel == 0 && mVirtualChannelMap.size() > 0)
137 for (std::list<VirtualChannelInfo>::iterator it = mVirtualChannelMap.begin(); it != mVirtualChannelMap.end(); ++it)
140 if (VIRTUAL_CHANNEL_VALID(existingChannelInfo.channelNumber) )
142 if ( pFirstChannel == NULL )
144 pFirstChannel = &existingChannelInfo;
148 pNextChannel = &existingChannelInfo;
151 else if ( existingChannelInfo.channelNumber == mCurrentlyTunedChannel )
157 if (nextFound && pNextChannel == NULL)
159 pNextChannel = pFirstChannel;
164 void VirtualChannelMap::print()
166 if (mVirtualChannelMap.empty())
171 printf(
"[AAMPCLI] aampcli.cfg virtual channel map:\n");
174 for (std::list<VirtualChannelInfo>::iterator it = mVirtualChannelMap.begin(); it != mVirtualChannelMap.end(); ++it )
177 std::string channelName = pChannelInfo.name.c_str();
178 size_t len = channelName.length();
183 channelName = channelName.substr(0,len);
185 if( pChannelInfo.uri.empty() )
191 printf(
"%s\n", channelName.c_str() );
195 printf(
"%4d: %s", pChannelInfo.channelNumber, channelName.c_str() );
203 while( len<maxNameLen )
214 void VirtualChannelMap::setCurrentlyTunedChannel(
int value)
216 mCurrentlyTunedChannel = value;
219 void VirtualChannelMap::showList(
void)
221 printf(
"******************************************************************************************\n");
222 printf(
"* Virtual Channel Map\n");
223 printf(
"******************************************************************************************\n");
229 setCurrentlyTunedChannel(channel.channelNumber);
230 const char *name = channel.name.c_str();
231 const char *locator = channel.uri.c_str();
232 printf(
"TUNING to '%s' %s\n", name, locator );
233 playerInstanceAamp->
Tune(locator);
236 std::string VirtualChannelMap::getNextFieldFromCSV(
const char **pptr )
238 const char *ptr = *pptr;
239 const char *delim = ptr;
240 const char *next = ptr;
242 if (!isprint(*ptr) && *ptr !=
'\0')
244 while (!isprint(*ptr) && *ptr !=
'\0')
254 delim = strchr(ptr,
'\"');
266 while( *delim >=
' ' && *delim !=
',' && *delim !=
'\0')
273 if( *next==
',' ) next++;
276 return std::string(ptr,delim-ptr);
279 void VirtualChannelMap::loadVirtualChannelMapFromCSV( FILE *f )
281 char buf[MAX_BUFFER_LENGTH];
282 while (fgets(buf,
sizeof(buf), f))
285 const char *ptr = buf;
286 std::string channelNumber = getNextFieldFromCSV( &ptr );
288 channelInfo.channelNumber = atoi(channelNumber.c_str());
289 channelInfo.name = getNextFieldFromCSV(&ptr);
290 channelInfo.uri = getNextFieldFromCSV(&ptr);
291 if (!channelInfo.name.empty() && !channelInfo.uri.empty())
309 char buf[MAX_BUFFER_LENGTH];
310 while (fgets(buf,
sizeof(buf), f))
312 const char *ptr = buf;
313 ptr = skipwhitespace(ptr);
321 ptr = skipwhitespace(ptr+1);
330 channelInfo.channelNumber = atoi(ptr);
331 while( *ptr>=
'0' && *ptr<=
'9' ) ptr++;
332 ptr = skipwhitespace(ptr);
335 const char *delim = ptr;
340 channelInfo.name = std::string(ptr,delim-ptr);
343 ptr = skipwhitespace(delim);
349 channelInfo.uri = std::string(ptr,delim-ptr);
355 const char *VirtualChannelMap::skipwhitespace(
const char *ptr )
357 while( *ptr==
' ' ) ptr++;