You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

service.h 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_SERVICE_H_
  17. #define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_SERVICE_H_
  18. #include <atomic>
  19. #include "minddata/dataset/util/lock.h"
  20. #include "minddata/dataset/util/status.h"
  21. namespace mindspore {
  22. namespace dataset {
  23. class Service {
  24. public:
  25. enum class STATE : int { kStartInProg = 1, kRunning, kStopInProg, kStopped };
  26. Service() : state_(STATE::kStopped) {}
  27. Service(const Service &) = delete;
  28. Service &operator=(const Service &) = delete;
  29. virtual ~Service() {}
  30. STATE ServiceState() const { return state_; }
  31. virtual Status DoServiceStart() = 0;
  32. virtual Status DoServiceStop() = 0;
  33. Status ServiceStart();
  34. Status ServiceStop() noexcept;
  35. protected:
  36. STATE state_;
  37. RWLock state_lock_;
  38. };
  39. } // namespace dataset
  40. } // namespace mindspore
  41. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_SERVICE_H_