1 /*---------------------------------------------------------------------------* 2 3 Copyright (C) Nintendo. All rights reserved. 4 5 These coded instructions, statements, and computer programs contain 6 proprietary information of Nintendo of America Inc. and/or Nintendo 7 Company Ltd., and are protected by Federal copyright law. They may 8 not be disclosed to third parties or copied or duplicated in any form, 9 in whole or in part, without the prior written consent of Nintendo. 10 11 *---------------------------------------------------------------------------*/ 12 13 #ifndef NN_BOSS_BOSS_TASK_H_ 14 #define NN_BOSS_BOSS_TASK_H_ 15 16 #include <nn/boss/boss_Const.h> 17 #include <nn/boss/boss_Result.h> 18 #include <nn/boss/boss_Types.h> 19 #include <nn/boss/boss_TaskSetting.h> 20 21 22 #ifdef __cplusplus 23 24 namespace nn { 25 namespace boss { 26 27 /*! 28 @addtogroup nn_boss_api 29 @{ 30 */ 31 32 /*! 33 @brief Represents a task. Used to register and start tasks and to manipulate them or access their attributes. 34 */ 35 class Task 36 { 37 friend class NbdlDataList; 38 39 public: 40 /*! 41 @brief Instantiates an object. The information required to use an instance is not set in this constructor. Use the <tt>@ref Initialize</tt> function to configure this class. 42 */ 43 explicit Task(void); 44 45 /*! 46 @brief Instantiates an object and calls <tt>@ref Initialize</tt>. This function targets the account that is logged in when the function is called. 47 48 @param[in] taskId Specifies the task ID. The maximum length, including the terminating null character, is defined by <tt>@ref TASK_ID_LENGTH_WITH_NULL</tt>. 49 */ 50 explicit Task( const char* taskId ); 51 52 /*! 53 @brief Instantiates an object and calls <tt>@ref Initialize</tt>. Specifies a slot in the target account. 54 55 @param[in] slotNo Specifies a slot in the target account. 56 @param[in] taskId Specifies the task ID. The maximum length, including the terminating null character, is defined by <tt>@ref TASK_ID_LENGTH_WITH_NULL</tt>. 57 */ 58 explicit Task( u8 slotNo, const char* taskId ); 59 60 /*! 61 @brief Destroys the object. 62 */ 63 virtual ~Task(void); 64 65 /*! 66 @brief Initializes the registered task with the specified task ID. This initialization enables the reuse of objects. This function targets the account that is logged in when the function is called. 67 68 @param[in] taskId Specifies the task ID. The maximum length, including the terminating null character, is defined by <tt>@ref TASK_ID_LENGTH_WITH_NULL</tt>. 69 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 70 @retval Result::IsSuccess Indicates that initialization succeeded. 71 @retval ResultInvalidParameter Indicates that the task ID is invalid. 72 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 73 */ 74 nn::Result Initialize(const char* taskId ); 75 76 /*! 77 @brief Initializes the registered task with the specified task ID. This initialization enables the reuse of objects. Specifies a slot in the target account. 78 79 @param[in] slotNo Specifies a slot in the target account. 80 @param[in] taskId Specifies the task ID. The maximum length, including the terminating null character, is defined by <tt>@ref TASK_ID_LENGTH_WITH_NULL</tt>. 81 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 82 @retval Result::IsSuccess Indicates that initialization succeeded. 83 @retval ResultInvalidParameter Indicates that the task ID is invalid. 84 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 85 */ 86 nn::Result Initialize( u8 slotNo, const char* taskId ); 87 88 /*! 89 @brief Finalizes the class instance. 90 91 Also called from the destructor. 92 */ 93 void Finalize( void ); 94 95 /*! 96 @brief Checks whether a task is registered. 97 98 @return Returns whether the task is registered. <tt>true</tt> if the task is registered. 99 */ 100 bool IsRegistered( void ) const; 101 102 103 /*! 104 @brief Registers a task. 105 106 Use <tt>@ref Initialize</tt> to set the IDs (the task ID and persistent ID) of the task to register. 107 Set the attributes for the task to register in an instance of the <tt>@ref TaskSetting</tt> subclass specified in the parameters. 108 109 The information for tasks registered with this function is held in the system and made persistent. 110 This enables the task to run in the background even across being powered down, or while a menu or other application is running. 111 Do not use this function if you only want to use the task in the foreground (that is, you want to register this task and execute it immediately only while the application is running, and you do not want to run it in the background while the menu or other application is running). Instead, use the <tt>@ref RegisterForImmediateRun</tt> function to register it as a dedicated immediate-execution task. 112 113 Tasks do not operate just by being registered. 114 Depending on the desired operations, start by using either the <tt>@ref Task::StartScheduling</tt> or <tt>@ref Task::Run</tt> function. 115 To halt a started task, use the <tt>@ref Task::StopScheduling</tt> function if you started the task using <tt>@ref Task::StartScheduling</tt>, or use <tt>@ref Task::Cancel (CANCEL_TO_STOP)</tt> or <tt>@ref Task::CancelSync (CANCEL_TO_STOP)</tt> if you started the task using <tt>@ref Task::Run</tt>. 116 117 The success conditions for registering tasks are as follows. 118 - Invalid values are not set in the <tt>TaskSetting</tt> specified in the parameters. 119 - The account from which the task was registered is tied to the network account. (If no account was explicitly specified, it is the account that was logged in when the task was registered.) 120 - The <b>Online Interaction in Games</b> option is not prohibited by the Parental Controls of the account from which the task was registered. 121 122 The first condition is met as long as the <tt>TaskSetting</tt> member functions are being used correctly. 123 If these conditions are not being met, this function returns an error. If you want to register a task that does not match these conditions, please contact Nintendo. 124 125 126 @param[in] taskSetting Specifies the task settings. 127 128 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. Something other than <tt>Result::IsSuccess</tt> is an error, and the task registration has failed. 129 @retval Result::IsSuccess Indicates that registration succeeded. 130 @retval ResultInvalidParameter Indicates that the task settings contain an invalid value. 131 @retval ResultInvalidFormat Indicates that the format of the task settings is invalid. 132 @retval ResultFull Indicates that the maximum number of tasks are already registered. 133 @retval ResultAlreadyExist Indicates that the same task (a task with the same task ID and the same persistent ID) has already been registered. 134 @retval ResultNotExist Indicates that there is no account with the specified persistent ID. 135 @retval ResultNotNetworkAccount Indicates that the account with the specified persistent ID is not associated with a network account. 136 @retval ResultRestrictedByParentalControl Indicates that Internet communication, including the SpotPass service, is restricted by the <b>Online Interaction in Games</b> option in Parental Controls for the account with the specified persistent ID. 137 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. 138 If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. 139 Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 140 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 141 142 143 144 145 */ 146 nn::Result Register(TaskSetting& taskSetting ); 147 148 149 /*! 150 @brief Registers a dedicated immediate-execution task. 151 152 Tasks registered with this function are exclusively for immediate execution. They are not persistent and are deleted if the system is restarted. In all other respects, they have the same specifications as tasks registered with the <tt>@ref Register</tt> function. 153 For more information, see <tt>@ref Register</tt>. 154 155 @param[in] taskSetting Specifies the task settings. 156 157 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. Something other than <tt>Result::IsSuccess</tt> is an error, and the task registration has failed. 158 @retval Result::IsSuccess Indicates that registration succeeded. 159 @retval ResultInvalidParameter Indicates that the task settings contain an invalid value. 160 @retval ResultInvalidFormat Indicates that the format of the task settings is invalid. 161 @retval ResultFull Indicates that the maximum number of tasks are already registered. 162 @retval ResultAlreadyExist Indicates that the same task (a task with the same task ID and the same persistent ID) has already been registered. 163 Alternately, indicates that a dedicated immediate-execution task with the same persistent ID has already been registered. 164 @retval ResultNotExist Indicates that there is no account with the specified persistent ID. 165 @retval ResultNotNetworkAccount Indicates that the account with the specified persistent ID is not associated with a network account. 166 @retval ResultRestrictedByParentalControl Indicates that Internet communication, including the SpotPass service, is restricted by the <b>Online Interaction in Games</b> option in Parental Controls for the account with the specified persistent ID. 167 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. 168 If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. 169 Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 170 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 171 */ 172 nn::Result RegisterForImmediateRun(const TaskSetting& taskSetting ); 173 174 175 /*! 176 @brief Allows the settings information for a registered task to be changed. 177 178 @param[in] taskSetting Specifies the task settings. 179 180 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 181 @retval Result::IsSuccess Indicates that registration succeeded. 182 @retval ResultInvalidParameter Indicates a failure to register the task because the task settings are invalid. Details of the cause are stored in <var>pResultDetail</var>. 183 @retval ResultNotExist Indicates that the specified task has not been registered. 184 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. 185 If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. 186 Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 187 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 188 */ 189 nn::Result Reconfigure(const TaskSetting& taskSetting ); 190 191 192 193 /*! 194 @brief Deletes a registered task. 195 196 If the task is running, it is first canceled, and then deleted. 197 Canceling and deleting a task can take several seconds. 198 199 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 200 @retval Result::IsSuccess Indicates that deletion succeeded. 201 @retval ResultNotExist Indicates that the specified task has not been registered. 202 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. 203 If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. 204 Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 205 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 206 */ 207 nn::Result Unregister(void); 208 209 210 /*! 211 @brief Updates the execution interval for a task after registration. You can change this interval even after a task has been instructed to start executing. 212 213 @param[in] intervalHour Specifies the interval at which to execute the task. The unit is hours. 214 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 215 @retval Result::IsSuccess Indicates that the execution interval was updated successfully. 216 @retval ResultNotInitialized Indicates that the instance has not been initialized. Call this method after calling <tt>@ref Initialize</tt>. 217 @retval ResultNotExist Indicates that the specified task has not been registered. 218 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 219 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 220 */ UpdateInterval(u32 intervalHour)221 inline nn::Result UpdateInterval(u32 intervalHour){return UpdateIntervalSec(intervalHour*60*60);} 222 223 /*! 224 @brief [For debugging only. In production, execution intervals are only approved if they are measured in hours. Use the <tt>@ref UpdateInterval</tt> function when you are not debugging. ] Updates the execution interval for a task after registration. The unit is seconds. You can change this interval even after a task has been instructed to start executing. 225 226 @param[in] intervalSec Specifies the execution interval. The unit is seconds. 227 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 228 @retval Result::IsSuccess Indicates that the execution interval was updated successfully. 229 @retval ResultNotInitialized Indicates that the instance has not been initialized. Call this method after calling <tt>@ref Initialize</tt>. 230 @retval ResultNotExist Indicates that the specified task has not been registered. 231 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 232 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 233 */ 234 nn::Result UpdateIntervalSec(u32 intervalSec); 235 236 /*! 237 @brief Updates the lifetime of a registered task. You can change this interval even after a task has been instructed to start executing. 238 239 @param[in] lifeTimeHourFromNow The time (in hours) from now at which to execute the task. 240 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 241 @retval Result::IsSuccess Indicates that the lifetime was updated successfully. 242 @retval ResultServiceFinished Indicates that the service related to the task has already terminated. 243 @retval ResultNotInitialized Indicates that the instance has not been initialized. Call this method after calling <tt>@ref Initialize</tt>. 244 @retval ResultNotExist Indicates that the specified task has not been registered. 245 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 246 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 247 */ UpdateLifeTime(u32 lifeTimeHourFromNow)248 inline nn::Result UpdateLifeTime(u32 lifeTimeHourFromNow){return UpdateLifeTimeSec(lifeTimeHourFromNow*60*60);} 249 250 /*! 251 @brief [For debugging only. In production, the task lifetime must be in hours. Use the <tt>@ref UpdateLifeTime</tt> function when you are not debugging. ] Updates the task lifetime after task registration. You can change this interval even after a task has been instructed to start executing. 252 253 @param[in] lifeTimeSecFromNow The time (in seconds) from now at which to execute the task. 254 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 255 @retval Result::IsSuccess Indicates that the lifetime was updated successfully. 256 @retval ResultServiceFinished Indicates that the service related to the task has already terminated. 257 @retval ResultNotInitialized Indicates that the instance has not been initialized. Call this method after calling <tt>@ref Initialize</tt>. 258 @retval ResultNotExist Indicates that the specified task has not been registered. 259 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 260 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 261 */ 262 nn::Result UpdateLifeTimeSec(s64 lifeTimeSecFromNow); 263 264 265 /*! 266 @brief Gets the execution interval. The unit is hours. 267 268 @return Returns the execution interval. 269 */ GetInterval(void)270 inline u32 GetInterval(void) const 271 { 272 const u32 intervalSec = GetIntervalSec(); 273 return (intervalSec / (60*60)); 274 } 275 276 /*! 277 @brief Gets the execution interval. The unit is seconds. 278 279 @return Returns the execution interval. 280 */ 281 u32 GetIntervalSec(void) const; 282 283 /*! 284 @brief Gets the lifetime of the task. The unit is hours. 285 286 @return Returns the lifetime. The unit is hours. 287 */ GetLifeTime(void)288 inline u32 GetLifeTime(void) const 289 { 290 const s64 secLifeTime = GetLifeTimeSec(); 291 return (secLifeTime / (60*60)); 292 } 293 294 /*! 295 @brief Gets the lifetime of the task. The unit is seconds. 296 297 @return Returns the lifetime. The unit is seconds. 298 */ 299 s64 GetLifeTimeSec(void) const; 300 301 302 /*! 303 @brief Gets the remaining lifetime of the task. The unit is seconds. 304 305 @return Returns the remaining lifetime of the task. The unit is seconds. 306 */ 307 s64 GetRemainingLifeTimeSec(void) const; 308 309 /*! 310 @brief Gets the target URL for task execution. 311 Returns an empty string for NBDL tasks. 312 313 @param[out] url Specifies the URL for which the task is executed. 314 @param[in] urlLength Specifies the length of <var>url</var>. 315 316 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 317 @retval Result::IsSuccess Indicates success. 318 @retval ResultNotInitialized Indicates that the instance has not been initialized. Call this method after calling <tt>@ref Initialize</tt>. 319 @retval ResultNotExist Indicates that the specified task has not been registered. 320 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 321 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 322 */ 323 nn::Result GetUrl(char url[], u32 urlLength) const; 324 325 /*! 326 @brief Checks whether a task has finished executing. 327 328 For a task with a specified lifetime, returns <tt>true</tt> if the lifetime has completed. 329 330 For a one-time execution task, only returns <tt>true</tt> after it has completed execution. 331 (This relates only to whether execution has completed, and not the task result. <tt>true</tt> is returned if execution has completed, even if the result is an error.) 332 This method returns <tt>false</tt> when it is called while the task is running. 333 334 @return Returns whether task execution has completed. Returns <tt>true</tt> if it has completed. 335 */ 336 bool IsFinished(void) const; 337 338 /*! 339 @brief Renews the task lifetime. 340 341 For a task with a specified lifetime, calling this method gives the task a new lifetime equal in length to the lifetime of the task when it was initially registered, and starting from the time the method is called. 342 For a one-time task, the task enters a state to be run once more, and is executed one execution interval after the method is called. 343 344 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 345 @retval Result::IsSuccess Indicates success. 346 @retval ResultServiceFinished Indicates that the service related to the task has already terminated. 347 @retval ResultNotInitialized Indicates that the instance has not been initialized. Call this method after calling <tt>@ref Initialize</tt>. 348 @retval ResultNotExist Indicates that the specified task has not been registered. 349 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 350 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 351 */ 352 nn::Result RestoreLifeTime(void); 353 354 355 /*! 356 @brief Gets the service status of a task. 357 358 Applications can check the status of a service when they detect a notification from the server that indicates that the service was discontinued. 359 <b>Note:</b> If the server has not been accessed since the task was registered, the status is <tt>@ref SERVICE_UNKNOWN</tt>. 360 361 @return Returns the service status of a task. 362 */ 363 TaskServiceStatus GetServiceStatus(void) const; 364 365 /*! 366 @brief Gives an instruction to start scheduled execution of the task. 367 368 The scheduled tasks automatically run in the background when infrastructure connections are enabled. 369 370 The <var>isFirstRunImmediate</var> parameter setting affects the timing of when the task right after <tt>RegisterTask</tt> runs for the first time. 371 If <var>isFirstRunImmediate</var> is set to <tt>true</tt> (or if the argument is omitted), the task is immediately ready to run for the first time when the function is called. The task runs as soon as the system makes an infrastructure connection following the function call. 372 If <var>isFirstRunImmediate</var> is <tt>false</tt>, the task is executed for the first time one execution interval after this method is called. 373 374 If this method is called to resume a task that was stopped by the <tt>@ref StopScheduling</tt> function, the <var>isFirstRunImmediate</var> parameter is ignored and the task resumes from the state it was in when it was stopped by the <tt>@ref StopScheduling</tt> function. 375 376 When execution of a task completes, if the time at one execution interval after that point is within the task lifetime, the task runs again after one execution interval. 377 (A one-time execution task is not executed subsequently.) 378 In the following circumstances, tasks are not executed even if a command is issued to start a task. 379 @li The execution priority of the task is <tt>@ref PRIORITY_STOPPED</tt>. 380 @li <b>Parental Controls</b> are enabled, and the attributes of the task do not override <b>Parental Controls</b>. 381 @li The user has not accepted the EULA, and the attributes of the task do not override EULA acceptance. 382 @li A policy list blocks task execution. 383 @li The application has paused all tasks. 384 385 The following methods can be used to wait for task completion. 386 @li Use the <tt>@ref Wait</tt> function to wait until execution completes. 387 @li Use the <tt>@ref Wait</tt> function to wait until execution completes, specifying a maximum wait time. 388 @li Use the <tt>@ref GetTurnState</tt> function to poll for task completion. 389 390 After task completion has been detected, you can use the <tt>@ref GetState</tt> function to check the task's status, the <tt>@ref GetResult</tt> function to check the task's execution result code, and the <tt>@ref GetHttpStatusCode</tt> function to check the result code of HTTP communications. 391 392 393 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 394 @retval Result::IsSuccess Indicates success. 395 @retval ResultNotInitialized Indicates that the instance has not been initialized. Call this method after calling <tt>@ref Initialize</tt>. 396 @retval ResultNotExist Indicates that the specified task has not been registered. 397 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 398 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 399 400 401 402 */ 403 nn::Result StartScheduling(bool isFirstRunImmediate = true); 404 405 /*! 406 @brief Immediately executes a task. 407 408 If <var>isForegroundRun</var> is <tt>true</tt>, the task runs in the foreground. In this case, the user must already have connected to the infrastructure network, and the task is run on that connection. 409 If a task running in the foreground is canceled—for example, because of loss of connection—the task generates an error and does not enter a waiting-for-retry state. 410 Use this method to run a task using the high-priority communication provided in the foreground. 411 412 If <var>isForegroundRun</var> is <tt>false</tt> (or is omitted), the task runs in the background. In this case, a network connection is created in the background, and the task runs according to the permissions for using BOSS. 413 If a task running in the background is canceled—for example, because of loss of connection—the task enters a waiting-for-retry state and no error is generated. 414 A task in the waiting-for-retry state creates a connection to the infrastructure network in the background, and resumes execution according to permissions for using BOSS. 415 This function can be used when the user wants to run a task immediately, when it would normally be run periodically in the background. 416 417 When this method is used, if there is a task currently running, that task is suspended and the applicable task runs immediately. 418 <b>Note:</b> There is a limit to the number of tasks that BOSS can run simultaneously in parallel. If multiple tasks are already running with this method at the same time, the task may not run immediately in some cases. 419 420 421 @param[in] isForegroundRun Specify whether to run in the foreground. If omitted, the task is run in the background. 422 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 423 @retval Result::IsSuccess The instruction to start the task immediately succeeded. 424 @retval ResultNotConnectNetwork Not connected to the infrastructure network. When running in the foreground, the user must connect to the infrastructure network before using this method. 425 @retval ResultInvalidTaskId Indicates that the task ID pointer is <tt>NULL</tt> or a zero-length string. 426 @retval ResultNotExist Indicates that the specified task ID was not found. Confirm whether it is registered yet. 427 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 428 @retval ResultNotConnectNetwork Although foreground execution was specified, the console is not connected to the infrastructure network. When running in the foreground, the call originator must have an infrastructure network connection implemented using the AC library. 429 @retval nn::ac::ResultNotAcInitialized Although foreground execution was specified, the <tt>nn::ac::Initialize</tt> function has not been called. When running in the foreground, the call originator must have an infrastructure network connection implemented using the AC library. 430 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 431 */ 432 nn::Result Run(bool isForegroundRun = false); 433 434 435 /*! 436 @brief Stops scheduled execution of a task. 437 438 You can use the <tt>@ref StartScheduling</tt> function to restart a task that has been suspended. 439 If a task has been suspended, calling the <tt>@ref GetState</tt> function returns <tt>@ref STOP</tt> as the state of the task. 440 If the applicable task is currently running, the task is canceled. 441 442 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 443 @retval Result::IsSuccess Indicates success. 444 @retval ResultInvalidTaskId Indicates that the task ID pointer is <tt>NULL</tt> or a zero-length string. 445 @retval ResultNotExist Indicates that the specified task ID was not found. Confirm whether it is registered yet. 446 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 447 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 448 */ 449 nn::Result StopScheduling(void); 450 451 /*! 452 @brief Cancels execution of a task that is in progress. Unlike <tt>@ref CancelSync</tt>, this is an asynchronous function, only triggering a cancel and returning immediately. 453 454 This function is provided to stop immediate execution tasks. 455 It performs nothing for tasks in a state other than <tt>RUNNING</tt>, <tt>WAITING_RUN</tt>, and <tt>WAITING_RESUME</tt>. 456 457 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 458 @retval Result::IsSuccess Indicates success. 459 @retval ResultInvalidTaskId Indicates that the task ID pointer is <tt>NULL</tt> or a zero-length string. 460 @retval ResultNotExist Indicates that the specified task ID was not found. Confirm whether it is registered yet. 461 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 462 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 463 */ 464 void Cancel(CancelMode cancelModel = CANCEL_TO_STOP); 465 466 /*! 467 @brief Cancels execution of a task that is in progress. Unlike <tt>@ref Cancel</tt>, this synchronous function blocks until cancellation of execution is completed. 468 469 This function is provided to stop immediate execution tasks. 470 It performs nothing for tasks in a state other than <tt>RUNNING</tt>, <tt>WAITING_RUN</tt>, and <tt>WAITING_RESUME</tt>. 471 472 @return Returns the result of the function. Returns one of the following <tt>Result</tt> values. 473 @retval Result::IsSuccess Indicates success. 474 @retval ResultInvalidTaskId Indicates that the task ID pointer is <tt>NULL</tt> or a zero-length string. 475 @retval ResultNotExist Indicates that the specified task ID was not found. Confirm whether it is registered yet. 476 @retval ResultLibraryNotInitialized Indicates that the session is not initialized. If this function is called before <tt>@ref boss::Initialize</tt> is called, this <tt>Result</tt> is returned. Always call the <tt>@ref boss::Initialize</tt> function before you use the BOSS library. 477 @retval Other Indicates an unexpected error. (For more information, see <tt>@ref nn_boss_result</tt>.) 478 */ 479 void CancelSync(CancelMode cancelModel = CANCEL_TO_STOP); 480 481 /*! 482 @brief Cancels execution of a task that is in progress. This function is the same as <tt>@ref CancelSync</tt>, except that it also has a timeout feature. 483 484 For more information, see the <tt>@ref CancelSync</tt> function, which is the same, but without a timeout feature. 485 486 It does nothing for tasks in a state other than <tt>RUNNING</tt>, <tt>WAITING_RUN</tt>, and <tt>WAITING_RESUME</tt>. 487 This function is provided to stop immediate execution tasks. 488 489 */ 490 bool CancelSync(u32 timeoutMsec, CancelMode cancelModel = CANCEL_TO_STOP); 491 492 493 494 /*! 495 @brief Waits until a task assumes a certain state. 496 497 This method blocks until the applicable task enters the specified state. 498 @param[in] waitState Specifies the waiting state. If this argument is omitted, the function waits for the default <tt>@ref TWS_DONE</tt> (task completed) state. 499 */ 500 void Wait(TaskWaitState waitState = TWS_DONE); 501 502 /*! 503 @brief Waits until a task assumes a certain state. This is a version of the <tt>@ref Wait</tt> function that takes a timeout value as an argument. 504 505 For more information, see the version of the <tt>@ref Wait</tt> function that does not take a timeout value. 506 507 @param[in] timeoutSec Specifies the timeout. The unit is seconds. 508 @param[in] waitState Specifies the waiting state. If this argument is omitted, the function waits for the default <tt>@ref TWS_DONE</tt> (task completed) state. 509 @return Returns the reason for returning from the method. Either the task entered the specified state, or the timeout occurred. 510 @retval true Indicates the task reached the specified state. 511 @retval false Indicates that the task timed out. 512 513 */ 514 bool Wait(u32 timeoutSec, TaskWaitState waitState = TWS_DONE); 515 516 517 /*! 518 @brief Gets the state of a task. 519 520 @param[out] pExecCount Returns the task execution count for the status code being obtained. 521 @return Returns the task state. 522 */ 523 TaskState GetState( u32* pExecCount = NULL ) const; 524 525 /*! 526 @brief Gets the HTTP status code from the last time a task executed. 527 528 @param[out] pExecCount Returns the task execution count for the status code being obtained. 529 @return Returns the HTTP status code from the last time a task executed. 530 @retval 0 Indicates the status code could not be obtained. (Occurs when the task has not executed even once, or the task does not use HTTP communication.) 531 */ 532 s32 GetHttpStatusCode( u32* pExecCount = NULL ) const; 533 534 /*! 535 @brief Gets the detailed result for the last time a task executed. 536 537 For more information about task results, see <tt>@ref TaskResult</tt>. 538 This function cannot be used on tasks that have not yet been registered or executed. For example, if the <tt>@ref Task::Register</tt> function fails, this function cannot be used on that instance of that task. 539 If this function is used on such a task, it returns a <tt>@ref TaskResult</tt> indicating that the result of the task is unknown. 540 541 @param[out] pExecCount Returns a number indicating which task execution the detailed results are for (1 for the first execution, 2 for the second, and so on). 542 @return Returns the result from the last task execution. 543 */ 544 TaskResult GetResult( u32* pExecCount = NULL ) const; 545 546 /*! 547 @brief Gets the state of the currently executing task turn. 548 549 If the task cannot yet be run (<tt>@ref TTS_WAITING_RUN</tt>), returns the result from the previous task turn. 550 Returns the task turn state at that time if the task has not run even once, or <tt>@ref ClearTurnState</tt> has just been run, even if the task is not in a runnable state. 551 552 @param[out] pExecCount Returns a number indicating which task execution the results are for (1 for the first execution, 2 for the second, and so on). 553 @return Returns the state for the currently running task turn or the previously run task turn. 554 555 */ 556 TaskTurnState GetTurnState( u32* pExecCount = NULL ) const; 557 558 559 /*! 560 @brief Clears the task turn state. 561 562 Immediately after calling this method, <tt>@ref GetTurnState</tt> returns the state or result of the task turn at that point. 563 To check for the end of execution of a task turn by polling, call this method followed by the <tt>@ref GetTurnState</tt> method. 564 */ 565 void ClearTurnState( void ); 566 567 /*! 568 @brief Gets the number of executions of a task at the time the function is called. This value also gives the number of times a task executed after it has executed for the last time. 569 570 @return Returns the number of times the task has executed. 571 572 */ 573 u32 GetExecCount( void ) const; 574 575 /*! 576 @brief Gets the priority for current task execution. 577 578 If the priority has been temporarily set by a policy list to something different from when the task was registered, the temporary priority level is returned. 579 580 @return Returns the current task execution priority. 581 */ 582 TaskPriority GetPriority(void) const; 583 584 585 586 /*! 587 @brief Gets the size of the task's data. 588 589 Until a task enters the <tt>Running</tt> state, it holds the data size for the previous time it ran, and zero if it has not run at all. 590 In the <tt>Running</tt> state, it is initially reset to zero. When a data size is defined, the value can be obtained. 591 592 Note that even if the values obtained by <tt>GetContentLength</tt> and <tt>GetProcessedLength</tt> match, the task processing after the communication completes may not have completed. 593 Use <tt>Task::GetTurnState</tt> to verify that the task processing has completed. 594 595 @param[out] pExecCount Returns a number indicating which task execution the obtained size is for (1 for the first execution, 2 for the second, and so on). 596 @return Returns the size of the task's data. 597 */ 598 s64 GetContentLength( u32* pExecCount = NULL ) const; 599 600 /*! 601 @brief Gets the size of data already sent or received by the task. 602 603 Until a task enters the <tt>Running</tt> state, this function holds the size of the received data from the previous time it completed the task execution. (If it has not executed the task at all, the function holds a data size of zero.) 604 When this function runs, the value is first reset to zero, and then it is updated periodically as data is processed. 605 606 Note that even if the values obtained by <tt>GetContentLength</tt> and <tt>GetProcessedLength</tt> match, the task processing after the communication completes may not have completed. 607 Use <tt>Task::GetTurnState</tt> to verify that the task processing has completed. 608 609 @param[out] pExecCount Returns a number indicating which task execution the obtained size is for (1 for the first execution, 2 for the second, and so on). 610 @return Returns the size of data already processed by the task. 611 */ 612 s64 GetProcessedLength( u32* pExecCount = NULL ) const; 613 614 /*! 615 @brief Gets the task ID. 616 617 Returns the task ID set for this instance using the <tt>@ref Initialize</tt> function. 618 619 @return Returns the task ID. 620 */ 621 TaskID GetTaskID( void ) const; 622 623 624 /*! 625 @brief Gets the title ID of the task. 626 627 This ID cannot be specified in the <tt>@ref Task</tt> class, so this function always returns the value <tt>TitleID(0)</tt>. 628 629 @return Returns the title ID of the task. 630 */ 631 TitleID GetTitleID( void ) const; 632 633 634 635 /*! 636 @brief Gets the execution state of the task. 637 638 @param[out] pExecCount Returns a number indicating which task execution the obtained size is for (1 for the first execution, 2 for the second, and so on). 639 @return Returns the execution state of the task. 640 */ 641 TaskRunningState GetRunningState( u32* pExecCount = NULL ) const; 642 643 644 /*! 645 @brief Gets the option execution results from the last time a task executed. 646 647 Unlike the common task execution results that are retrieved from <tt>@ref GetResult</tt>, the execution results of an option have different meanings depending on the task type. 648 The availability of option execution results depends on the task type. 649 For more information about the availability and types of option execution results for each task, see the programming manual. 650 651 @param[in] optionKind Specifies the option type. The type of value that can be set depends on the task type. 652 @param[out] pExecCount Returns a number indicating which task execution the detailed results are for (1 for the first execution, 2 for the second, and so on). 653 @return Returns the option execution results from the last task execution. Returns <tt>0</tt> if the target task has no option execution results for the specified <var>optionKind</var>. 654 */ 655 u64 GetOptionResult( u32 optionKind, u32* pExecCount = NULL ) const; 656 657 658 /*! 659 @deprecated This API function is outdated. Do not use it. 660 */ 661 explicit Task( const char* taskId, AccountID accountId ); 662 663 /*! 664 @deprecated This API function is outdated. Do not use it. 665 */ 666 nn::Result Initialize(const char* taskId, AccountID accountId ); 667 668 /*! 669 @deprecated This API function is outdated. Do not use it. 670 */ 671 AccountID GetAccountID( void ) const; 672 673 protected: 674 AccountID m_accountId; 675 u8 padding[4]; 676 TaskID m_taskId; 677 TitleID m_titleId; 678 }; 679 680 //! @} 681 682 } // end of namespace boss 683 } // end of namespace nn 684 685 #endif // __cplusplus 686 687 #endif /* NN_BOSS_BOSS_TASK_H_ */ 688 689