WSF
WsfExchangeProcessor.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFEXCHANGEPROCESSOR_HPP
13#define WSFEXCHANGEPROCESSOR_HPP
14
15#include <float.h>
16#include <vector>
17
18#include "UtCallbackHolder.hpp"
19class UtInput;
20#include "wsf_export.h"
21
22#include "WsfEvent.hpp"
23#include "WsfExchange.hpp"
24#include "WsfMessage.hpp"
27
43
45{
46public:
50 ~WsfExchangeProcessor() override;
51
52 WsfProcessor* Clone() const override;
53
54 bool Initialize(double aSimTime) override;
55 bool ProcessInput(UtInput& aInput) override;
56
57 bool IgnoreAllProximityChecks() const { return mIgnoreProxChecks; }
58 bool ForceTransactionsInstantaneous() const { return mAllTransAreInstant; }
59
60 void PlatformDeleted(WsfPlatform* aPlatformPtr) override;
61
62 // ====================== Container Accessors =========================
63 WsfExchange::Container* FindContainer(WsfStringId aContainerNameId);
64 bool AddContainer(const WsfExchange::Container& aContainer);
65
66 // ====================== Transactor Accessors =========================
67 bool AddTransactor(const WsfExchange::Transactor& aTransactor);
68 WsfExchange::Transactor* FindTransactor(WsfStringId aTransactorNameId);
69 bool GetTransactorPtr(WsfStringId aItemNameId, WsfStringId aContainerId, bool aIsOfferor, WsfExchange::Transactor*& aTransPtr);
70
71 // ====================== Capability Accessors =========================
72 WsfExchange::CapabilityType GetCapabilityOf(WsfStringId aCommodityNameId);
73 bool AddCapability(WsfStringId aCommodityTypeId);
74
75 // ================ Callback Signatures =============================
76 void PlatformCapabilityChanged(double aSimTime, WsfPlatform* aPlatformPtr, WsfStringId aCapabilityId, bool aIsCapable);
77 void ExchangeQueried(double aSimTime, const WsfExchange::Query& aQuery);
78 void ExchangeNegotiated(double aSimTime, const WsfExchange::Query& aQuery);
79 void ExchangeRequestFailed(double aSimTime, const WsfExchange::Transactor& aTransactor, const WsfExchange::Query& aQuery);
80 void ExchangeCompleted(double aSimTime, const WsfExchange::Transactor& aTransactor, const WsfExchange::Query& aQuery);
81
82 // ================ Script-Related =============================
83 static UtScriptClass* CreateScriptClass(const std::string& aClassName, UtScriptTypes* aScriptTypesPtr);
84 const char* GetScriptClassName() const override;
85
86 std::vector<size_t> PayloadProviders();
87 std::vector<size_t> FuelProviders();
88 std::vector<size_t> VehicleRecoverers();
89 std::vector<size_t> VehicleRepairers();
90 // std::vector<size_t> ADS_B_Providers();
91
92 WsfPlatform* ClosestPossibleProvider(WsfStringId aCommodityOrServiceId,
93 double aProximityLimit = std::numeric_limits<double>::max());
94 // =========================================================================
95
96protected:
98 {
100 : mCommodityTypeId(aCommodityTypeId)
101 , mCapability(aCapability)
102 {
103 }
104
107 };
108
109 struct Supplier
110 {
111 Supplier(size_t aPlatformIndex);
112 void Nullify();
113 bool SetCapability(WsfExchange::CapabilityType aAbility, bool aIsCapable);
114 bool IsCapableOf(WsfExchange::CapabilityType aAbility) const;
115
118 };
119
120 bool AddCapability(WsfStringId aCommodityTypeId, WsfExchange::CapabilityType aCapabilityType);
121
122 void RemoveSupplier(size_t aPlatformIndex);
123
124 void SetSupplierAbility(size_t aPlatformIndex, WsfExchange::CapabilityType aCapabilityType, bool aIsCapable);
125
126private:
127 std::vector<WsfExchange::Transactor> mTransactors; // Transactors I have been configured with in "ProcessInput()".
128 std::vector<CommodityCapability> mCapabilityPairs; // Collection of the capabilities I (this) provides.
129 std::vector<Supplier> mKnownSuppliers; // Collection of affirmative "offerors/providers/suppliers".
130 std::vector<WsfExchange::Container> mContainers; // Collection of Containers to hold pools of commodities or services.
131 UtCallbackHolder mCallbacks;
132 bool mIgnoreProxChecks;
133 bool mAllTransAreInstant;
134 UtScript* mOnTransactionCompleteScriptPtr;
135 UtScript* mOnRequestFailedScriptPtr;
136 UtScriptClass* mTransactorClassPtr; // = mContextPtr->GetClass("Transactor");
137};
138
141{
142public:
143 WsfScriptExchangeProcessorClass(const std::string& aClassName, UtScriptTypes* aScriptTypesPtr);
144
147
148 UT_DECLARE_SCRIPT_METHOD(PayloadProviders);
150 UT_DECLARE_SCRIPT_METHOD(VehicleRepairers);
151 UT_DECLARE_SCRIPT_METHOD(VehicleRecoverers);
152 // UT_DECLARE_SCRIPT_METHOD(ADS_B_Suppliers);
153
154 UT_DECLARE_SCRIPT_METHOD(ClosestPossibleProvider);
155};
156
157#endif
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
WsfExchangeProcessor(WsfScenario &aScenario)
Definition WsfExchangeProcessor.cpp:53
std::vector< size_t > PayloadProviders()
Definition WsfExchangeProcessor.cpp:715
void ExchangeRequestFailed(double aSimTime, const WsfExchange::Transactor &aTransactor, const WsfExchange::Query &aQuery)
Definition WsfExchangeProcessor.cpp:239
void ExchangeNegotiated(double aSimTime, const WsfExchange::Query &aQuery)
WsfExchangeProcessor & operator=(const WsfExchangeProcessor &)=delete
static UtScriptClass * CreateScriptClass(const std::string &aClassName, UtScriptTypes *aScriptTypesPtr)
Definition WsfExchangeProcessor.cpp:47
void SetSupplierAbility(size_t aPlatformIndex, WsfExchange::CapabilityType aCapabilityType, bool aIsCapable)
Definition WsfExchangeProcessor.cpp:356
void PlatformCapabilityChanged(double aSimTime, WsfPlatform *aPlatformPtr, WsfStringId aCapabilityId, bool aIsCapable)
Definition WsfExchangeProcessor.cpp:678
void ExchangeQueried(double aSimTime, const WsfExchange::Query &aQuery)
Definition WsfExchangeProcessor.cpp:212
std::vector< size_t > VehicleRepairers()
Definition WsfExchangeProcessor.cpp:743
std::vector< size_t > FuelProviders()
Definition WsfExchangeProcessor.cpp:729
WsfPlatform * ClosestPossibleProvider(WsfStringId aCommodityOrServiceId, double aProximityLimit=std::numeric_limits< double >::max())
Definition WsfExchangeProcessor.cpp:424
bool AddCapability(WsfStringId aCommodityTypeId)
std::vector< size_t > VehicleRecoverers()
Definition WsfExchangeProcessor.cpp:757
void ExchangeCompleted(double aSimTime, const WsfExchange::Transactor &aTransactor, const WsfExchange::Query &aQuery)
Definition WsfExchangeProcessor.cpp:281
bool ForceTransactionsInstantaneous() const
Definition WsfExchangeProcessor.hpp:58
void RemoveSupplier(size_t aPlatformIndex)
Definition WsfExchangeProcessor.cpp:342
bool IgnoreAllProximityChecks() const
Definition WsfExchangeProcessor.hpp:57
Definition WsfExchange.hpp:312
Callback Query class.
Definition WsfExchange.hpp:164
Definition WsfExchange.hpp:356
virtual void PlatformDeleted(WsfPlatform *aPlatformPtr)
Definition WsfPlatformPart.cpp:343
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
WsfProcessor(const WsfScenario &aScenario)
Definition WsfProcessor.cpp:25
const char * GetScriptClassName() const override
Definition WsfProcessor.cpp:63
Contains the data required to create a simulation, and acts as the entry point for input file process...
Definition WsfScenario.hpp:111
UT_DECLARE_SCRIPT_METHOD(FuelProviders)
UT_DECLARE_SCRIPT_METHOD(ClosestPossibleProvider)
UT_DECLARE_SCRIPT_METHOD(PayloadProviders)
UT_DECLARE_SCRIPT_METHOD(VehicleRecoverers)
UT_DECLARE_SCRIPT_METHOD(FindTransactor)
UT_DECLARE_SCRIPT_METHOD(VehicleRepairers)
WsfScriptExchangeProcessorClass(const std::string &aClassName, UtScriptTypes *aScriptTypesPtr)
Definition WsfExchangeProcessor.cpp:811
UT_DECLARE_SCRIPT_METHOD(FindContainer)
WsfScriptProcessorClass(const std::string &aClassName, UtScriptTypes *aScriptTypesPtr)
Definition WsfScriptProcessorClass.cpp:31
WsfProcessor * Clone() const override
Definition WsfScriptProcessor.cpp:97
WsfScriptProcessor(const WsfScenario &aScenario)
Definition WsfScriptProcessor.cpp:30
bool Initialize(double aSimTime) override
Definition WsfScriptProcessor.cpp:104
bool ProcessInput(UtInput &aInput) override
Definition WsfScriptProcessor.cpp:186
CapabilityType
Definition WsfExchange.hpp:278
@ cNO_CAPABILITY
Definition WsfExchange.hpp:286
WsfStringId mCommodityTypeId
Definition WsfExchangeProcessor.hpp:105
CommodityCapability(WsfStringId aCommodityTypeId, WsfExchange::CapabilityType aCapability)
Definition WsfExchangeProcessor.hpp:99
WsfExchange::CapabilityType mCapability
Definition WsfExchangeProcessor.hpp:106
bool mAbilities[WsfExchange::cNO_CAPABILITY]
Definition WsfExchangeProcessor.hpp:117
void Nullify()
Definition WsfExchangeProcessor.cpp:783
Supplier(size_t aPlatformIndex)
Definition WsfExchangeProcessor.cpp:776
bool IsCapableOf(WsfExchange::CapabilityType aAbility) const
Definition WsfExchangeProcessor.cpp:802
size_t mPlatformIndex
Definition WsfExchangeProcessor.hpp:116
bool SetCapability(WsfExchange::CapabilityType aAbility, bool aIsCapable)
Definition WsfExchangeProcessor.cpp:793
Copyrights Multiple, All Rights Reserved