ZLMediaKit/src/Onvif/Onvif.h
xia-chu adb844032d
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
macOS / build (push) Has been cancelled
Windows / build (push) Has been cancelled
初步添加onvif客户端
2025-11-22 08:40:25 +08:00

51 lines
1.7 KiB
C++

/*
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
*
* Use of this source code is governed by MIT-like license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#ifndef ZLMEDIAKIT_ONVIF_H
#define ZLMEDIAKIT_ONVIF_H
#include <vector>
#include <map>
#include "Network/Socket.h"
#include "Network/Buffer.h"
class OnvifSearcher : public std::enable_shared_from_this<OnvifSearcher> {
public:
//返回false代表不再监听事件
using onDevice = std::function<bool(const std::map<std::string, std::string> &device_info, const std::string &onvif_url)>;
OnvifSearcher();
static OnvifSearcher &Instance();
void sendSearchBroadcast(onDevice cb = nullptr, uint64_t timeout_ms = 10 * 1000);
private:
void onDeviceResponse(const toolkit::Buffer::Ptr &buf, struct sockaddr *addr, int addr_len);
void onGotDevice(const std::string &uuid, std::map<std::string, std::string> &device_info, const std::string &onvif_url);
void sendSearchBroadcast_l(onDevice cb, uint64_t timeout_ms);
private:
struct onDeviceCB{
onDevice cb;
toolkit::Ticker ticker;
uint64_t timeout_ms;
bool expired() const;
bool operator()(std::map<std::string, std::string> &device_info, const std::string &onvif_url);
};
private:
toolkit::EventPoller::Ptr _poller;
toolkit::Timer::Ptr _timer;
std::vector<toolkit::Socket::Ptr> _sock_list;
std::unordered_map<std::string/*uuid*/, onDeviceCB> _cb_map;
};
#endif //ZLMEDIAKIT_ONVIF_H