/*
 * DhcpClient.h
 *
 *  Created on: Mar 25, 2023
 *      Author: ZKSWE Develop Team
 */

#ifndef _NET_DHCP_CLIENT_H_
#define _NET_DHCP_CLIENT_H_

#include <stdint.h>
#include <string>
#include "system/Thread.h"

typedef enum {
	E_DHCP_LEASE_TYPE_SUCCESS,
	E_DHCP_LEASE_TYPE_FAIL,
	E_DHCP_LEASE_TYPE_TIMEOUT
} dhcp_lease_type_e;

typedef void (*dhcp_lease_cb)(dhcp_lease_type_e type, void *data);

namespace net {

class DhcpClient : public Thread {
public:
	DhcpClient();
	virtual ~DhcpClient();

	void set_lease_cb(dhcp_lease_cb cb);
	bool start(const char *ip, const char *macaddr, const char *gateway);
	void stop();

protected:
	bool threadLoop();
	bool renew();

private:
	std::string ip_;
	std::string macaddr_;
	std::string gateway_;
	dhcp_lease_cb lease_cb_;
	uint32_t record_time_;
	uint32_t lease_;
	uint32_t record_lease_;
	int wakeup_[2];

};

}

#endif /* _NET_DHCP_CLIENT_H_ */
