[ExecString] combine SplitParameters with identical function of CUtil
[xbmc.git] / xbmc / application / ApplicationStackHelper.h
blob6af0044372af7a1c83d8dd82ddbf3b8305b20c9b
1 /*
2 * Copyright (C) 2017-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "application/IApplicationComponent.h"
12 #include "threads/CriticalSection.h"
14 #include <map>
15 #include <memory>
16 #include <string>
18 class CFileItem;
19 class CFileItemList;
21 class CApplicationStackHelper : public IApplicationComponent
23 public:
24 CApplicationStackHelper(void);
25 ~CApplicationStackHelper() = default;
27 void Clear();
28 void OnPlayBackStarted(const CFileItem& item);
30 /*!
31 \brief Initialize stack
32 \param item the FileItem object that is the stack
34 bool InitializeStack(const CFileItem& item);
36 /*!
37 \brief Initialize stack times for each part, start & end, total time, and current part number if resume offset is specified.
38 \param item the FileItem object that is the stack
40 int InitializeStackStartPartAndOffset(const CFileItem& item);
42 /*!
43 \brief returns the current part number
45 int GetCurrentPartNumber() const { return m_currentStackPosition; }
47 /*!
48 \brief Returns true if Application is currently playing an ISO stack
50 bool IsPlayingISOStack() const;
52 /*!
53 \brief Returns true if Application is currently playing a Regular (non-ISO) stack
55 bool IsPlayingRegularStack() const;
57 /*!
58 \brief returns true if there is a next part available
60 bool HasNextStackPartFileItem() const;
62 /*!
63 \brief sets the next stack part as the current and returns a reference to it
65 const CFileItem& SetNextStackPartCurrentFileItem()
67 return GetStackPartFileItem(++m_currentStackPosition);
70 /*!
71 \brief sets a given stack part as the current and returns a reference to it
72 \param partNumber the number of the part that needs to become the current one
74 const CFileItem& SetStackPartCurrentFileItem(int partNumber)
76 return GetStackPartFileItem(m_currentStackPosition = partNumber);
79 /*!
80 \brief Returns the FileItem currently playing back as part of a (non-ISO) stack playback
82 const CFileItem& GetCurrentStackPartFileItem() const
84 return GetStackPartFileItem(m_currentStackPosition);
87 /*!
88 \brief Returns the end time of a FileItem part of a (non-ISO) stack playback
89 \param partNumber the requested part number in the stack
91 uint64_t GetStackPartEndTimeMs(int partNumber) const;
93 /*!
94 \brief Returns the start time of a FileItem part of a (non-ISO) stack playback
95 \param partNumber the requested part number in the stack
97 uint64_t GetStackPartStartTimeMs(int partNumber) const { return (partNumber > 0) ? GetStackPartEndTimeMs(partNumber - 1) : 0; }
99 /*!
100 \brief Returns the start time of the current FileItem part of a (non-ISO) stack playback
102 uint64_t GetCurrentStackPartStartTimeMs() const { return GetStackPartStartTimeMs(m_currentStackPosition); }
105 \brief Returns the total time of a (non-ISO) stack playback
107 uint64_t GetStackTotalTimeMs() const;
110 \brief Returns the stack part number corresponding to the given timestamp in a (non-ISO) stack playback
111 \param msecs the requested timestamp in the stack (in milliseconds)
113 int GetStackPartNumberAtTimeMs(uint64_t msecs);
115 // Stack information registration methods
118 \brief Clear all entries in the item-stack map. To be called upon playback stopped.
120 void ClearAllRegisteredStackInformation();
123 \brief Returns a smart pointer to the stack CFileItem.
125 std::shared_ptr<const CFileItem> GetRegisteredStack(const CFileItem& item) const;
128 \brief Returns true if there is a registered stack for the given CFileItem part.
129 \param item the reference to the item that is part of a stack
131 bool HasRegisteredStack(const CFileItem& item) const;
134 \brief Stores a smart pointer to the stack CFileItem in the item-stack map.
135 \param item the reference to the item that is part of a stack
136 \param stackItem the smart pointer to the stack CFileItem
138 void SetRegisteredStack(const CFileItem& item, std::shared_ptr<CFileItem> stackItem);
141 \brief Returns the part number of the part in the parameter
142 \param item the reference to the item that is part of a stack
144 int GetRegisteredStackPartNumber(const CFileItem& item);
147 \brief Stores the part number in the item-stack map.
148 \param item the reference to the item that is part of a stack
149 \param partNumber the part number of the part in other parameter
151 void SetRegisteredStackPartNumber(const CFileItem& item, int partNumber);
154 \brief Returns the start time of the part in the parameter
155 \param item the reference to the item that is part of a stack
157 uint64_t GetRegisteredStackPartStartTimeMs(const CFileItem& item) const;
160 \brief Stores the part start time in the item-stack map.
161 \param item the reference to the item that is part of a stack
162 \param startTime the start time of the part in other parameter
164 void SetRegisteredStackPartStartTimeMs(const CFileItem& item, uint64_t startTimeMs);
167 \brief Returns the total time of the stack associated to the part in the parameter
168 \param item the reference to the item that is part of a stack
170 uint64_t GetRegisteredStackTotalTimeMs(const CFileItem& item) const;
173 \brief Stores the stack's total time associated to the part in the item-stack map.
174 \param item the reference to the item that is part of a stack
175 \param totalTime the total time of the stack
177 void SetRegisteredStackTotalTimeMs(const CFileItem& item, uint64_t totalTimeMs);
179 CCriticalSection m_critSection;
181 protected:
183 \brief Returns a FileItem part of a (non-ISO) stack playback
184 \param partNumber the requested part number in the stack
186 CFileItem& GetStackPartFileItem(int partNumber);
187 const CFileItem& GetStackPartFileItem(int partNumber) const;
189 class StackPartInformation
191 public:
192 StackPartInformation()
194 m_lStackPartNumber = 0;
195 m_lStackPartStartTimeMs = 0;
196 m_lStackTotalTimeMs = 0;
198 uint64_t m_lStackPartStartTimeMs;
199 uint64_t m_lStackTotalTimeMs;
200 int m_lStackPartNumber;
201 std::shared_ptr<CFileItem> m_pStack;
204 typedef std::shared_ptr<StackPartInformation> StackPartInformationPtr;
205 typedef std::map<std::string, StackPartInformationPtr> Stackmap;
206 Stackmap m_stackmap;
207 StackPartInformationPtr GetStackPartInformation(const std::string& key);
208 StackPartInformationPtr GetStackPartInformation(const std::string& key) const;
210 std::unique_ptr<CFileItemList> m_currentStack;
211 int m_currentStackPosition = 0;
212 bool m_currentStackIsDiscImageStack = false;