|
Katana Plug-in APIs 0.1
|
00001 // Copyright (c) 2012 The Foundry Visionmongers Ltd. All Rights Reserved. 00002 00003 #ifndef FNASSET__H 00004 #define FNASSET__H 00005 00006 #include <FnPlatform/internal/UniquePtr.h> 00007 #include <FnPluginSystem/FnPluginSystem.h> 00008 #include <FnPluginSystem/FnPlugin.h> 00009 #include <FnAsset/FnAssetAPI.h> 00010 #include <FnAsset/suite/FnAssetSuite.h> 00011 00012 #include <FnAttribute/FnAttribute.h> 00013 00014 #include <string> 00015 #include <memory> 00016 #include <map> 00017 00018 namespace Foundry 00019 { 00020 namespace Katana 00021 { 00022 class AssetTransaction; 00023 00092 class FNASSET_API Asset 00093 { 00094 public: 00095 typedef std::map<std::string, std::string> StringMap; 00096 typedef std::vector<std::string> StringVector; 00097 00098 Asset() { /* Empty */ } 00099 virtual ~Asset() { /* Empty */ } 00100 00103 virtual void reset() = 0; 00104 00114 virtual bool isAssetId(const std::string& str) = 0; 00115 00125 virtual bool containsAssetId(const std::string& str) = 0; 00126 00135 virtual bool checkPermissions(const std::string &assetId, const StringMap &context) = 0; 00136 00145 virtual bool runAssetPluginCommand(const std::string &assetId, const std::string &command, const StringMap &commandArgs) = 0; 00146 00152 virtual void resolveAsset(const std::string& assetId, std::string& ret) = 0; 00153 00160 virtual void resolveAllAssets(const std::string& str, std::string& ret) = 0; 00161 00172 virtual void resolvePath(const std::string& str, const int frame, std::string& ret) = 0; 00173 00188 virtual void resolveAssetVersion(const std::string& assetId, 00189 std::string& ret, const std::string& versionStr = std::string()) = 0; 00190 00202 virtual void getUniqueScenegraphLocationFromAssetId(const std::string& assetId, 00203 bool includeVersion, std::string& ret) = 0; 00204 00211 virtual void getAssetDisplayName(const std::string& assetId, std::string& ret) = 0; 00212 00219 virtual void getAssetVersions(const std::string& assetId, StringVector& ret) = 0; 00220 00231 virtual void getRelatedAssetId(const std::string& assetId, const std::string& relation, 00232 std::string& ret) = 0; 00233 00244 virtual void getAssetFields(const std::string& assetId, bool includeDefaults, 00245 StringMap& returnFields) = 0; 00246 00255 virtual void buildAssetId(const StringMap& fields, std::string& ret) = 0; 00256 00267 virtual void getAssetAttributes(const std::string& assetId, const std::string& scope, 00268 StringMap& returnAttrs) = 0; 00269 00279 virtual void setAssetAttributes(const std::string& assetId, const std::string& scope, 00280 const StringMap& attrs) = 0; 00281 00293 virtual void getAssetIdForScope(const std::string& assetId, const std::string& scope, 00294 std::string& ret) = 0; 00295 00309 virtual void createAssetAndPath(AssetTransaction* txn, const std::string& assetType, 00310 const StringMap& assetFields, const StringMap& args, bool createDirectory, 00311 std::string& assetId) = 0; 00312 00323 virtual void postCreateAsset(AssetTransaction* txn, const std::string& assetType, 00324 const StringMap& assetFields, const StringMap& args, 00325 std::string& assetId) = 0; 00326 00327 00336 virtual AssetTransaction * createTransaction(); 00337 00339 static FnPlugStatus setHost(FnPluginHost* host); 00340 static FnPluginHost* getHost(); 00341 static FnAssetPluginSuite_v1 createSuite(FnAssetHandle (*create)()); 00342 00343 static FnAssetHandle newAssetHandle(Asset* asset); 00344 static FnAssetTransactionHandle newAssetTransactionHandle(AssetTransaction* txn); 00345 00346 static unsigned int _apiVersion; 00347 static const char* _apiName; 00348 00349 private: 00350 static FnPluginHost* _host; 00351 00353 }; 00354 00361 class FNASSET_API AssetTransaction 00362 { 00363 public: 00364 AssetTransaction() {/* Empty */} 00365 virtual ~AssetTransaction() {/* Empty */} 00366 00369 virtual void cancel() = 0; 00370 00373 virtual bool commit() = 0; 00374 }; 00375 00380 class FNASSET_API SimpleAction 00381 { 00382 public: 00383 virtual ~SimpleAction() {} 00384 virtual bool doit() = 0; 00385 virtual void rollback() = 0; 00386 }; 00387 00393 class FNASSET_API SimpleTransaction : public AssetTransaction 00394 { 00395 public: 00396 virtual ~SimpleTransaction(); 00397 00398 void addAction(SimpleAction *action); 00399 00400 void cancel(); 00401 00402 bool commit(); 00403 00404 private: 00405 std::vector<SimpleAction *> _actions; 00406 00407 void _clearActions(); 00408 }; 00409 00413 }; // namespace Katana 00414 }; // namespace Foundry 00415 00416 namespace FnKat = Foundry::Katana; 00417 00419 00420 #define DEFINE_ASSET_PLUGIN(ASSET_CLASS) \ 00421 \ 00422 FnPlugin ASSET_CLASS##_plugin; \ 00423 \ 00424 FnAssetHandle ASSET_CLASS##_create() \ 00425 { \ 00426 return Foundry::Katana::Asset::newAssetHandle(ASSET_CLASS::create()); \ 00427 } \ 00428 \ 00429 FnAssetPluginSuite_v1 ASSET_CLASS##_suite = \ 00430 Foundry::Katana::Asset::createSuite(ASSET_CLASS##_create); \ 00431 \ 00432 const void* ASSET_CLASS##_getSuite() \ 00433 { \ 00434 return &ASSET_CLASS##_suite; \ 00435 } \ 00436 00437 00438 struct FnAssetStruct 00439 { 00440 public: 00441 FnAssetStruct(Foundry::Katana::Asset* asset) : 00442 _asset(asset) { /* Empty */ } 00443 ~FnAssetStruct() { /* Empty */ } 00444 00445 Foundry::Katana::Asset& getAsset() 00446 { 00447 return *_asset; 00448 } 00449 00450 private: 00451 FnPlatform::internal::UniquePtr<Foundry::Katana::Asset>::type _asset; 00452 }; 00453 00454 struct FnAssetTransactionStruct 00455 { 00456 public: 00457 FnAssetTransactionStruct(Foundry::Katana::AssetTransaction* txn) : 00458 _assetTransaction(txn) { /* Empty */ } 00459 ~FnAssetTransactionStruct() { /* Empty */ } 00460 00461 Foundry::Katana::AssetTransaction& getAssetTransaction() 00462 { 00463 return *_assetTransaction; 00464 } 00465 00466 private: 00467 FnPlatform::internal::UniquePtr<Foundry::Katana::AssetTransaction>::type 00468 _assetTransaction; 00469 }; 00470 00472 00473 #endif // #ifndef FNASSET__H
1.7.3