1 /* 2 * SessionPackageProvidedExtension.hpp 3 * 4 * Copyright (C) 2021 by RStudio, PBC 5 * 6 * Unless you have received this program directly from RStudio pursuant 7 * to the terms of a commercial license agreement with RStudio, then 8 * this program is licensed to you under the terms of version 3 of the 9 * GNU Affero General Public License. This program is distributed WITHOUT 10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13 * 14 */ 15 16 #ifndef SESSION_MODULES_PACKAGE_PROVIDED_EXTENSION_HPP 17 #define SESSION_MODULES_PACKAGE_PROVIDED_EXTENSION_HPP 18 19 #include <string> 20 #include <vector> 21 22 #include <shared_core/json/Json.hpp> 23 24 #include <boost/function.hpp> 25 #include <boost/noncopyable.hpp> 26 #include <boost/shared_ptr.hpp> 27 28 namespace rstudio { 29 namespace core { 30 31 class Error; 32 class FilePath; 33 34 } // end namespace core 35 } // end namespace rstudio 36 37 namespace rstudio { 38 namespace session { 39 namespace modules { 40 namespace ppe { 41 42 core::Error parseDcfResourceFile( 43 const core::FilePath& resourcePath, 44 boost::function<core::Error(const std::map<std::string, std::string>&)> callback); 45 46 class Worker : boost::noncopyable 47 { 48 public: 49 virtual void onIndexingStarted() = 0; 50 virtual void onIndexingCompleted(core::json::Object* pPayload) = 0; 51 virtual void onWork(const std::string& pkgName, const core::FilePath& resourcePath) = 0; ~Worker()52 virtual ~Worker() {} 53 54 public: 55 Worker()56 Worker() 57 { 58 } 59 Worker(const std::string & resourcePath)60 Worker(const std::string& resourcePath) 61 : resourcePath_(resourcePath) 62 { 63 } 64 resourcePath() const65 const std::string& resourcePath() const { return resourcePath_; } 66 67 private: 68 std::string resourcePath_; 69 }; 70 71 class Indexer : boost::noncopyable 72 { 73 public: 74 explicit Indexer(); ~Indexer()75 virtual ~Indexer() {} 76 77 public: 78 void addWorker(boost::shared_ptr<Worker> pWorker); 79 void removeWorker(boost::shared_ptr<Worker> pWorker); 80 81 public: 82 void start(); running()83 bool running() { return running_; } getPayload()84 core::json::Object getPayload() { return payload_; } 85 86 private: 87 void beginIndexing(); 88 bool work(); 89 void endIndexing(); 90 91 private: 92 std::vector<boost::shared_ptr<Worker> > workers_; 93 std::vector<core::FilePath> pkgDirs_; 94 core::json::Object payload_; 95 96 std::size_t index_; 97 std::size_t n_; 98 bool running_; 99 }; 100 101 Indexer& indexer(); 102 core::Error initialize(); 103 104 } // end namespace ppe 105 } // end namespace modules 106 } // end namespace session 107 } // end namespace rstudio 108 109 #endif /* SESSION_MODULES_PACKAGE_PROVIDED_EXTENSION_HPP */ 110