main.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. *
  3. * Copyright (c) 2023 Project CHIP Authors
  4. * All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "RvcAppCommandDelegate.h"
  19. #include "rvc-device.h"
  20. #include <AppMain.h>
  21. #define RVC_ENDPOINT 1
  22. using namespace chip;
  23. using namespace chip::app;
  24. using namespace chip::app::Clusters;
  25. namespace {
  26. constexpr const char kChipEventFifoPathPrefix[] = "/tmp/chip_rvc_fifo_";
  27. NamedPipeCommands sChipNamedPipeCommands;
  28. RvcAppCommandDelegate sRvcAppCommandDelegate;
  29. } // namespace
  30. RvcDevice * gRvcDevice = nullptr;
  31. void ApplicationInit()
  32. {
  33. std::string path = kChipEventFifoPathPrefix + std::to_string(getpid());
  34. if (sChipNamedPipeCommands.Start(path, &sRvcAppCommandDelegate) != CHIP_NO_ERROR)
  35. {
  36. ChipLogError(NotSpecified, "Failed to start CHIP NamedPipeCommands");
  37. sChipNamedPipeCommands.Stop();
  38. }
  39. gRvcDevice = new RvcDevice(RVC_ENDPOINT);
  40. gRvcDevice->Init();
  41. sRvcAppCommandDelegate.SetRvcDevice(gRvcDevice);
  42. }
  43. void ApplicationShutdown()
  44. {
  45. delete gRvcDevice;
  46. gRvcDevice = nullptr;
  47. sChipNamedPipeCommands.Stop();
  48. }
  49. int main(int argc, char * argv[])
  50. {
  51. if (ChipLinuxAppInit(argc, argv) != 0)
  52. {
  53. return -1;
  54. }
  55. ChipLinuxAppMainLoop();
  56. return 0;
  57. }