Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
teonet.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1996-2019 Kirill Scherba <kirill@scherba.ru>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /*
18  * File: teonet.hpp
19  * Author: Kirill Scherba <kirill@scherba.ru>
20  *
21  * Created on October 18, 2017, 11:03 AM
22  *
23  * Teonet c++ wrapper
24  */
25 
37 //#pragma once
38 #ifndef THIS_TEONET_H
39 #define THIS_TEONET_H
40 
41 #include <cstring>
42 #include <iostream>
43 #include <memory>
44 #include <string>
45 #include <vector>
46 
47 #include "ev_mgr.h"
48 #include "modules/log_reader.h"
49 #include "modules/subscribe.h"
50 #include "modules/teodb_com.h"
51 
52 namespace teo {
53 
57 typedef struct teoL0Client {
58 
59  const char* name;
60  uint8_t name_len;
61  const char* addr;
62  int port;
63 
64  teoL0Client(const char* name, uint8_t name_len, const char* addr, int port)
65  : name(strdup(name)), name_len(name_len), addr(strdup(addr)), port(port) {}
66 
67  teoL0Client(const std::string& name, const std::string& addr, int port)
68  : teoL0Client(name.c_str(), name.size() + 1, addr.c_str(), port) {}
69 
70  virtual ~teoL0Client() {
71  free((void*)name);
72  free((void*)addr);
73  }
74 
75 } teoL0Client;
76 
81 namespace unique_raw_ptr {
82 
83 template <typename T> struct destroy {
84  void operator()(T x) { free((void*)x); }
85 };
86 
87 template <typename T> std::unique_ptr<T[], destroy<T*>> make(T* raw_data) {
88  std::unique_ptr<T[], destroy<T*>> str_ptr(raw_data);
89  return str_ptr;
90 }
91 } // namespace unique_raw_ptr
92 
98 class Teonet {
99 
100 public:
104  typedef void (*teoEventsCb)(Teonet& teo, teoEvents event, void* data, size_t data_len,
105  void* user_data);
106 
107 private:
108  ksnetEvMgrClass* ke;
109  teoEventsCb event_cb;
110  const char* classVersion = "0.0.4";
111 
112 public:
113  inline ksnetEvMgrClass* getKe() const { return ke; }
114 
115 public:
131  Teonet(int argc, char** argv, teoEventsCb event_cb = NULL, int options = READ_ALL, int port = 0,
132  void* user_data = NULL) {
133 
134  this->event_cb = event_cb;
135  ke = ksnetEvMgrInitPort(
136  argc, argv,
137  [](ksnetEvMgrClass* ke, teoEvents e, void* data, size_t data_len, void* user_data) {
138  auto teonet_ptr = static_cast<Teonet*>(ke->teo_class);
139  teonet_ptr->eventCb(e, data, data_len, user_data);
140  },
141  options, port, user_data);
142  if(ke) ke->teo_class = this;
143  }
144 
148  virtual ~Teonet() { /*std::cout << "Destructor Teonet\n";*/
149  }
150 
156  inline void setAppType(const char* type) { teoSetAppType(ke, (char*)type); }
157 
163  inline void setAppVersion(const char* version) { teoSetAppVersion(ke, (char*)version); }
164 
170  inline int run() { return ksnetEvMgrRun(ke); }
171 
182  void BroadcastSend(const char* to, uint8_t cmd, void* data, size_t data_len) const {
183  teoBroadcastSend(ke->kc, (char*)to, cmd, data, data_len);
184  }
185  inline ksnet_arp_data* sendTo(const char* to, uint8_t cmd, void* data, size_t data_len) const {
186  return ksnCoreSendCmdto(ke->kc, (char*)to, cmd, data, data_len);
187  }
188  inline ksnet_arp_data* sendTo(const char* to, uint8_t cmd, const std::string& data) const {
189  return sendTo((char*)to, cmd, (void*)data.c_str(), data.size() + 1);
190  }
200  inline void sendToA(const char* to, uint8_t cmd, void* data, size_t data_len) const {
201  ksnCoreSendCmdtoA((void*)ke, to, cmd, data, data_len);
202  }
203  inline void sendToA(const char* to, uint8_t cmd, const std::string& data) const {
204  sendToA(to, cmd, (void*)data.c_str(), data.size() + 1);
205  }
206 
218  inline void sendAnswerTo(teo::teoPacket* rd, const char* name, void* data,
219  size_t data_len) const {
220  sendCmdAnswerTo(ke, rd, (char*)name, data, data_len);
221  }
222  inline void sendAnswerTo(teo::teoPacket* rd, const char* name, const std::string& data) const {
223  sendAnswerTo(rd, (char*)name, (void*)data.c_str(), data.size() + 1);
224  }
236  inline void sendAnswerToA(teo::teoPacket* rd, uint8_t cmd, void* data, size_t data_len) const {
237  sendCmdAnswerToBinaryA(ke, rd, cmd, (void*)data, data_len);
238  }
239  inline void sendAnswerToA(teo::teoPacket* rd, uint8_t cmd, const std::string& data) const {
240  sendCmdAnswerToBinaryA(ke, rd, cmd, (void*)data.c_str(), data.size() + 1);
241  }
242 
252  int sendEchoTo(const char* to, void* data = NULL, size_t data_len = 0) const {
253  if(!data || !data_len) {
254  data = (void*)"Hello Teonet!";
255  data_len = std::strlen((char*)data) + 1;
256  }
257  return ksnCommandSendCmdEcho(ke->kc->kco, (char*)to, data, data_len);
258  }
259 
273  inline int sendToL0(const char* addr, int port, const char* cname, size_t cname_length,
274  uint8_t cmd, void* data, size_t data_len) const {
275  return ksnLNullSendToL0(ke, (char*)addr, port, (char*)cname, cname_length, cmd, data, data_len);
276  }
277  inline int sendToL0(const char* addr, int port, const std::string& cname, uint8_t cmd, void* data,
278  size_t data_len) const {
279  return sendToL0(addr, port, cname.c_str(), cname.size() + 1, cmd, data, data_len);
280  }
281  inline int sendToL0(const char* addr, int port, const std::string& cname, uint8_t cmd,
282  const std::string& data) const {
283  return sendToL0(addr, port, cname.c_str(), cname.size() + 1, cmd, (void*)data.c_str(),
284  data.size() + 1);
285  }
286 
297  inline int sendToL0(teoL0Client* l0cli, uint8_t cmd, void* data, size_t data_len) const {
298 
299  return sendToL0(l0cli->addr, l0cli->port, l0cli->name, l0cli->name_len, cmd, data, data_len);
300  }
301 
314  inline void sendToL0A(const char* addr, int port, const char* cname, size_t cname_length,
315  uint8_t cmd, void* data, size_t data_len) const {
317  rd.from = (char*)cname;
318  rd.from_len = cname_length;
319  rd.addr = (char*)addr;
320  rd.port = port;
321  rd.l0_f = 1;
322  sendCmdAnswerToBinaryA((void*)ke, &rd, cmd, data, data_len);
323  }
324 
338  inline int sendEchoToL0(const char* addr, int port, const char* cname, size_t cname_length,
339  void* data, size_t data_len) const {
340 
341  return ksnLNullSendEchoToL0(ke, (char*)addr, port, (char*)cname, cname_length, data, data_len);
342  }
343 
344  inline int sendEchoToL0A(const char* addr, int port, const char* cname, size_t cname_length,
345  void* data, size_t data_len) const {
346 
347  return ksnLNullSendEchoToL0A(ke, (char*)addr, port, (char*)cname, cname_length, data, data_len);
348  }
349 
359  inline int sendEchoToL0(teoL0Client* l0cli, void* data, size_t data_len) const {
360  return sendEchoToL0(l0cli->addr, l0cli->port, l0cli->name, l0cli->name_len, data, data_len);
361  }
362  inline int sendEchoToL0A(teoL0Client* l0cli, void* data, size_t data_len) const {
363  return sendEchoToL0A(l0cli->addr, l0cli->port, l0cli->name, l0cli->name_len, data, data_len);
364  }
365 
366  inline void subscribe(const char* peer_name, uint16_t ev) const {
367  teoSScrSubscribe((teoSScrClass*)ke->kc->kco->ksscr, (char*)peer_name, ev);
368  }
369  inline void subscribeA(const char* peer_name, uint16_t ev) const {
370  teoSScrSubscribeA((teoSScrClass*)ke->kc->kco->ksscr, (char*)peer_name, ev);
371  }
372 
373  inline void sendToSscr(uint16_t ev, void* data, size_t data_length, uint8_t cmd = 0) const {
374  teoSScrSend((teoSScrClass*)ke->kc->kco->ksscr, ev, data, data_length, cmd);
375  }
376  inline void sendToSscr(uint16_t ev, const std::string& data, uint8_t cmd = 0) const {
377  sendToSscr(ev, (void*)data.c_str(), data.size() + 1, cmd);
378  }
379  inline void sendToSscrA(uint16_t ev, const std::string& data, uint8_t cmd = 0) const {
380  teoSScrSendA(ke, ev, (void*)data.c_str(), data.size() + 1, cmd);
381  }
382 
388  inline void setCustomTimer(double time_interval = 2.00) {
389  ksnetEvMgrSetCustomTimer(ke, time_interval);
390  }
391 
397  inline const char* getClassVersion() const { return classVersion; }
398 
404  static inline const char* getTeonetVersion() { return teoGetLibteonetVersion(); }
405 
411  inline const char* getHostName() const { return ksnetEvMgrGetHostName(ke); }
412 
420  static teo::teoAppParam* appParam(std::vector<const char*> params,
421  std::vector<const char*> params_description) {
422 
423  params.insert(params.begin(), "");
424  params_description.insert(params_description.begin(), "");
425 
426  static teo::teoAppParam app_param;
427  app_param.app_argc = params.size();
428  app_param.app_argv = reinterpret_cast<const char**>(params.data());
429  app_param.app_descr = reinterpret_cast<const char**>(params_description.data());
430  return &app_param;
431  };
432 
439  inline const char* getParam(int parm_number) const {
440  return getKe()->teo_cfg.app_argv[parm_number];
441  }
442 
450  inline double getTime() const { return ksnetEvMgrGetTime(ke); }
451 
457  inline const std::string getPath() {
458  char *data_path = getDataPath();
459  std::string data_path_str(data_path);
460  free(data_path);
461  return data_path_str;
462  }
463 
468  inline void stop() { ksnetEvMgrStop(ke); }
469 
476  inline teo::teoPacket* getPacket(void* data) const { return (teo::teoPacket*)data; }
477 
484  inline void metricCounter(const std::string &name, int value) {
485  teoMetricCounter(ke->tm, name.c_str(), value);
486  }
487 
494  inline void metricCounter(const std::string &name, double value) {
495  teoMetricCounterf(ke->tm, name.c_str(), value);
496  }
497 
504  inline void metricMs(const std::string &name, double value) {
505  teoMetricMs(ke->tm, name.c_str(), value);
506  }
507 
514  inline void metricGauge(const std::string &name, int value) {
515  teoMetricGauge(ke->tm, name.c_str(), value);
516  }
517 
524  inline void metricGauge(const std::string &name, double value) {
525  teoMetricGaugef(ke->tm, name.c_str(), value);
526  }
527 
536  virtual inline void eventCb(teo::teoEvents event, void* data, size_t data_len, void* user_data) {
537 
538  if(event_cb) event_cb(*this, event, data, data_len, user_data);
539  };
540 
541  virtual void cqueueCb(uint32_t id, int type, void* data) {}
542 
543 #ifdef DEBUG_KSNET
544 #define teo_printf(module, type, format, ...) \
545  ksnet_printf(&((getKe())->teo_cfg), type, \
546  type != DISPLAY_M ? _ksn_printf_format_(format) \
547  : _ksn_printf_format_display_m(format), \
548  type != DISPLAY_M ? _ksn_printf_type_(type) : "", \
549  type != DISPLAY_M ? (module[0] == '\0' ? (getKe())->teo_cfg.app_name : module) : "", \
550  type != DISPLAY_M ? __func__ : "", type != DISPLAY_M ? __FILE__ : "", \
551  type != DISPLAY_M ? __LINE__ : 0, __VA_ARGS__)
552 
553 #define teo_puts(module, type, format) \
554  ksnet_printf(&((getKe())->teo_cfg), type, \
555  type != DISPLAY_M ? _ksn_printf_format_(format) "\n" \
556  : _ksn_printf_format_display_m(format) "\n", \
557  type != DISPLAY_M ? _ksn_printf_type_(type) : "", \
558  type != DISPLAY_M ? (module[0] == '\0' ? (getKe())->teo_cfg.app_name : module) : "", \
559  type != DISPLAY_M ? __func__ : "", type != DISPLAY_M ? __FILE__ : "", \
560  type != DISPLAY_M ? __LINE__ : 0)
561 
562 #else
563 #define teo_printf(module, type, format, ...) ;
564 #define teo_puts(module, type, format) ;
565 #endif
566 
567  template <typename... Arguments>
568  inline std::string formatMessage(const char* format, const Arguments&... args) {
569  const char* cstr = ksnet_formatMessage(format, args...);
570  std::string str(cstr);
571  free((void*)cstr);
572  return str;
573  }
574 
577 
581  class CQue {
582 
583  public:
584  typedef std::unique_ptr<CQue> cquePtr;
585 
586  private:
587  Teonet* teo;
588  ksnCQueClass* kq;
589 
590  public:
591  explicit CQue(Teonet* t, bool send_event = false)
592  : teo(t), kq(ksnCQueInit(t->getKe(), send_event)) { /*std::cout << "CQue::CQue\n";*/
593  }
594  CQue(const CQue& obj) : teo(obj.teo), kq(obj.kq) { /*std::cout << "CQue::CQue copy\n";*/
595  }
596  virtual ~CQue() { ksnCQueDestroy(kq); /*std::cout << "~CQue::CQue\n";*/ }
597 
609  template <typename Callback, typename T>
610  cqueData* add(Callback cb, T timeout = 5.00, void* user_data = NULL) {
611 
612  struct userData {
613  void* user_data;
614  Callback cb;
615  };
616  userData* ud = new userData{user_data, cb};
617  return ksnCQueAdd(kq,
618  [](uint32_t id, int type, void* data) {
619  userData* ud = static_cast<userData*>(data);
620  ud->cb(id, type, ud->user_data);
621  delete(ud);
622  },
623  (double)timeout, ud);
624  }
625 
626  template <typename T>
627  inline cqueData* add(cqueCallback cb, T timeout = 5.00, void* user_data = NULL) {
628 
629  return ksnCQueAdd(kq, cb, (double)timeout, user_data);
630  }
631 
632  template <typename T> inline cqueData* add(T timeout = 5.00, void* user_data = NULL) {
633  return ksnCQueAdd(kq, NULL, (double)timeout, user_data);
634  }
635 
636  inline int remove(uint32_t id) {
637  return ksnCQueRemove(kq, id);
638  }
639 
640  template <typename Callback>
641  inline void* find(void* find, const Callback compare, size_t* key_length = NULL) {
642  return ksnCQueFindData(kq, find, compare, key_length);
643  }
644 
645  template <typename Callback>
646  inline void* find(const std::string& find, const Callback compare, size_t* key_length = NULL) {
647  return ksnCQueFindData(kq, (void*)find.c_str(), compare, key_length);
648  }
649 
659  inline int exec(uint32_t id) { return ksnCQueExec(kq, id); }
660 
668  inline cqueData* getData(void* data) const { return (cqueData*)data; }
669 
670  inline void* getCQueData(int id) const { return ksnCQueGetData(kq, id); }
671 
678  inline uint32_t getId(cqueData* cd) const { return cd->id; }
679 
685  inline Teonet* getTeonet() const { return teo; }
686 
695  int setUserData(uint32_t id, void* data) {
696  int retval = -1;
697  struct userData {
698  void* user_data;
699  void* cb;
700  };
701  auto ud = static_cast<userData*>(ksnCQueGetData(kq, id));
702  if(ud) {
703  ud->user_data = data;
704  retval = 0;
705  }
706  return retval;
707  }
708  };
709 
715  inline CQue::cquePtr getCQueP() { return getCQue<std::unique_ptr<teo::Teonet::CQue>>(); }
716 
722  inline CQue& getCQueR() {
723  static auto cque = getCQueP();
724  return *cque;
725  }
726 
732  template <typename T> T getCQue() {
733  T cque(new CQue(this));
734  return cque;
735  }
736 
737  class TeoDB {
738 
739  public:
742  typedef struct teoDbCQueData {
743 
747  uint8_t cb_type;
748  void* user_data;
749 
751  uint8_t cb_type = 0)
752  : teodb(teoDb), tdd(tdd), l0client(l0client), cb_type(cb_type) {}
753 
754  virtual ~teoDbCQueData() {
755  if(l0client) delete(l0client);
756  }
757 
758  static inline teoL0Client* setl0Cli(const char* name, uint8_t name_len, const char* addr,
759  int port) {
760  return new teoL0Client((char*)name, name_len, (char*)addr, port);
761  }
763  return rd ? setl0Cli(rd->from, rd->from_len, rd->addr, rd->port) : NULL;
764  }
765 
766  inline auto getId() const -> decltype((*tdd)->id) { return (*tdd)->id; }
767 
768  inline auto getCbType() const -> decltype(cb_type) { return cb_type; }
769 
770  inline auto getL0Client() const -> decltype(l0client) { return l0client; }
771 
772  inline void* getKey() const { return (*tdd)->key_data; }
773  inline char* getKeyStr() const { return (char*)getKey(); }
774 
775  inline void* getValue() const { return (*tdd)->key_data + (*tdd)->key_length; }
776  inline char* getValueStr() const { return (char*)getValue(); }
777 
778  } teoDbCQueData;
779 
780  private:
781  Teonet* teo;
782  teoDbData** tdd;
783  std::string peer;
784  CQue cque = CQue(teo);
785 
786  public:
787  TeoDB(Teonet* t, const std::string& peer, teoDbData** tdd)
788  : teo(t), tdd(tdd), peer(peer) { /*std::cout << "TeoDB::TeoDB\n";*/
789  }
790  TeoDB(const TeoDB& obj)
791  : teo(obj.teo), tdd(obj.tdd), peer(obj.peer) { /*std::cout << "TeoDB::TeoDB copy\n";*/
792  }
793  virtual ~TeoDB() { /*std::cout << "~TeoDB::TeoDB\n";*/
794  }
795 
801  inline Teonet* getTeonet() const { return teo; }
802 
803  inline ksnetEvMgrClass* getKe() const { return getTeonet()->getKe(); }
804 
805  inline CQue* getCQue() { return &cque; }
806 
807  inline const char* getPeer() const { return peer.c_str(); }
808 
809  inline bool checkPeer(const char* peer_name) { return !strcmp(peer.c_str(), peer_name); }
810 
811  inline std::unique_ptr<teoDbData> prepareRequest(const void* key, size_t key_len,
812  const void* data, size_t data_len, uint32_t id,
813  size_t* tdd_len) {
814 
815  return (std::unique_ptr<teoDbData>)prepare_request_data(key, key_len, data, data_len, id,
816  tdd_len);
817  }
818 
819  static inline teoDbData* getData(teo::teoPacket* rd) {
820  return (teoDbData*)(rd ? rd->data : NULL);
821  }
822 
823  inline ksnet_arp_data* send(uint8_t cmd, const void* key, size_t key_len,
824  const void* data = NULL, size_t data_len = 0) {
825 
826  return sendTDD(cmd, key, key_len, data, data_len);
827  }
828 
829  template <typename Callback>
830  ksnet_arp_data* send(uint8_t cmd, const void* key, size_t key_len, Callback cb, double timeout,
831  uint8_t cb_type, teo::teoPacket* rd = NULL, teoDbData** tdd = NULL,
832  void* user_data = NULL) {
833 
834  // Create user data if it is NULL
835  if(!user_data) {
836  if(!tdd) tdd = this->tdd;
837  user_data = new teoDbCQueData(this, tdd, teoDbCQueData::setl0Cli(rd), cb_type);
838  }
839 
840  // Add callback to queue and wait timeout after 5 sec ...
841  struct userData {
842  void* user_data;
843  Callback cb;
844  };
845  auto ud = new userData{user_data, cb};
846  auto cq = cque.add(
847  [](uint32_t id, int type, void* data) {
848  userData* ud = static_cast<userData*>(data);
849  ud->cb(id, type, ud->user_data);
850  delete(static_cast<TeoDB::teoDbCQueData*>(ud->user_data));
851  delete(ud);
852  },
853  timeout, ud);
854  teo_printf("", DEBUG, "Register callback id %u\n", cq->id);
855  return sendTDD(cmd, key, key_len, NULL, 0, cq->id);
856  }
857 
858  ksnet_arp_data* send(uint8_t cmd, const void* key, size_t key_len, cqueCallback cb,
859  double timeout, uint8_t cb_type, teo::teoPacket* rd = NULL,
860  teoDbData** tdd = NULL, void* user_data = NULL) {
861 
862  // Create user data if it is NULL
863  if(!user_data) {
864  if(!tdd) tdd = this->tdd;
865  user_data = new teoDbCQueData(this, tdd, teoDbCQueData::setl0Cli(rd), cb_type);
866  }
867 
868  // Add callback to queue and wait timeout after 5 sec ...
869  std::cout << "!!! cqueCallback !!!\n";
870  auto cq = cque.add(cb, timeout, user_data);
871  teo_printf("", DEBUG, "Register simple callback id %u\n", cq->id);
872  return sendTDD(cmd, key, key_len, NULL, 0, cq->id);
873  }
874 
875  inline int exec(uint32_t id) { return cque.exec(id); }
876 
877  bool process(teoEvents event, void* data) {
878 
879  bool processed = false;
880  auto rd = teo->getPacket(data);
881  *tdd = getData(rd);
882 
883  // Check teonet event
884  switch(event) {
885 
886  case EV_K_RECEIVED:
887 
888  // DATA event
889  if(rd && checkPeer(rd->from)) {
890 
891  switch(rd->cmd) {
892 
893  // Get data response #132
894  case CMD_D_GET_ANSWER:
895  // Get list response #133
896  case CMD_D_LIST_ANSWER:
897  // Get list length response #135
899  // Get List range response #137
901 
902  if(*tdd && (*tdd)->id && !exec((*tdd)->id)) processed = true;
903  break;
904  }
905  }
906  break;
907 
908  default: break;
909  }
910 
911  return processed;
912  }
913 
914  private:
915  ksnet_arp_data* sendTDD(uint8_t cmd, const void* key, size_t key_len, const void* data = NULL,
916  size_t data_len = 0, uint32_t id = 0) {
917 
918  size_t tdd_len;
919  auto tddr = prepareRequest(key, key_len, data, data_len, id, &tdd_len);
920  return teo->sendTo(peer.c_str(), cmd, tddr.get(), tdd_len);
921  /*auto tddr = prepare_request_data(key, key_len, data, data_len, id, &tdd_len);
922  auto retval = teo->sendTo(peer.c_str(), cmd, tddr, tdd_len);
923  free(tddr);
924  return retval;*/
925  }
926  };
927 
928  class LogReader {
929 
930  public:
933 
934  private:
935  Teonet& teo;
936 
937  public:
938  explicit LogReader(Teonet& teo) : teo(teo) {}
939  explicit LogReader(Teonet* teo) : teo(*teo) {}
940 
941  struct PUserData {
942  virtual ~PUserData() { std::cout << "~PUserData" << std::endl; }
943  };
944 
945  template <typename AnyCallback>
946  inline Watcher* open(const char* name, const char* file_name, Flags flags = READ_FROM_BEGIN,
947  const AnyCallback& cb = nullptr) const {
948  struct UserData : PUserData {
949  AnyCallback cb;
950  explicit UserData(const AnyCallback& cb) : cb(cb) {}
951  virtual ~UserData() { std::cout << "~UserData" << std::endl; }
952  };
953  auto ud = new UserData(cb);
954  return teoLogReaderOpenCbPP(teo.getKe()->lr, name, file_name, flags,
955  [](void* data, size_t data_length, Watcher* wd) {
956  auto ud = static_cast<UserData*>(wd->user_data);
957  ud->cb(data, data_length, wd);
958  },
959  ud);
960  }
961 
962  inline int close(Watcher* wd) const {
963  if(wd->user_data) delete static_cast<PUserData*>(wd->user_data);
964  return teoLogReaderClose(wd);
965  }
966  };
967 };
968 
972 struct HostInfo {
973 
974  std::string name;
975  struct {
976  std::vector<std::string> v;
977  std::string to_string() {
978  std::string type_str = "";
979  for(size_t i = 0; i < v.size(); i++) { type_str += v[i] + (i < v.size() - 1 ? "," : ""); }
980  return type_str;
981  }
982  } type;
983  std::string version;
984  std::string teonetVersion;
985 
986  void makeTeonetVersion(uint8_t* ver, int num_dig = DIG_IN_TEO_VER) {
987  teonetVersion = "";
988  for(auto i = 0; i < num_dig; i++) {
989  teonetVersion += std::to_string(ver[i]) + (i < num_dig - 1 ? "." : "");
990  }
991  }
992 
993  explicit HostInfo(void* data) {
994  auto host_info = (host_info_data*)data;
995  makeTeonetVersion(host_info->ver);
996  size_t ptr = 0;
997  for(auto i = 0; i <= host_info->string_ar_num; i++) {
998  if(!i)
999  name = host_info->string_ar + ptr;
1000  else if(i == host_info->string_ar_num)
1001  version = host_info->string_ar + ptr;
1002  else
1003  type.v.push_back(host_info->string_ar + ptr);
1004  ptr += std::char_traits<char>::length(host_info->string_ar + ptr) + 1;
1005  }
1006  }
1007 };
1008 
1013 
1014 private:
1015  ksnet_stringArr sa;
1016  std::string sep = ",";
1017 
1018  inline ksnet_stringArr create() const { return ksnet_stringArrCreate(); }
1019  inline ksnet_stringArr split(const char* str, const char* separators, int with_empty,
1020  int max_parts) {
1021  sep = separators;
1022  return ksnet_stringArrSplit(str, separators, with_empty, max_parts);
1023  }
1024  inline ksnet_stringArr destroy(ksnet_stringArr* arr) const { return ksnet_stringArrFree(arr); }
1025  inline const char* _to_string(const char* separator) const {
1026  return ksnet_stringArrCombine(sa, separator ? separator : sep.c_str());
1027  }
1028 
1029 public:
1030  // Default constructor
1032  // std::cout << "Default constructor" << std::endl;
1033  sa = create();
1034  }
1035 
1036  // Split from const char* constructor
1037  explicit StringArray(const char* str, const char* separators = ",", bool with_empty = true,
1038  int max_parts = 0) {
1039  // std::cout << "Split from const char* constructor" << std::endl;
1040  sa = split(str, separators, with_empty, max_parts);
1041  }
1042 
1043  // Split from std::string constructor
1044  explicit StringArray(const std::string& str, const std::string& separators = ",", bool with_empty = true,
1045  int max_parts = 0)
1046  : StringArray(str.c_str(), separators.c_str(), with_empty, max_parts) {
1047  // std::cout << "Split from std::string constructor" << std::endl;
1048  }
1049 
1050  // Combine from std::vector constructor
1051  explicit StringArray(const std::vector<const char*>& vstr, const char* separators = ",") {
1052  // std::cout << "Combine from std::vector constructor" << std::endl;
1053  sa = create();
1054  sep = separators;
1055  for(auto& st : vstr) add(st);
1056  }
1057 
1058  // Assignment operator
1060  sa = create();
1061  sep = ar.sep;
1062  for(int i = 0; i < ar.size(); i++) { add(ar[i]); }
1063  return *this;
1064  }
1065 
1066  virtual ~StringArray() { destroy(&sa); }
1067 
1068 public:
1069  inline const char* operator[](int i) const { return sa[i]; }
1070 
1071  inline int size() const { return ksnet_stringArrLength(sa); }
1072  inline StringArray& add(const char* str) {
1073  ksnet_stringArrAdd(&sa, str);
1074  return *this;
1075  };
1076  inline StringArray& add(const std::string& str) {
1077  add(str.c_str());
1078  return *this;
1079  };
1080  inline std::string to_string(const char* separator = NULL) const {
1081  return std::string(unique_raw_ptr::make<const char>(_to_string(separator)).get());
1082  }
1083  inline std::string to_string(const std::string& separator) const {
1084  return to_string(separator.c_str());
1085  }
1086  inline bool move(unsigned int fromIdx, unsigned int toIdx) {
1087  return !!ksnet_stringArrMoveTo(sa, fromIdx, toIdx);
1088  }
1089 
1090  class iterator {
1091 
1092  private:
1093  using pointer = ksnet_stringArr;
1094  using reference = char*&;
1095 
1096  pointer ptr_;
1097  int idx_ = 0;
1098 
1099  public:
1100  iterator(pointer ptr, int idx) : ptr_(ptr), idx_(idx) {}
1101  const pointer operator->() { return ptr_; }
1103  idx_++;
1104  return *this;
1105  }
1106  iterator operator++(int junk) {
1107  auto rv = *this;
1108  idx_++;
1109  return rv;
1110  }
1111  bool operator==(const iterator& rhs) { return idx_ == rhs.idx_; }
1112  bool operator!=(const iterator& rhs) { return idx_ != rhs.idx_; }
1113  reference operator*() { return (ptr_)[idx_]; }
1114  };
1115 
1116  inline iterator begin() { return iterator(sa, 0); }
1117  inline iterator end() { return iterator(sa, size()); }
1118 };
1119 
1120 } // namespace teo
1121 
1122 /*
1123  * This an Utils submodule.
1124  *
1125  * - The showMessage used to show teonet messages:
1126  * showMessage(DEBUG, "Some debuf message\n");
1127  *
1128  * - The watch(x) is very useful debugging define to print variable name and it
1129  * value in next format:
1130  * variable = value
1131  *
1132  */
1133 #ifndef THIS_UTILS_H
1134 #define THIS_UTILS_H
1135 
1136 #define msg_to_string(msg) \
1137  ({ \
1138  std::ostringstream foo; \
1139  foo << msg; \
1140  foo.str(); \
1141  })
1142 
1143 #define showMessage(mtype, msg) teo_printf("", mtype, "%s", msg_to_string(msg).c_str())
1144 #define showMessageLn(mtype, msg) teo_printf("", mtype, "%s\n", msg_to_string(msg).c_str())
1145 
1146 #define watch(x) std::cout << (#x) << " = " << (x) << std::endl
1147 
1148 #ifdef __cplusplus
1149 extern "C" {
1150 #endif
1151 
1152 #ifdef __cplusplus
1153 }
1154 #endif
1155 
1156 #endif /* THIS_UTILS_H */
1157 
1158 #endif /*THIS_TEONET_H */
static teo::teoAppParam * appParam(std::vector< const char * > params, std::vector< const char * > params_description)
Create Application parameters.
Definition: teonet.hpp:420
Teonet * getTeonet() const
Get pointer to teonet class object.
Definition: teonet.hpp:801
T getCQue()
CQue class factory(maker)
Definition: teonet.hpp:732
Definition: log_reader.h:38
static teoDbData * getData(teo::teoPacket *rd)
Definition: teonet.hpp:819
#define teo_printf(module, type, format,...)
Definition: teonet.hpp:544
const char * getClassVersion() const
Get this class version.
Definition: teonet.hpp:397
int sendEchoToL0(teoL0Client *l0cli, void *data, size_t data_len) const
Send ECHO command to L0 client with teoL0Client structure.
Definition: teonet.hpp:359
const pointer operator->()
Definition: teonet.hpp:1101
ksnetEvMgrClass * getKe() const
Definition: teonet.hpp:803
Definition: teonet.hpp:737
iterator end()
Definition: teonet.hpp:1117
void teoSetAppVersion(ksnetEvMgrClass *ke, char *version)
Set Teonet application version.
Definition: ev_mgr.c:203
Watcher * open(const char *name, const char *file_name, Flags flags=READ_FROM_BEGIN, const AnyCallback &cb=nullptr) const
Definition: teonet.hpp:946
teoL0Client * l0client
Definition: teonet.hpp:746
virtual ~TeoDB()
Definition: teonet.hpp:793
teoL0Client(const char *name, uint8_t name_len, const char *addr, int port)
Definition: teonet.hpp:64
ksnCQueData * ksnCQueAdd(ksnCQueClass *kq, ksnCQueCallback cb, double timeout, void *data)
Add callback to queue.
Definition: cque.c:260
int ksnLNullSendEchoToL0(void *ke, char *addr, int port, char *cname, size_t cname_length, void *data, size_t data_len)
Send echo to L0 client.
Definition: l0-server.c:510
int run()
Start Teonet Event Manager and network communication.
Definition: teonet.hpp:170
void(* teoEventsCb)(Teonet &teo, teoEvents event, void *data, size_t data_len, void *user_data)
Teonet event callback.
Definition: teonet.hpp:104
Teo DB binary network structure.
Definition: teodb_com.h:45
void * data
Received data.
Definition: net_com.h:117
void operator()(T x)
Definition: teonet.hpp:84
#133 List response: [ key, key, ... ]
Definition: teodb_com.h:25
virtual void cqueueCb(uint32_t id, int type, void *data)
Definition: teonet.hpp:541
void teoSScrSend(teoSScrClass *sscr, uint16_t ev, void *data, size_t data_length, uint8_t cmd)
Send event and it data to all subscribers.
Definition: subscribe.c:58
teo_db_data_range teoDbDataRange
Definition: teonet.hpp:741
ksnetEvMgrClass * getKe() const
Teonet class version.
Definition: teonet.hpp:113
reference operator*()
Definition: teonet.hpp:1113
void sendAnswerToA(teo::teoPacket *rd, uint8_t cmd, const std::string &data) const
Definition: teonet.hpp:239
ksnet_arp_data * send(uint8_t cmd, const void *key, size_t key_len, cqueCallback cb, double timeout, uint8_t cb_type, teo::teoPacket *rd=NULL, teoDbData **tdd=NULL, void *user_data=NULL)
Definition: teonet.hpp:858
uint32_t id
Callback ID (equal to key)
Definition: cque.h:44
void subscribeA(const char *peer_name, uint16_t ev) const
Definition: teonet.hpp:369
const char data[]
Make it with: gcc -o post-callback post-callback.c -lcurl.
Definition: post-callback.c:23
void sendToA(const char *to, uint8_t cmd, const std::string &data) const
Definition: teonet.hpp:203
#define cq
int sendToL0(const char *addr, int port, const std::string &cname, uint8_t cmd, const std::string &data) const
Definition: teonet.hpp:281
Teonet string array class.
Definition: teonet.hpp:1012
std::unique_ptr< T[], destroy< T * > > make(T *raw_data)
Definition: teonet.hpp:87
uint32_t getId(cqueData *cd) const
Get CQue data id.
Definition: teonet.hpp:678
const char * getHostName() const
Return host name.
Definition: teonet.hpp:411
void teoMetricMs(teoMetricClass *tm, const char *name, double value)
Send time(ms) teonet metric.
Definition: metric.c:132
char * getDataPath(void)
Get path to teonet data folder.
Definition: utils.c:416
ksnet_arp_data * sendTo(const char *to, uint8_t cmd, const std::string &data) const
Definition: teonet.hpp:188
#132 Get data response: { namespace, key, data, data_len, ID } }
Definition: teodb_com.h:24
char * from
Remote peer name.
Definition: net_com.h:112
Teonet class.
Definition: teonet.hpp:98
bool operator==(const iterator &rhs)
Definition: teonet.hpp:1111
virtual ~StringArray()
Definition: teonet.hpp:1066
virtual ~PUserData()
Definition: teonet.hpp:942
ksnet_stringArr ksnet_stringArrCreate()
Create empty c string array.
Definition: string_arr.c:21
void * user_data
Definition: log_reader.h:44
teoDbCQueData(TeoDB *teoDb, teoDbData **tdd, teoL0Client *l0client=NULL, uint8_t cb_type=0)
Definition: teonet.hpp:750
void metricMs(const std::string &name, double value)
Send time(ms) metric.
Definition: teonet.hpp:504
ksnet_arp_data * sendTo(const char *to, uint8_t cmd, void *data, size_t data_len) const
Definition: teonet.hpp:185
StringArray & add(const std::string &str)
Definition: teonet.hpp:1076
void sendToSscrA(uint16_t ev, const std::string &data, uint8_t cmd=0) const
Definition: teonet.hpp:379
TeoDB * teodb
Definition: teonet.hpp:744
std::string teonetVersion
Definition: teonet.hpp:984
teoMetricClass * tm
Metric send module.
Definition: ev_mgr.h:270
int sendEchoTo(const char *to, void *data=NULL, size_t data_len=0) const
Send ECHO command to peer.
Definition: teonet.hpp:252
std::string version
Definition: teonet.hpp:983
int sendEchoToL0A(teoL0Client *l0cli, void *data, size_t data_len) const
Definition: teonet.hpp:362
cqueData * add(Callback cb, T timeout=5.00, void *user_data=NULL)
Add callback to queue.
Definition: teonet.hpp:610
char * ksnetEvMgrGetHostName(ksnetEvMgrClass *ke)
Return host name.
Definition: ev_mgr.c:571
void setAppVersion(const char *version)
Set Teonet application version.
Definition: teonet.hpp:163
uint8_t cb_type
Definition: teonet.hpp:747
void sendAnswerTo(teo::teoPacket *rd, const char *name, void *data, size_t data_len) const
Sent teonet command to peer or l0 client depend of input rd.
Definition: teonet.hpp:218
void ksnCoreSendCmdtoA(void *ke, const char *peer, uint8_t cmd, void *data, size_t data_length)
Definition: async_calls.c:368
void * ksnCQueGetData(ksnCQueClass *kq, uint32_t id)
Get callback queue data.
Definition: cque.c:200
teonet_cfg teo_cfg
KSNet configuration.
Definition: ev_mgr.h:261
ksnCQue Class structure definition
Definition: cque.h:18
int size() const
Definition: teonet.hpp:1071
void subscribe(const char *peer_name, uint16_t ev) const
Definition: teonet.hpp:366
#137 List range response: { listLength, key, ID }
Definition: teodb_com.h:31
int exec(uint32_t id)
Definition: teonet.hpp:875
double ksnetEvMgrGetTime(ksnetEvMgrClass *ke)
Get KSNet event manager time.
Definition: ev_mgr.c:701
CQue & getCQueR()
CQue class factory(maker)
Definition: teonet.hpp:722
StringArray(const std::vector< const char * > &vstr, const char *separators=",")
Definition: teonet.hpp:1051
ksnet_arp_data * send(uint8_t cmd, const void *key, size_t key_len, Callback cb, double timeout, uint8_t cb_type, teo::teoPacket *rd=NULL, teoDbData **tdd=NULL, void *user_data=NULL)
Definition: teonet.hpp:830
void ksnetEvMgrStop(ksnetEvMgrClass *ke)
Stop event manager.
Definition: ev_mgr.c:259
ksnetEvMgrAppParam teoAppParam
Teonet Packet.
Definition: teonet.hpp:56
int app_argc
Definition: ev_mgr.h:234
#5 This host Received a data
Definition: ev_mgr.h:128
Application parameters user data.
Definition: ev_mgr.h:232
void teoMetricCounter(teoMetricClass *tm, const char *name, int value)
Send counter teonet metric.
Definition: metric.c:108
void(* ksnCQueCallback)(uint32_t id, int type, void *data)
ksnCQue callback function definition
Definition: cque.h:34
teoDbData ** tdd
Definition: teonet.hpp:745
CQue(const CQue &obj)
Definition: teonet.hpp:594
cqueData * getData(void *data) const
Get pointer to CQue data structure.
Definition: teonet.hpp:668
void metricGauge(const std::string &name, int value)
Send gauge metric.
Definition: teonet.hpp:514
void stop()
Stop Teonet event manager.
Definition: teonet.hpp:468
Teonet App parameters.
Definition: teonet.hpp:57
teo_db_data teoDbData
Definition: teonet.hpp:740
void * teo_class
Pointer to Teonet c++ Class (in c++ wrapper)
Definition: ev_mgr.h:310
uint8_t from_len
Remote peer name length.
Definition: net_com.h:113
void makeTeonetVersion(uint8_t *ver, int num_dig=DIG_IN_TEO_VER)
Definition: teonet.hpp:986
static const char * getTeonetVersion()
Get Teonet library version.
Definition: teonet.hpp:404
void sendAnswerToA(teo::teoPacket *rd, uint8_t cmd, void *data, size_t data_len) const
Sent teonet command to peer or l0 client depend of input rd (asynchronously)
Definition: teonet.hpp:236
int sendEchoToL0(const char *addr, int port, const char *cname, size_t cname_length, void *data, size_t data_len) const
Send ECHO command to L0 client.
Definition: teonet.hpp:338
CQue(Teonet *t, bool send_event=false)
Definition: teonet.hpp:591
Definition: teonet.hpp:928
KSNet core received data structure.
Definition: net_com.h:107
int sendToL0(const char *addr, int port, const char *cname, size_t cname_length, uint8_t cmd, void *data, size_t data_len) const
Send data to L0 client.
Definition: teonet.hpp:273
teo::teoPacket * getPacket(void *data) const
Cast data to teo::teoPacket.
Definition: teonet.hpp:476
Teonet * getTeonet() const
Get pointer to teonet class object.
Definition: teonet.hpp:685
const char ** app_argv
Definition: ev_mgr.h:235
iterator operator++()
Definition: teonet.hpp:1102
StringArray()
Definition: teonet.hpp:1031
void setAppType(const char *type)
Set Teonet application type.
Definition: teonet.hpp:156
const char * getPeer() const
Definition: teonet.hpp:807
cqueData * add(cqueCallback cb, T timeout=5.00, void *user_data=NULL)
Definition: teonet.hpp:627
HostInfo(void *data)
Definition: teonet.hpp:993
ksnet_stringArr ksnet_stringArrSplit(const char *string, const char *separators, int with_empty, int max_parts)
Split string by separators into words.
Definition: string_arr.c:137
std::string to_string(const std::string &separator) const
Definition: teonet.hpp:1083
iterator(pointer ptr, int idx)
Definition: teonet.hpp:1100
void metricCounter(const std::string &name, double value)
Send counter metric.
Definition: teonet.hpp:494
#define rd
Definition: teonet.hpp:83
int close(Watcher *wd) const
Definition: teonet.hpp:962
ksnet_arp_data * ksnCoreSendCmdto(ksnCoreClass *kc, char *to, uint8_t cmd, void *data, size_t data_len)
Send command by name to peer.
Definition: net_core.c:389
auto getL0Client() const -> decltype(l0client)
Definition: teonet.hpp:770
void teoBroadcastSend(ksnCoreClass *kc, char *to, uint8_t cmd, void *data, size_t data_len)
Send brodcast command to peers by type.
Definition: net_core.c:358
StringArray(const char *str, const char *separators=",", bool with_empty=true, int max_parts=0)
Definition: teonet.hpp:1037
ksnCQueClass * ksnCQueInit(void *ke, uint8_t send_event)
Initialize ksnCQue module class.
Definition: cque.c:43
LogReader(Teonet &teo)
Definition: teonet.hpp:938
CQue * getCQue()
Definition: teonet.hpp:805
CMD_D_GET_LIST_RANGE extended Data structure.
Definition: teodb_com.h:57
virtual ~CQue()
Definition: teonet.hpp:596
teoL0Client(const std::string &name, const std::string &addr, int port)
Definition: teonet.hpp:67
ksnet_stringArr ksnet_stringArrAdd(ksnet_stringArr *arr, const char *str)
Add c string to string array.
Definition: string_arr.c:33
teo_db_data * prepare_request_data(const void *key, size_t key_len, const void *data, size_t data_len, uint32_t id, size_t *tdd_len)
Prepare teonet db data.
Definition: teodb_com.c:25
int ksnet_stringArrMoveTo(ksnet_stringArr arr, unsigned int fromIdx, unsigned toIdx)
Move array item from one position to another.
Definition: string_arr.c:73
Definition: teonet.hpp:1090
void teoMetricGaugef(teoMetricClass *tm, const char *name, double value)
Send gauge teonet metrics.
Definition: metric.c:156
const char * operator[](int i) const
Definition: teonet.hpp:1069
ksnetEvMgrEvents
KSNet event manager events.
Definition: ev_mgr.h:49
uint32_t teoLogReaderFlag
Definition: log_reader.h:17
ksnetEvMgrClass * ksnetEvMgrInitPort(int argc, char **argv, void(*event_cb)(ksnetEvMgrClass *ke, ksnetEvMgrEvents event, void *data, size_t data_len, void *user_data), int options, int port, void *user_data)
Initialize KSNet Event Manager and network and set new default port.
Definition: ev_mgr.c:104
const char * addr
Definition: teonet.hpp:61
struct teo::HostInfo::@3 type
int sendEchoToL0A(const char *addr, int port, const char *cname, size_t cname_length, void *data, size_t data_len) const
Definition: teonet.hpp:344
iterator begin()
Definition: teonet.hpp:1116
void ksnCQueDestroy(ksnCQueClass *kq)
Destroy ksnCQue module class.
Definition: cque.c:88
void metricGauge(const std::string &name, double value)
Send gauge metric.
Definition: teonet.hpp:524
ksnCommandClass * kco
Command class object.
Definition: net_core.h:48
bool operator!=(const iterator &rhs)
Definition: teonet.hpp:1112
void sendToL0A(const char *addr, int port, const char *cname, size_t cname_length, uint8_t cmd, void *data, size_t data_len) const
Send data to L0 client.
Definition: teonet.hpp:314
char ** ksnet_stringArr
Definition: string_arr.h:11
void * getValue() const
Definition: teonet.hpp:775
int ksnCommandSendCmdEcho(ksnCommandClass *kco, char *to, void *data, size_t data_len)
Send ECHO command to peer.
Definition: net_com.c:283
int ksnLNullSendEchoToL0A(void *ke, char *addr, int port, char *cname, size_t cname_length, void *data, size_t data_len)
Definition: l0-server.c:523
char * getValueStr() const
Definition: teonet.hpp:776
uint8_t name_len
Definition: teonet.hpp:60
KSNet event manager functions data.
Definition: ev_mgr.h:245
iterator operator++(int junk)
Definition: teonet.hpp:1106
teoLogReaderFlag Flags
Definition: teonet.hpp:932
char * getKeyStr() const
Definition: teonet.hpp:773
CQue::cquePtr getCQueP()
CQue class factory(maker)
Definition: teonet.hpp:715
std::vector< std::string > v
Definition: teonet.hpp:976
int ksnetEvMgrRun(ksnetEvMgrClass *ke)
Start KSNet Event Manager and network communication.
Definition: ev_mgr.c:301
void sendToA(const char *to, uint8_t cmd, void *data, size_t data_len) const
Send command by name to peer(asynchronously)
Definition: teonet.hpp:200
std::string name
Definition: teonet.hpp:974
Teonet(int argc, char **argv, teoEventsCb event_cb=NULL, int options=READ_ALL, int port=0, void *user_data=NULL)
Teonet constructor.
Definition: teonet.hpp:131
int sendToL0(teoL0Client *l0cli, uint8_t cmd, void *data, size_t data_len) const
Send data to L0 client with the teoL0Client structure.
Definition: teonet.hpp:297
int teoLogReaderClose(teoLogReaderWatcher *wd)
Definition: log_reader.c:155
ksnetEvMgrEvents teoEvents
Definition: teonet.hpp:54
virtual ~Teonet()
Teonet simple destructor.
Definition: teonet.hpp:148
const char * getParam(int parm_number) const
Get additional application command line parameter defined in teoAppParam.
Definition: teonet.hpp:439
char * ksnet_stringArrCombine(ksnet_stringArr arr, const char *separator)
Combine string array to string.
Definition: string_arr.c:240
void * find(const std::string &find, const Callback compare, size_t *key_length=NULL)
Definition: teonet.hpp:646
TeoDB(Teonet *t, const std::string &peer, teoDbData **tdd)
Definition: teonet.hpp:787
void teoMetricCounterf(teoMetricClass *tm, const char *name, double value)
Send counter teonet metric.
Definition: metric.c:120
void * ksscr
Pointer to teoSScrClass.
Definition: net_com.h:100
Definition: opt.h:20
teoLogReaderClass * lr
Log reader class.
Definition: ev_mgr.h:266
ksnCQue data structure
Definition: cque.h:39
int ksnCQueRemove(ksnCQueClass *kq, uint32_t id)
Remove callback from queue.
Definition: cque.c:147
TeoDB(const TeoDB &obj)
Definition: teonet.hpp:790
char ** app_argv
Array of application parameters.
Definition: conf.h:91
ksnCoreClass * kc
KSNet core class.
Definition: ev_mgr.h:249
void teoSScrSendA(void *ke, uint16_t event, void *data, size_t data_length, uint8_t cmd)
Definition: async_calls.c:396
void free(void *)
ksnCorePacketData teoPacket
Teonet Events.
Definition: teonet.hpp:55
bool move(unsigned int fromIdx, unsigned int toIdx)
Definition: teonet.hpp:1086
ksnet_stringArr ksnet_stringArrFree(ksnet_stringArr *arr)
Free string array.
Definition: string_arr.c:110
double getTime() const
Get KSNet event manager time.
Definition: teonet.hpp:450
int port
Definition: teonet.hpp:62
ksnet_arp_data * send(uint8_t cmd, const void *key, size_t key_len, const void *data=NULL, size_t data_len=0)
Definition: teonet.hpp:823
void sendCmdAnswerToBinaryA(void *ke, void *rdp, uint8_t cmd, void *data, size_t data_length)
Definition: async_calls.c:422
bool checkPeer(const char *peer_name)
Definition: teonet.hpp:809
void teoSetAppType(ksnetEvMgrClass *ke, char *type)
Set Teonet application type.
Definition: ev_mgr.c:192
int l0_f
L0 command flag (from set to l0 client name)
Definition: net_com.h:125
uint32_t id
Request ID.
Definition: teodb_com.h:49
static teoL0Client * setl0Cli(teo::teoPacket *rd)
Definition: teonet.hpp:762
virtual void eventCb(teo::teoEvents event, void *data, size_t data_len, void *user_data)
Virtual Teonet event callback.
Definition: teonet.hpp:536
void setCustomTimer(double time_interval=2.00)
Set custom timer interval.
Definition: teonet.hpp:388
bool process(teoEvents event, void *data)
Definition: teonet.hpp:877
int exec(uint32_t id)
Execute callback queue record.
Definition: teonet.hpp:659
void BroadcastSend(const char *to, uint8_t cmd, void *data, size_t data_len) const
Send command by name to peer.
Definition: teonet.hpp:182
void sendAnswerTo(teo::teoPacket *rd, const char *name, const std::string &data) const
Definition: teonet.hpp:222
StringArray & add(const char *str)
Definition: teonet.hpp:1072
LogReader(Teonet *teo)
Definition: teonet.hpp:939
StringArray & operator=(const StringArray &ar)
Definition: teonet.hpp:1059
void sendToSscr(uint16_t ev, const std::string &data, uint8_t cmd=0) const
Definition: teonet.hpp:376
ksnCQueData cqueData
Definition: teonet.hpp:575
const char * teoGetLibteonetVersion()
Get teonet library version.
Definition: ev_mgr.c:249
std::unique_ptr< teoDbData > prepareRequest(const void *key, size_t key_len, const void *data, size_t data_len, uint32_t id, size_t *tdd_len)
Definition: teonet.hpp:811
#4 Debug message (normal)
Definition: src/utils/utils.h:37
char * ksnet_formatMessage(const char *fmt,...)
Create formated message in new null terminated string.
Definition: utils.c:231
Definition: log_reader.h:19
int ksnLNullSendToL0(void *ke, char *addr, int port, char *cname, size_t cname_length, uint8_t cmd, void *data, size_t data_len)
Send data to L0 client.
Definition: l0-server.c:466
#135 List length response: { listLength, key, ID }
Definition: teodb_com.h:28
static teoL0Client * setl0Cli(const char *name, uint8_t name_len, const char *addr, int port)
Definition: teonet.hpp:758
std::unique_ptr< CQue > cquePtr
Definition: teonet.hpp:584
int setUserData(uint32_t id, void *data)
Set callback queue data, update data set in ksnCQueAdd.
Definition: teonet.hpp:695
virtual ~teoL0Client()
Definition: teonet.hpp:70
auto getId() const -> decltype((*tdd) ->id)
Definition: teonet.hpp:766
void teoSScrSubscribe(teoSScrClass *sscr, char *peer_name, uint16_t ev)
Send command to subscribe this host to event at remote peer.
Definition: subscribe.c:437
void * getCQueData(int id) const
Definition: teonet.hpp:670
cqueData * add(T timeout=5.00, void *user_data=NULL)
Definition: teonet.hpp:632
teoLogReaderWatcher * teoLogReaderOpenCbPP(teoLogReaderClass *lr, const char *name, const char *file_name, teoLogReaderFlag flags, teoLogReaderCallback cb, void *user_data)
Definition: log_reader.c:116
const char ** app_descr
Definition: ev_mgr.h:236
void * getKey() const
Definition: teonet.hpp:772
const char * name
Teonet L0 Client address.
Definition: teonet.hpp:59
const std::string getPath()
Get path to teonet data folder.
Definition: teonet.hpp:457
int ksnet_stringArrLength(ksnet_stringArr arr)
Get length of string array.
Definition: string_arr.c:52
struct teoLogReaderWatcher teoLogReaderWatcher
Definition: log_reader.h:34
void metricCounter(const std::string &name, int value)
Send counter metric.
Definition: teonet.hpp:484
int ksnCQueExec(ksnCQueClass *kq, uint32_t id)
Execute callback queue record.
Definition: cque.c:106
void * find(void *find, const Callback compare, size_t *key_length=NULL)
Definition: teonet.hpp:641
Definition: teonet.hpp:742
void sendToSscr(uint16_t ev, void *data, size_t data_length, uint8_t cmd=0) const
Definition: teonet.hpp:373
void ksnetEvMgrSetCustomTimer(ksnetEvMgrClass *ke, double time_interval)
Set custom timer interval.
Definition: ev_mgr.c:559
struct teo::Teonet::TeoDB::teoDbCQueData teoDbCQueData
ksnCQueCallback cqueCallback
Teonet CQue data structure.
Definition: teonet.hpp:576
Teonet host info processing class.
Definition: teonet.hpp:972
void teoSScrSubscribeA(teoSScrClass *sscr, char *peer, uint16_t ev)
Send command to subscribe this host to event at remote peer.
Definition: async_calls.c:461
void * ksnCQueFindData(ksnCQueClass *kq, void *find, ksnCQueCompare compare, size_t *key_length)
Find data in CQue.
Definition: cque.c:301
void * user_data
Definition: teonet.hpp:748
std::string formatMessage(const char *format, const Arguments &...args)
Definition: teonet.hpp:568
auto getCbType() const -> decltype(cb_type)
Definition: teonet.hpp:768
int sendToL0(const char *addr, int port, const std::string &cname, uint8_t cmd, void *data, size_t data_len) const
Definition: teonet.hpp:277
Definition: teonet.hpp:941
void teoMetricGauge(teoMetricClass *tm, const char *name, int value)
Send gauge teonet metrics.
Definition: metric.c:144
StringArray(const std::string &str, const std::string &separators=",", bool with_empty=true, int max_parts=0)
Definition: teonet.hpp:1044
Teonet CQue callback function.
Definition: teonet.hpp:581
virtual ~teoDbCQueData()
Definition: teonet.hpp:754
File: subscribe.h Author: Kirill Scherba kirill@scherba.ru
Definition: subscribe.h:19
int port
Remote peer port.
Definition: net_com.h:110
std::string to_string(const char *separator=NULL) const
Definition: teonet.hpp:1080
struct teo::teoL0Client teoL0Client
Teonet App parameters.
char * addr
Remote peer IP address.
Definition: net_com.h:109
#define sendCmdAnswerTo(ke, rd, name, out_data, out_data_len)
Sent teonet command to peer or l0 client.
Definition: net_core.h:77