瀏覽代碼

2010-03-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Use gid_t type for gid.
	* src/BtRegistry.cc
	* src/BtRegistry.h
	* src/DownloadResult.h
	* src/RequestGroup.cc
	* src/RequestGroup.h
	* src/RequestGroupMan.cc
	* src/RequestGroupMan.h
	* src/XmlRpcMethodImpl.cc
Tatsuhiro Tsujikawa 15 年之前
父節點
當前提交
322a0d1ad7
共有 9 個文件被更改,包括 72 次插入58 次删除
  1. 12 0
      ChangeLog
  2. 6 6
      src/BtRegistry.cc
  3. 7 6
      src/BtRegistry.h
  4. 7 6
      src/DownloadResult.h
  5. 2 2
      src/RequestGroup.cc
  6. 11 9
      src/RequestGroup.h
  7. 7 8
      src/RequestGroupMan.cc
  8. 6 7
      src/RequestGroupMan.h
  9. 14 14
      src/XmlRpcMethodImpl.cc

+ 12 - 0
ChangeLog

@@ -1,3 +1,15 @@
+2010-03-20  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Use gid_t type for gid.
+	* src/BtRegistry.cc
+	* src/BtRegistry.h
+	* src/DownloadResult.h
+	* src/RequestGroup.cc
+	* src/RequestGroup.h
+	* src/RequestGroupMan.cc
+	* src/RequestGroupMan.h
+	* src/XmlRpcMethodImpl.cc
+
 2010-03-20  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Use cuid_t type for cuid.

+ 6 - 6
src/BtRegistry.cc

@@ -45,7 +45,7 @@
 namespace aria2 {
 
 SharedHandle<DownloadContext>
-BtRegistry::getDownloadContext(int32_t gid) const
+BtRegistry::getDownloadContext(gid_t gid) const
 {
   return get(gid)._downloadContext;
 }
@@ -54,7 +54,7 @@ SharedHandle<DownloadContext>
 BtRegistry::getDownloadContext(const std::string& infoHash) const
 {
   SharedHandle<DownloadContext> dctx;
-  for(std::map<int32_t, BtObject>::const_iterator i = _pool.begin(),
+  for(std::map<gid_t, BtObject>::const_iterator i = _pool.begin(),
         eoi = _pool.end(); i != eoi; ++i) {
     const BDE& attrs =
       (*i).second._downloadContext->getAttribute(bittorrent::BITTORRENT);
@@ -66,14 +66,14 @@ BtRegistry::getDownloadContext(const std::string& infoHash) const
   return dctx;
 }
 
-void BtRegistry::put(int32_t gid, const BtObject& obj)
+void BtRegistry::put(gid_t gid, const BtObject& obj)
 {
   _pool[gid] = obj;
 }
 
-BtObject BtRegistry::get(int32_t gid) const
+BtObject BtRegistry::get(gid_t gid) const
 {
-  std::map<int32_t, BtObject>::const_iterator i = _pool.find(gid);
+  std::map<gid_t, BtObject>::const_iterator i = _pool.find(gid);
   if(i == _pool.end()) {
     return BtObject();
   } else {
@@ -81,7 +81,7 @@ BtObject BtRegistry::get(int32_t gid) const
   }
 }
 
-bool BtRegistry::remove(int32_t gid)
+bool BtRegistry::remove(gid_t gid)
 {
   return _pool.erase(gid);
 }

+ 7 - 6
src/BtRegistry.h

@@ -40,6 +40,7 @@
 #include <map>
 
 #include "SharedHandle.h"
+#include "RequestGroup.h"
 
 namespace aria2 {
 
@@ -86,22 +87,22 @@ struct BtObject {
 
 class BtRegistry {
 private:
-  std::map<int32_t, BtObject> _pool;
+  std::map<gid_t, BtObject> _pool;
 public:
   SharedHandle<DownloadContext>
-  getDownloadContext(int32_t gid) const;
+  getDownloadContext(gid_t gid) const;
 
   SharedHandle<DownloadContext>
   getDownloadContext(const std::string& infoHash) const;
 
-  void put(int32_t gid, const BtObject& obj);
+  void put(gid_t gid, const BtObject& obj);
 
-  BtObject get(int32_t gid) const;
+  BtObject get(gid_t gid) const;
 
   template<typename OutputIterator>
   OutputIterator getAllDownloadContext(OutputIterator dest)
   {
-    for(std::map<int32_t, BtObject>::const_iterator i = _pool.begin(),
+    for(std::map<gid_t, BtObject>::const_iterator i = _pool.begin(),
           eoi = _pool.end(); i != eoi; ++i) {
       *dest++ = (*i).second._downloadContext;
     }
@@ -110,7 +111,7 @@ public:
 
   void removeAll();
 
-  bool remove(int32_t gid);
+  bool remove(gid_t gid);
 };
 
 } // namespace aria2

+ 7 - 6
src/DownloadResult.h

@@ -44,6 +44,7 @@
 
 #include "SharedHandle.h"
 #include "DownloadResultCode.h"
+#include "RequestGroup.h"
 
 namespace aria2 {
 
@@ -52,7 +53,7 @@ class FileEntry;
 class DownloadResult
 {
 public:
-  int32_t gid;
+  gid_t gid;
  
   std::vector<SharedHandle<FileEntry> > fileEntries;
 
@@ -67,20 +68,20 @@ public:
 
   // This field contains GIDs. See comment in
   // RequestGroup.cc::_followedByGIDs.
-  std::vector<int32_t> followedBy;
+  std::vector<gid_t> followedBy;
 
   // This field contains GID. See comment in
   // RequestGroup.cc::_belongsToGID.
-  int32_t belongsTo;
+  gid_t belongsTo;
 
-  DownloadResult(int32_t gid,
+  DownloadResult(gid_t gid,
                  const std::vector<SharedHandle<FileEntry> >& fileEntries,
                  bool inMemoryDownload,
                  uint64_t sessionDownloadLength,
                  int64_t sessionTime,
                  downloadresultcode::RESULT result,
-                 const std::vector<int32_t> followedBy,
-                 int32_t belongsTo):
+                 const std::vector<gid_t> followedBy,
+                 gid_t belongsTo):
     gid(gid),
     fileEntries(fileEntries),
     inMemoryDownload(inMemoryDownload),

+ 2 - 2
src/RequestGroup.cc

@@ -108,7 +108,7 @@
 
 namespace aria2 {
 
-int32_t RequestGroup::_gidCounter = 0;
+gid_t RequestGroup::_gidCounter = 0;
 
 RequestGroup::RequestGroup(const SharedHandle<Option>& option):
   _gid(newGID()),
@@ -1162,7 +1162,7 @@ void RequestGroup::setDownloadContext
   }
 }
 
-int32_t RequestGroup::newGID()
+gid_t RequestGroup::newGID()
 {
   if(_gidCounter == INT32_MAX) {
     _gidCounter = 0;

+ 11 - 9
src/RequestGroup.h

@@ -73,6 +73,8 @@ class BtRuntime;
 class PeerStorage;
 #endif // ENABLE_BITTORRENT
 
+typedef int32_t gid_t;
+
 class RequestGroup {
 public:
   enum HaltReason {
@@ -81,9 +83,9 @@ public:
     USER_REQUEST
   };
 private:
-  static int32_t _gidCounter;
+  static gid_t _gidCounter;
 
-  int32_t _gid;
+  gid_t _gid;
 
   SharedHandle<Option> _option;
 
@@ -155,13 +157,13 @@ private:
   // example, downloads generated by PostDownloadHandler), this field
   // has the GID of generated RequestGroups. empty list means there is
   // no such RequestGroup.
-  std::vector<int32_t> _followedByGIDs;
+  std::vector<gid_t> _followedByGIDs;
 
   // If this download is a part of another download(for example,
   // downloading torrent file described in Metalink file), this field
   // has the GID of parent RequestGroup. 0 means this is a parent
   // RequestGroup.
-  int32_t _belongsToGID;
+  gid_t _belongsToGID;
 
   RequestGroupMan* _requestGroupMan;
 
@@ -244,7 +246,7 @@ public:
     return _numConcurrentCommand;
   }
 
-  int32_t getGID() const
+  gid_t getGID() const
   {
     return _gid;
   }
@@ -478,17 +480,17 @@ public:
     }
   }
 
-  const std::vector<int32_t>& followedBy() const
+  const std::vector<gid_t>& followedBy() const
   {
     return _followedByGIDs;
   }
 
-  void belongsTo(int32_t gid)
+  void belongsTo(gid_t gid)
   {
     _belongsToGID = gid;
   }
 
-  int32_t belongsTo() const
+  gid_t belongsTo() const
   {
     return _belongsToGID;
   }
@@ -500,7 +502,7 @@ public:
 
   static void resetGIDCounter() { _gidCounter = 0; }
 
-  static int32_t newGID();
+  static gid_t newGID();
 };
 
 } // namespace aria2

+ 7 - 8
src/RequestGroupMan.cc

@@ -77,7 +77,6 @@ RequestGroupMan::RequestGroupMan
   _reservedGroups(requestGroups.begin(), requestGroups.end()),
   _logger(LogFactory::getInstance()),
   _maxSimultaneousDownloads(maxSimultaneousDownloads),
-  _gidCounter(0),
   _option(option),
   _serverStatMan(new ServerStatMan()),
   _maxOverallDownloadSpeedLimit
@@ -157,7 +156,7 @@ SharedHandle<RequestGroup> RequestGroupMan::getRequestGroup(size_t index) const
 }
 
 template<typename Iterator>
-static Iterator findByGID(Iterator first, Iterator last, int32_t gid)
+static Iterator findByGID(Iterator first, Iterator last, gid_t gid)
 {
   for(; first != last; ++first) {
     if((*first)->getGID() == gid) {
@@ -168,7 +167,7 @@ static Iterator findByGID(Iterator first, Iterator last, int32_t gid)
 }
 
 SharedHandle<RequestGroup>
-RequestGroupMan::findRequestGroup(int32_t gid) const
+RequestGroupMan::findRequestGroup(gid_t gid) const
 {
   std::deque<SharedHandle<RequestGroup> >::const_iterator i =
     findByGID(_requestGroups.begin(), _requestGroups.end(), gid);
@@ -180,7 +179,7 @@ RequestGroupMan::findRequestGroup(int32_t gid) const
 }
 
 SharedHandle<RequestGroup>
-RequestGroupMan::findReservedGroup(int32_t gid) const
+RequestGroupMan::findReservedGroup(gid_t gid) const
 {
   std::deque<SharedHandle<RequestGroup> >::const_iterator i =
     findByGID(_reservedGroups.begin(), _reservedGroups.end(), gid);
@@ -192,7 +191,7 @@ RequestGroupMan::findReservedGroup(int32_t gid) const
 }
 
 size_t RequestGroupMan::changeReservedGroupPosition
-(int32_t gid, int pos, HOW how)
+(gid_t gid, int pos, HOW how)
 {
   std::deque<SharedHandle<RequestGroup> >::iterator i =
     findByGID(_reservedGroups.begin(), _reservedGroups.end(), gid);
@@ -234,7 +233,7 @@ size_t RequestGroupMan::changeReservedGroupPosition
   return pos;
 }
 
-bool RequestGroupMan::removeReservedGroup(int32_t gid)
+bool RequestGroupMan::removeReservedGroup(gid_t gid)
 {
   std::deque<SharedHandle<RequestGroup> >::iterator i =
     findByGID(_reservedGroups.begin(), _reservedGroups.end(), gid);
@@ -246,7 +245,7 @@ bool RequestGroupMan::removeReservedGroup(int32_t gid)
   }
 }
 
-static void executeHook(const std::string& command, int gid)
+static void executeHook(const std::string& command, gid_t gid)
 {
   LogFactory::getInstance()->info("Executing user command: %s %d",
                                   command.c_str(), gid);
@@ -764,7 +763,7 @@ TransferStat RequestGroupMan::calculateStat()
 }
 
 SharedHandle<DownloadResult>
-RequestGroupMan::findDownloadResult(int32_t gid) const
+RequestGroupMan::findDownloadResult(gid_t gid) const
 {
   for(std::deque<SharedHandle<DownloadResult> >::const_iterator i =
         _downloadResults.begin(), eoi = _downloadResults.end(); i != eoi; ++i) {

+ 6 - 7
src/RequestGroupMan.h

@@ -45,11 +45,11 @@
 #include "SharedHandle.h"
 #include "DownloadResult.h"
 #include "TransferStat.h"
+#include "RequestGroup.h"
 
 namespace aria2 {
 
 class DownloadEngine;
-class RequestGroup;
 class Command;
 class Logger;
 class DownloadResult;
@@ -64,7 +64,6 @@ private:
   std::deque<SharedHandle<DownloadResult> > _downloadResults;
   Logger* _logger;
   unsigned int _maxSimultaneousDownloads;
-  int32_t _gidCounter;
 
   const Option* _option;
 
@@ -124,14 +123,14 @@ public:
     return _requestGroups;
   }
 
-  SharedHandle<RequestGroup> findRequestGroup(int32_t gid) const;
+  SharedHandle<RequestGroup> findRequestGroup(gid_t gid) const;
 
   const std::deque<SharedHandle<RequestGroup> >& getReservedGroups() const
   {
     return _reservedGroups;
   }
 
-  SharedHandle<RequestGroup> findReservedGroup(int32_t gid) const;
+  SharedHandle<RequestGroup> findReservedGroup(gid_t gid) const;
 
   enum HOW {
     POS_SET,
@@ -148,9 +147,9 @@ public:
   // beyond the end of the queue, it moves the download to the
   // beginning or the end of the queue respectively.  Returns the
   // destination position.
-  size_t changeReservedGroupPosition(int32_t gid, int pos, HOW how);
+  size_t changeReservedGroupPosition(gid_t gid, int pos, HOW how);
 
-  bool removeReservedGroup(int32_t gid);
+  bool removeReservedGroup(gid_t gid);
 
   void showDownloadResults(std::ostream& o) const;
 
@@ -201,7 +200,7 @@ public:
     return _downloadResults;
   }
 
-  SharedHandle<DownloadResult> findDownloadResult(int32_t gid) const;
+  SharedHandle<DownloadResult> findDownloadResult(gid_t gid) const;
 
   // Removes all download results.
   void purgeDownloadResult();

+ 14 - 14
src/XmlRpcMethodImpl.cc

@@ -131,7 +131,7 @@ const std::string KEY_MODE = "mode";
 const std::string KEY_SERVERS = "servers";
 }
 
-static BDE createGIDResponse(int32_t gid)
+static BDE createGIDResponse(gid_t gid)
 {
   return BDE(util::itos(gid));
 }
@@ -292,7 +292,7 @@ static BDE removeDownload
     throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
   }
   
-  int32_t gid = util::parseInt(params[0].s());
+  gid_t gid = util::parseInt(params[0].s());
 
   SharedHandle<RequestGroup> group = e->_requestGroupMan->findRequestGroup(gid);
 
@@ -399,7 +399,7 @@ void gatherProgressCommon
   if(!group->followedBy().empty()) {
     BDE list = BDE::list();
     // The element is GID.
-    for(std::vector<int32_t>::const_iterator i = group->followedBy().begin(),
+    for(std::vector<gid_t>::const_iterator i = group->followedBy().begin(),
           eoi = group->followedBy().end(); i != eoi; ++i) {
       list << util::itos(*i);
     }
@@ -525,7 +525,7 @@ void gatherStoppedDownload
   if(!ds->followedBy.empty()) {
     BDE list = BDE::list();
     // The element is GID.
-    for(std::vector<int32_t>::const_iterator i = ds->followedBy.begin(),
+    for(std::vector<gid_t>::const_iterator i = ds->followedBy.begin(),
           eoi = ds->followedBy.end(); i != eoi; ++i) {
       list << util::itos(*i);
     }
@@ -541,7 +541,7 @@ void gatherStoppedDownload
 
 static
 SharedHandle<RequestGroup>
-findRequestGroup(const SharedHandle<RequestGroupMan>& rgman, int32_t gid)
+findRequestGroup(const SharedHandle<RequestGroupMan>& rgman, gid_t gid)
 {
   SharedHandle<RequestGroup> group = rgman->findRequestGroup(gid);
   if(group.isNull()) {
@@ -560,7 +560,7 @@ BDE GetFilesXmlRpcMethod::process
     throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
   }
   
-  int32_t gid = util::parseInt(params[0].s());
+  gid_t gid = util::parseInt(params[0].s());
 
   BDE files = BDE::list();
   SharedHandle<RequestGroup> group = findRequestGroup(e->_requestGroupMan, gid);
@@ -591,7 +591,7 @@ BDE GetUrisXmlRpcMethod::process
     throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
   }
   
-  int32_t gid = util::parseInt(params[0].s());
+  gid_t gid = util::parseInt(params[0].s());
 
   SharedHandle<RequestGroup> group = findRequestGroup(e->_requestGroupMan, gid);
   if(group.isNull()) {
@@ -617,7 +617,7 @@ BDE GetPeersXmlRpcMethod::process
     throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
   }
   
-  int32_t gid = util::parseInt(params[0].s());
+  gid_t gid = util::parseInt(params[0].s());
 
   SharedHandle<RequestGroup> group = findRequestGroup(e->_requestGroupMan, gid);
   if(group.isNull()) {
@@ -644,7 +644,7 @@ BDE TellStatusXmlRpcMethod::process
     throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
   }
   
-  int32_t gid = util::parseInt(params[0].s());
+  gid_t gid = util::parseInt(params[0].s());
 
   SharedHandle<RequestGroup> group = e->_requestGroupMan->findRequestGroup(gid);
 
@@ -728,7 +728,7 @@ BDE ChangeOptionXmlRpcMethod::process
   if(params.empty() || !params[0].isString()) {
     throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
   }  
-  int32_t gid = util::parseInt(params[0].s());
+  gid_t gid = util::parseInt(params[0].s());
 
   SharedHandle<RequestGroup> group = findRequestGroup(e->_requestGroupMan, gid);
   if(group.isNull()) {
@@ -823,7 +823,7 @@ BDE GetOptionXmlRpcMethod::process
   if(params.empty() || !params[0].isString()) {
     throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
   }  
-  int32_t gid = util::parseInt(params[0].s());
+  gid_t gid = util::parseInt(params[0].s());
 
   SharedHandle<RequestGroup> group = findRequestGroup(e->_requestGroupMan, gid);
   if(group.isNull()) {
@@ -860,7 +860,7 @@ BDE ChangePositionXmlRpcMethod::process
      !params[0].isString() || !params[1].isInteger() || !params[2].isString()) {
     throw DL_ABORT_EX("Illegal argument.");
   }
-  int32_t gid = util::parseInt(params[0].s());
+  gid_t gid = util::parseInt(params[0].s());
   int pos = params[1].i();
   const std::string& howStr = params[2].s();
   RequestGroupMan::HOW how;
@@ -896,7 +896,7 @@ BDE GetServersXmlRpcMethod::process
   if(params.empty() || !params[0].isString()) {
     throw DL_ABORT_EX("Bad request");
   }
-  int32_t gid = util::parseInt(params[0].s());
+  gid_t gid = util::parseInt(params[0].s());
   SharedHandle<RequestGroup> group = e->_requestGroupMan->findRequestGroup(gid);
   if(group.isNull()) {
     throw DL_ABORT_EX(StringFormat("No active download for GID#%d", gid).str());
@@ -946,7 +946,7 @@ BDE ChangeUriXmlRpcMethod::process
   bool posGiven = false;
   getPosParam(params, 4, posGiven, pos);
 
-  int32_t gid = util::parseInt(params[0].s());
+  gid_t gid = util::parseInt(params[0].s());
   size_t index = params[1].i()-1;
   const BDE& deluris = params[2];
   const BDE& adduris = params[3];