diff options
Diffstat (limited to 'tools/EventClients/Clients/OSXRemote/xbmcclientwrapper.mm')
-rw-r--r-- | tools/EventClients/Clients/OSXRemote/xbmcclientwrapper.mm | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/tools/EventClients/Clients/OSXRemote/xbmcclientwrapper.mm b/tools/EventClients/Clients/OSXRemote/xbmcclientwrapper.mm index 3bc580e51f..97b2e789f2 100644 --- a/tools/EventClients/Clients/OSXRemote/xbmcclientwrapper.mm +++ b/tools/EventClients/Clients/OSXRemote/xbmcclientwrapper.mm @@ -10,12 +10,12 @@ // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. @@ -31,12 +31,12 @@ class XBMCClientEventSequence{ public: XBMCClientEventSequence(){} - + //implicit conversion XBMCClientEventSequence(eATVClientEvent f_event){ m_stream.push_back(f_event); } - + std::string str() const{ std::stringstream ss; for(std::vector<eATVClientEvent>::const_iterator it = m_stream.begin(); @@ -49,7 +49,7 @@ public: void clear(){ m_stream.clear(); } - + // // operators // @@ -63,7 +63,7 @@ public: } friend bool operator <(XBMCClientEventSequence const& fcr_lhs,XBMCClientEventSequence const& fcr_rhs){ return fcr_lhs.m_stream < fcr_rhs.m_stream; - } + } friend bool operator ==(XBMCClientEventSequence const& fcr_lhs,XBMCClientEventSequence const& fcr_rhs){ return fcr_lhs.m_stream == fcr_rhs.m_stream; } @@ -83,7 +83,7 @@ class XBMCClientWrapperImpl{ tSequenceMap m_sequence_map; tMultiRemoteMap m_multiremote_map; eRemoteMode m_mode; - int m_socket; + int m_socket; std::string m_address; int m_port; XBMCClientEventSequence m_sequence; @@ -109,7 +109,7 @@ public: void switchRemote(int f_device_id){ m_device_id = f_device_id; } - void handleEvent(eATVClientEvent f_event); + void handleEvent(eATVClientEvent f_event); void enableVerboseMode(bool f_value){ m_verbose_mode = f_value; } @@ -122,7 +122,7 @@ void XBMCClientWrapperImpl::timerCallBack (CFRunLoopTimerRef timer, void *info) fprintf(stderr, "Error. invalid argument to timer callback\n"); return; } - + XBMCClientWrapperImpl *p_impl = (XBMCClientWrapperImpl *)info; p_impl->sendSequence(); p_impl->resetTimer(); @@ -136,12 +136,12 @@ void XBMCClientWrapperImpl::resetTimer(){ CFRelease(m_timer); m_timer = NULL; } -} +} void XBMCClientWrapperImpl::restartTimer(){ if (m_timer) - resetTimer(); - + resetTimer(); + CFRunLoopTimerContext context = { 0, this, 0, 0, 0 }; m_timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + m_sequence_timeout, 0, 0, 0, timerCallBack, &context); CFRunLoopAddTimer(CFRunLoopGetCurrent(), m_timer, kCFRunLoopCommonModes); @@ -173,7 +173,7 @@ XBMCClientWrapperImpl::XBMCClientWrapperImpl(eRemoteMode f_mode, const std::stri NSLog(@"XBMCClientWrapperImpl started in normal mode sending to address %s, port %i", fcr_address.c_str(), f_port); populateEventMap(); } - + //open udp port etc m_socket = socket(AF_INET, SOCK_DGRAM, 0); if (m_socket < 0) @@ -185,7 +185,7 @@ XBMCClientWrapperImpl::XBMCClientWrapperImpl(eRemoteMode f_mode, const std::stri namespace { struct delete_second{ - template <class T> + template <class T> void operator ()(T& fr_pair){ delete fr_pair.second; } @@ -208,14 +208,14 @@ void XBMCClientWrapperImpl::sendButton(eATVClientEvent f_event){ if(m_mode == MULTIREMOTE_MODE){ tMultiRemoteMap::iterator it = m_multiremote_map.find(std::make_pair(m_device_id, f_event)); if(it == m_multiremote_map.end()){ - ELOG(@"XBMCClientWrapperImpl::sendButton: No mapping defined for remoteID: %i button %i", m_device_id, f_event); + ELOG(@"XBMCClientWrapperImpl::sendButton: No mapping defined for remoteID: %i button %i", m_device_id, f_event); return; } lp_packet = it->second; } else { tEventMap::iterator it = m_event_map.find(f_event); if(it == m_event_map.end()){ - ELOG(@"XBMCClientWrapperImpl::sendButton: No mapping defined for button %i", f_event); + ELOG(@"XBMCClientWrapperImpl::sendButton: No mapping defined for button %i", f_event); return; } lp_packet = it->second; @@ -224,7 +224,7 @@ void XBMCClientWrapperImpl::sendButton(eATVClientEvent f_event){ CAddress addr(m_address.c_str(), m_port); if(m_verbose_mode) NSLog(@"XBMCClientWrapperImpl::sendButton sending button %i down:%i up:%i", lp_packet->GetButtonCode(), lp_packet->GetFlags()&BTN_DOWN,lp_packet->GetFlags()&BTN_UP ); - lp_packet->Send(m_socket, addr); + lp_packet->Send(m_socket, addr); } void XBMCClientWrapperImpl::sendSequence(){ @@ -232,7 +232,7 @@ void XBMCClientWrapperImpl::sendSequence(){ if(it != m_sequence_map.end()){ CPacketBUTTON& packet = *(it->second); CAddress addr(m_address.c_str()); - packet.Send(m_socket, addr); + packet.Send(m_socket, addr); if(m_verbose_mode) NSLog(@"XBMCClientWrapperImpl::sendSequence sent sequence %i down:%i up:%i", packet.GetButtonCode(), packet.GetFlags()&BTN_DOWN,packet.GetFlags()&BTN_UP ); } else { @@ -241,12 +241,12 @@ void XBMCClientWrapperImpl::sendSequence(){ m_sequence.clear(); } -void XBMCClientWrapperImpl::handleEvent(eATVClientEvent f_event){ +void XBMCClientWrapperImpl::handleEvent(eATVClientEvent f_event){ if(m_mode != UNIVERSAL_MODE){ sendButton(f_event); } else { //in universal mode no keys are directly send. instead a key-sequence is assembled and a timer started - //when the timer expires, that key sequence is checked against predefined sequences and if it is a valid one, + //when the timer expires, that key sequence is checked against predefined sequences and if it is a valid one, //a button press is generated if(m_sequence.str().empty()){ if(isStartToken(f_event)){ @@ -271,7 +271,7 @@ void XBMCClientWrapperImpl::handleEvent(eATVClientEvent f_event){ void XBMCClientWrapperImpl::populateEventMap(){ tEventMap& lr_map = m_event_map; - + lr_map.insert(std::make_pair(ATV_BUTTON_CENTER, new CPacketBUTTON(5, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); lr_map.insert(std::make_pair(ATV_BUTTON_RIGHT, new CPacketBUTTON(4, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); lr_map.insert(std::make_pair(ATV_BUTTON_RIGHT_RELEASE, new CPacketBUTTON(4, "CC:AppleRemote", BTN_UP | BTN_NO_REPEAT | BTN_QUEUE))); @@ -283,12 +283,12 @@ void XBMCClientWrapperImpl::populateEventMap(){ lr_map.insert(std::make_pair(ATV_BUTTON_UP_RELEASE, new CPacketBUTTON(1, "CC:AppleRemote", BTN_UP | BTN_QUEUE))); lr_map.insert(std::make_pair(ATV_BUTTON_DOWN, new CPacketBUTTON(2, "CC:AppleRemote", BTN_DOWN | BTN_QUEUE))); lr_map.insert(std::make_pair(ATV_BUTTON_DOWN_RELEASE, new CPacketBUTTON(2, "CC:AppleRemote", BTN_UP | BTN_QUEUE))); - + // only present on ATV <= 2.1 <--- check that; OSX seems to have the release parts - lr_map.insert(std::make_pair(ATV_BUTTON_RIGHT_H, new CPacketBUTTON(10, "CC:AppleRemote", BTN_DOWN | BTN_QUEUE))); - lr_map.insert(std::make_pair(ATV_BUTTON_RIGHT_H_RELEASE, new CPacketBUTTON(10, "CC:AppleRemote", BTN_UP | BTN_QUEUE))); + lr_map.insert(std::make_pair(ATV_BUTTON_RIGHT_H, new CPacketBUTTON(10, "CC:AppleRemote", BTN_DOWN | BTN_QUEUE))); + lr_map.insert(std::make_pair(ATV_BUTTON_RIGHT_H_RELEASE, new CPacketBUTTON(10, "CC:AppleRemote", BTN_UP | BTN_QUEUE))); lr_map.insert(std::make_pair(ATV_BUTTON_LEFT_H, new CPacketBUTTON(9, "CC:AppleRemote", BTN_DOWN | BTN_QUEUE))); - lr_map.insert(std::make_pair(ATV_BUTTON_LEFT_H_RELEASE, new CPacketBUTTON(9, "CC:AppleRemote", BTN_UP | BTN_QUEUE))); + lr_map.insert(std::make_pair(ATV_BUTTON_LEFT_H_RELEASE, new CPacketBUTTON(9, "CC:AppleRemote", BTN_UP | BTN_QUEUE))); //new aluminium remote buttons lr_map.insert(std::make_pair(ATV_BUTTON_PLAY, new CPacketBUTTON(12, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); @@ -296,7 +296,7 @@ void XBMCClientWrapperImpl::populateEventMap(){ // only present on atv >= 2.2 lr_map.insert(std::make_pair(ATV_BUTTON_CENTER_H, new CPacketBUTTON(7, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); - + //learned remote buttons (ATV >=2.3) lr_map.insert(std::make_pair(ATV_LEARNED_PLAY, new CPacketBUTTON(70, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); lr_map.insert(std::make_pair(ATV_LEARNED_PAUSE, new CPacketBUTTON(71, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); @@ -321,7 +321,7 @@ void XBMCClientWrapperImpl::populateSequenceMap(){ m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_UP, new CPacketBUTTON(23, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_DOWN, new CPacketBUTTON(24, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_MENU, new CPacketBUTTON(25, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); - + sequence_prefix.clear(); sequence_prefix << ATV_BUTTON_MENU_H << ATV_BUTTON_CENTER; m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_CENTER, new CPacketBUTTON(26, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); @@ -330,7 +330,7 @@ void XBMCClientWrapperImpl::populateSequenceMap(){ m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_UP, new CPacketBUTTON(29, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_DOWN, new CPacketBUTTON(30, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_MENU, new CPacketBUTTON(31, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); - + sequence_prefix.clear(); sequence_prefix << ATV_BUTTON_MENU_H << ATV_BUTTON_UP; m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_CENTER, new CPacketBUTTON(32, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); @@ -339,7 +339,7 @@ void XBMCClientWrapperImpl::populateSequenceMap(){ m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_UP, new CPacketBUTTON(35, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_DOWN, new CPacketBUTTON(36, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_MENU, new CPacketBUTTON(37, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); - + sequence_prefix.clear(); sequence_prefix << ATV_BUTTON_MENU_H << ATV_BUTTON_DOWN; m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_CENTER, new CPacketBUTTON(38, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); @@ -348,7 +348,7 @@ void XBMCClientWrapperImpl::populateSequenceMap(){ m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_UP, new CPacketBUTTON(41, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_DOWN, new CPacketBUTTON(42, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_MENU, new CPacketBUTTON(43, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); - + sequence_prefix.clear(); sequence_prefix << ATV_BUTTON_MENU_H << ATV_BUTTON_RIGHT; m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_CENTER, new CPacketBUTTON(44, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); @@ -357,7 +357,7 @@ void XBMCClientWrapperImpl::populateSequenceMap(){ m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_UP, new CPacketBUTTON(47, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_DOWN, new CPacketBUTTON(48, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_MENU, new CPacketBUTTON(49, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); - + sequence_prefix.clear(); sequence_prefix << ATV_BUTTON_MENU_H << ATV_BUTTON_LEFT; m_sequence_map.insert(std::make_pair( sequence_prefix + ATV_BUTTON_CENTER, new CPacketBUTTON(50, "CC:AppleRemote", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); @@ -376,11 +376,11 @@ void XBMCClientWrapperImpl::populateMultiRemoteModeMap(){ { // keymaps for mult-apple-remote, including the device-key sent after remote-switch // we just add them here with unique button numbers and do the real mapping in keymap.xml - // as an offset for the buttons we use the device - + // as an offset for the buttons we use the device + // this loop should probably be replaced by a proper setting of the individual keys // cons: currently only button-codes (aka ints) are sent - // way too lazy ;) + // way too lazy ;) // pro: custom tweaks. e.g. button 1 on the harmony may be (153, ATV_BUTTON_LEFT) and this should not get a repeat // maybe use the loop and tweak individual buttons later; plex maps here to strings, and later in keymap.xml to other strings, // but this may need another kind of remote in XBMC source @@ -388,22 +388,22 @@ void XBMCClientWrapperImpl::populateMultiRemoteModeMap(){ m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_UP_RELEASE), new CPacketBUTTON(1 + offset, "CC:Harmony", BTN_UP | BTN_QUEUE))); m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_DOWN), new CPacketBUTTON(2 + offset, "CC:Harmony", BTN_DOWN | BTN_QUEUE))); m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_DOWN_RELEASE), new CPacketBUTTON(2 + offset, "CC:Harmony", BTN_UP | BTN_QUEUE))); - + m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_LEFT), new CPacketBUTTON(3 + offset, "CC:Harmony", BTN_DOWN | BTN_QUEUE))); m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_LEFT_RELEASE), new CPacketBUTTON(3 + offset, "CC:Harmony", BTN_UP | BTN_QUEUE))); m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_RIGHT), new CPacketBUTTON(4 + offset, "CC:Harmony", BTN_DOWN | BTN_QUEUE))); m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_RIGHT_RELEASE), new CPacketBUTTON(4 + offset, "CC:Harmony", BTN_UP | BTN_QUEUE))); - + m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_CENTER), new CPacketBUTTON(5 + offset, "CC:Harmony", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_MENU), new CPacketBUTTON(6 + offset, "CC:Harmony", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_CENTER_H), new CPacketBUTTON(7 + offset, "CC:Harmony", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_MENU_H), new CPacketBUTTON(8 + offset, "CC:Harmony", BTN_DOWN | BTN_NO_REPEAT | BTN_QUEUE))); - + m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_RIGHT_H), new CPacketBUTTON(9 + offset, "CC:Harmony", BTN_DOWN | BTN_QUEUE))); m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_RIGHT_H_RELEASE),new CPacketBUTTON(9 + offset, "CC:Harmony", BTN_UP | BTN_QUEUE))); - - m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_LEFT_H), new CPacketBUTTON(10 + offset, "CC:Harmony", BTN_DOWN | BTN_QUEUE))); - m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_LEFT_H_RELEASE),new CPacketBUTTON(10 + offset, "CC:Harmony", BTN_UP | BTN_QUEUE))); + + m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_LEFT_H), new CPacketBUTTON(10 + offset, "CC:Harmony", BTN_DOWN | BTN_QUEUE))); + m_multiremote_map.insert(std::make_pair(std::make_pair(*device_id,ATV_BUTTON_LEFT_H_RELEASE),new CPacketBUTTON(10 + offset, "CC:Harmony", BTN_UP | BTN_QUEUE))); } } @@ -413,7 +413,7 @@ void XBMCClientWrapperImpl::populateMultiRemoteModeMap(){ } - (id) initWithMode:(eRemoteMode) f_mode serverAddress:(NSString*) fp_server port:(int) f_port verbose:(bool) f_verbose{ if( ![super init] ) - return nil; + return nil; mp_impl = new XBMCClientWrapperImpl(f_mode, [fp_server UTF8String], f_port, f_verbose); return self; } |