00001 /*************************************************************************** 00002 * Copyright (C) 2005 - 2006 by * 00003 * Erik Jälevik, Last.fm Ltd <erik@last.fm> * 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 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 00021 /*************************************************************************/ 00051 #ifndef SCROBSUBMITTER_H 00052 #define SCROBSUBMITTER_H 00053 00054 #include "BlockingClient.h" 00055 00056 #include <string> 00057 #include <deque> 00058 00059 /*************************************************************************/ 00081 class ScrobSubmitter 00082 { 00083 public: 00084 00085 /*********************************************************************/ 00093 typedef void (*StatusCallback)( 00094 int reqId, 00095 bool error, 00096 std::string msg, 00097 void* userData); 00098 00099 /*********************************************************************/ 00102 enum Encoding 00103 { 00104 ISO_8859_1, // standard Windows western codepage 00105 UTF_8 00106 }; 00107 00108 /*********************************************************************/ 00111 ScrobSubmitter(); 00112 00113 /*********************************************************************/ 00116 virtual 00117 ~ScrobSubmitter(); 00118 00119 /*********************************************************************/ 00131 void 00132 Init( 00133 const std::string& pluginId, 00134 StatusCallback callback, 00135 void* userData); 00136 00137 /*********************************************************************/ 00141 void 00142 Term(); 00143 00144 /*********************************************************************/ 00159 int 00160 Start( 00161 std::string artist, 00162 std::string track, 00163 std::string album, 00164 std::string mbId, 00165 int length, 00166 std::string filename, 00167 Encoding encoding = UTF_8); 00168 00169 /*********************************************************************/ 00175 int 00176 Stop(); 00177 00178 /*********************************************************************/ 00183 int 00184 Pause(); 00185 00186 /*********************************************************************/ 00192 int 00193 Resume(); 00194 00195 /*********************************************************************/ 00200 std::string 00201 GetVersion(); 00202 00203 /*********************************************************************/ 00210 static std::string 00211 GetLogPath(); 00212 00213 private: 00214 00215 /************************************************************************** 00216 Copy ctor private because a CRITICAL_SECTION cannot be copied. 00217 **************************************************************************/ 00218 ScrobSubmitter( 00219 const ScrobSubmitter&); 00220 00221 /************************************************************************** 00222 Sends the command cmd down the socket. 00223 **************************************************************************/ 00224 int 00225 SendToAS( 00226 const std::string& cmd); 00227 00228 /************************************************************************** 00229 Socket thread starter. 00230 **************************************************************************/ 00231 static unsigned __stdcall 00232 SendToASThreadMain( 00233 LPVOID p) 00234 { reinterpret_cast<ScrobSubmitter*>(p)->SendToASThread(); return 0; } 00235 00236 /************************************************************************** 00237 Socket worker thread function. 00238 **************************************************************************/ 00239 void 00240 SendToASThread(); 00241 00242 /************************************************************************** 00243 Connects to AS. Returns true if successful. 00244 **************************************************************************/ 00245 bool 00246 ConnectToAS( 00247 int reqId); 00248 00249 /************************************************************************** 00250 Reports status back to caller through callback. 00251 **************************************************************************/ 00252 void 00253 ReportStatus( 00254 int reqId, 00255 bool error, 00256 const std::string& msg); 00257 00258 /************************************************************************** 00259 Converts the passed in string to UTF-8 from the encoding specified 00260 as the second parameter. 00261 **************************************************************************/ 00262 void 00263 ConvertToUTF8( 00264 std::string& text, 00265 Encoding encoding); 00266 00267 /*********************************************************************/ 00271 std::string& 00272 Escape( 00273 std::string& text); 00274 00275 00276 std::string mPluginId; 00277 00278 int mActualPort; 00279 BlockingClient mSocket; 00280 00281 int mNextId; 00282 std::deque<std::pair<int, std::string> > mRequestQueue; 00283 00284 HANDLE mSocketThread; 00285 HANDLE mRequestAvailable; 00286 HANDLE mExit; 00287 CRITICAL_SECTION mMutex; 00288 bool mStopThread; 00289 00290 StatusCallback mpReportStatus; 00291 void* mpUserData; 00292 00293 DWORD mLaunchTime; 00294 }; 00295 00296 #endif // SCROBSUBMITTER_H
1.5.1