+++ /dev/null
-set(COMPONENT_NAME "timeservice")
-
-set(PUBLIC_HEADER
-)
-
-set(PRIVATE_HEADER
-${CMAKE_CURRENT_SOURCE_DIR}/include
-)
-
-set(SOURCES
-${CMAKE_CURRENT_SOURCE_DIR}/src/TimeServiceImpl.c
-)
-
-set(COMPONENT_PUBLIC_CCFLAGS
-)
-
-set(COMPONENT_CCFLAGS
- -Wno-error
- -Wno-unused-parameter
- -fno-exceptions
- -fno-unwind-tables
- -fno-asynchronous-unwind-tables
- -Wno-undef
- -Wno-bitwise-op-parentheses
- -Wno-shift-op-parentheses
- -nostdlibinc
- -nostdinc
- -nostdlib
- -Wno-error=unused-function
-)
-
-set(WHOLE_LINK
- true
-)
-
-set(MAIN_COMPONENT
- false
-)
-
-set(PUBLIC_DEFINES
-)
-
-set(PRIVATE_DEFINES
-)
-
-build_component()
-
-
+++ /dev/null
-
-#ifndef TIMESERVICE_H
-#define TIMESERVICE_H
-
-#include <string>
-#include <vector>
-
-class TimeUpdateListener
-{
-public:
- virtual void onTimeUpdate(const std::string &updatedTime) = 0;
- virtual ~TimeUpdateListener() {}
-};
-
-class TimeService
-{
-public:
- virtual std::string getCurrentTime() = 0;
- virtual void subscribeTimeUpdate(TimeUpdateListener *listener) = 0;
- virtual ~TimeService() {}
-};
-
-#endif // TIMESERVICE_H
\ No newline at end of file
+++ /dev/null
-
-// TimeServiceImpl.h
-#ifndef TIMESERVICEIMPL_H
-#define TIMESERVICEIMPL_H
-
-#include "TimeService.h"
-#include <thread>
-#include <chrono>
-
-class TimeServiceImpl : public TimeService {
-private:
- std::vector<TimeUpdateListener*> listeners;
-
-public:
- std::string getCurrentTime() override;
- void subscribeTimeUpdate(TimeUpdateListener* listener) override;
- void updateAndNotify();
-};
-
-#endif // TIMESERVICEIMPL_H
\ No newline at end of file
+++ /dev/null
-
-// TimeServiceImpl.cpp
-#include "TimeServiceImpl.h"
-#include <ctime>
-
-std::string TimeServiceImpl::getCurrentTime()
-{
- time_t now = time(0);
- tm *localTime = localtime(&now);
- char buffer[80];
- strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", localTime);
- return std::string(buffer);
-}
-
-void TimeServiceImpl::subscribeTimeUpdate(TimeUpdateListener *listener)
-{
- listeners.push_back(listener);
-}
-
-void TimeServiceImpl::updateAndNotify()
-{
- while (true)
- {
- std::string updatedTime = getCurrentTime();
- for (TimeUpdateListener *listener : listeners)
- {
- listener->onTimeUpdate(updatedTime);
- }
- std::this_thread::sleep_for(std::chrono::seconds(1));
- }
-}
\ No newline at end of file