msf-client code will be in d2d-server from this point.
Signed-off-by: Hongkuk, Son <hongkuk.son@samsung.com>
Change-Id: I95749e25e1ddac96ce62cceb051aac6baedf1f5a
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
)
-
-ADD_SUBDIRECTORY(msf_tizen_client)
+++ /dev/null
-Sanggune Lee <sanggun7.lee@samsung.com>
-
+++ /dev/null
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(msf-api)
-INCLUDE(GNUInstallDirs)
-
-# Targets
-SET(target_lib "msf-api")
-
-# Source Lists
-FILE(GLOB_RECURSE SRCS src/*.cpp)
-MESSAGE("Sources: ${SRCS}")
-
-# Dependencies
-SET(DEPS "glib-2.0 gio-2.0 json-glib-1.0 dlog openssl libwebsockets libcurl")
-
-SET(MAJORVER "0.1")
-SET(FULLVER "0.1")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default -std=c++0x")
-
-INCLUDE(FindPkgConfig)
-INCLUDE_DIRECTORIES(
-${CMAKE_CURRENT_SOURCE_DIR}/include
-)
-ADD_DEFINITIONS(-g -O2 -Wall -fPIC -Wl,--as-needed)
-
-# Building Library
-pkg_check_modules(lib_pkg REQUIRED ${DEPS})
-
-FOREACH(flag ${lib_pkg_CFLAGS})
-SET(LIB_EXTRA_CFLAGS "${LIB_EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-ADD_LIBRARY(${target_lib} SHARED ${SRCS})
-TARGET_LINK_LIBRARIES(${target_lib} ${lib_pkg_LDFLAGS} nsd-dns-sd)
-SET_TARGET_PROPERTIES(${target_lib} PROPERTIES COMPILE_FLAGS ${LIB_EXTRA_CFLAGS})
-SET_TARGET_PROPERTIES(${target_lib} PROPERTIES COMPILE_DEFINITIONS "LOG_TAG=\"MSF\"")
-SET_TARGET_PROPERTIES(${target_lib} PROPERTIES SOVERSION ${MAJORVER})
-SET_TARGET_PROPERTIES(${target_lib} PROPERTIES VERSION ${FULLVER})
-
-SET(VERSION ${FULLVER})
-SET(PREFIX ${CMAKE_INSTALL_PREFIX})
-SET(PC_NAME ${PROJECT_NAME})
-SET(PC_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
-SET(PC_DESCRIPTION "Tizen MSF Shared Library")
-SET(PC_REQUIRED ${DEPS})
-SET(PC_LDFLAGS -l${target_lib})
-SET(PC_CFLAGS -I\${includedir}/msf-api)
-
-# Installing Library
-INSTALL(TARGETS ${target_lib} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries})
-INSTALL(
-DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/msf-api
-FILES_MATCHING PATTERN "*.h"
-)
-
-
-
-CONFIGURE_FILE(
-${PROJECT_NAME}.pc.in
-${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc
-@ONLY
-)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
-
-ADD_SUBDIRECTORY(test)
+++ /dev/null
-Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
-Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+++ /dev/null
-#ifndef _MSF_APPLICATION_H_
-#define _MSF_APPLICATION_H_
-
-#include"Result.h"
-#include"ApplicationInfo.h"
-#include"Channel.h"
-#include"Service.h"
-
-
-class Application:public Channel
-{
-public:
- bool webapp;
- static string ROUTE_APPLICATION;
- static string ROUTE_WEBAPPLICATION;
- static string curl_data;
- bool install_result = false;
- Result_Base *install_result_listener = NULL;
-
- string createdata_data;
- string curl_install_data;
- typedef std::map<std::string, std::string> map_null;
- map<string, string> *startArgs;
- int curl_install(string uri);
- int curl_application_calling(string uri);
- map<string, string> getparams();
- void invokeMethod(string method, map<string, string> params, Result_Base *);
- void invokeMethod(string method, map<string, string> params, string messageID, Result_Base *);
- void realDisconnect(Result_Base *result);
-
-public:
- Application();
- Application(Service *service, string uri, string id);
- Application(Service *service, string uri, string id, map<string, string> startArgs);
- virtual ~Application();
- Result_Base *result ;
- bool isConnected();
- bool isWebapp();
- void createdata_process(string data);
- void getinfo(Result_Base *result);
- void connect();
- void connect(Result_Base *r);
- void connect(map<string, string> attributes, Result_Base *r);
- void disconnect();
- void disconnect(Result_Base *r);
- void disconnect(bool stopOnDisconnect);
- void install();
- static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream);
- static size_t createdata(char *buf, size_t size, size_t nmemb, void *up);
- static Application create(Service *service, string uri);
- static Application create(Service *service, string uri, string id, map<string, string>);
- void start(Result_Base *result);
- void stop(Result_Base *result);
- void json_parse(const char *in);
- static void foreach_json_object(JsonObject *object, const gchar *key, JsonNode *node, gpointer user_data);
- void setonInstallListener(Result_Base *listener);
- void unsetonInstallListener();
-};
-
-#endif
+++ /dev/null
-#ifndef _MSF_APPLICATION_INFO_H_
-#define _MSF_APPLICATION_INFO_H_
-
-#include <stdio.h>
-#include<iostream>
-#include <string.h>
-#include <json-glib/json-glib.h>
-#include <json-glib/json-parser.h>
-
-using namespace std;
-
-class ApplicationInfo
-{
- string name;
- string id;
- string msf_version;
- bool running;
- static string PROPERTY_ID;
- static string PROPERTY_STATE;
- static string PROPERTY_NAME;
- static string PROPERTY_VERSION;
-
-
-public:
- string getID();
- string getName();
- string getVersion();
- bool isRunning();
- ApplicationInfo create(string data);
- ApplicationInfo();
- ApplicationInfo(string iD, bool state, string Name, string Version);
- void json_parse(const char *in);
- static void foreach_json_object(JsonObject *object, const gchar *key, JsonNode *node, gpointer user_data);
-};
-
-#endif
+++ /dev/null
-#ifndef _CHANNEL_H_
-#define _CHANNEL_H_
-
-#include <libwebsockets.h>
-#include <list>
-#include <json-glib/json-glib.h>
-#include <json-glib/json-parser.h>
-#include "Result.h"
-#include "Error.h"
-#include "Message.h"
-#include "Client.h"
-
-using namespace std;
-
-class Service;
-class Clients;
-class Channel;
-
-class ChannelConnectionHandler {
-public:
- ChannelConnectionHandler();
- static string PING;
- static string PONG;
- static Channel *channel_ptr;
- void run();
- void setPingTimeout(long);
- void resetLastPingReceived();
- void calculateAverageRT();
- void stopPing();
- void startPing(Channel *);
- static void *Pinging(void *);
- static void ping_again(void *);
- static pthread_t ping_thread;
-
-private:
- long pingTimeout;
- long lastPingReceived;
- int numPings;
- long startTime;
- long pingSent;
- double average;
- long longestRT;
- bool running;
-};
-
-enum Result_base_Type {
- Result_Client = 1,
- Result_bool = 2,
- Result_ApplicationInfo = 3
-};
-
-typedef void (*_message_receive_cb)(Message msg);
-
-class OnConnectListener {
-public:
- virtual void onConnect(Client Client) {}
-};
-
-class OnDisconnectListener {
-public:
- virtual void onDisconnect(Client Client) {}
-};
-
-class OnClientConnectListener {
-public:
- virtual void onClientConnect(Client Client) {}
-};
-
-class OnClientDisconnectListener {
-public:
- virtual void onClientDisconnect(Client Client) {}
-};
-
-class OnReadyListener {
-public:
- virtual void onReady() {}
-};
-
-class OnMessageListener {
-public:
- virtual void onMessage(Message msg) {}
-};
-
-class OnErrorListener {
-public:
- virtual void onError(/*Error error*/) {}
-};
-
-class Channel {
-public:
- Channel();
- Channel(Service *, string);
- ~Channel();
- static Channel *create(Service *service, string uri);
- ChannelConnectionHandler *connectionHandler;
- Clients *getclients();
- Client getclient(string id);
- void setConnectionTimeout(long timeout);
- bool isConnected();
- bool isWebSocketOpen();
- bool connect();
- void disconnect();
- void set_connect_result(Result_Base *);
- void unset_connect_result();
- void set_disconnect_result(Result_Base *);
- void unset_disconnect_result();
- string getChannelUri(map<string, string> *);
- void addOnMessageListener(string, OnMessageListener *);
- void addOnAllMessageListener(OnMessageListener *);
- void removeAllMessageListener();
- void removeOnMessageListeners(string);
- void removeOnMessageListener(string, OnMessageListener *);
- void removeOnMessageListeners();
- void removeAllListeners();
- void register_message_receive_cb(_message_receive_cb cb);
- void setonConnectListener(OnConnectListener *);
- void unsetonConnectListener();
- void setonDisconnectListener(OnDisconnectListener *);
- void unsetonDisconnectListener();
- void setonClientConnectListener(OnClientConnectListener *);
- void unsetonClientConnectListener();
- void setonClientDisconnectListener(OnClientDisconnectListener *);
- void unsetonClientDisconnectListener();
- void setonReadyListener(OnReadyListener *);
- void unsetonReadyListener();
- void setmessageListeners(list<OnMessageListener>);
- void unsetmessageListeners();
- void setonErrorListener(OnErrorListener *);
- void unsetonErrorListener();
- void publish(string event, const char *data);
- void publish(string event, const char *data, unsigned char payload[],
- int payload_size);
- void publish(string event, const char *data, const char *target);
- void publish(string event, const char *data, const char *target,
- unsigned char payload[], int payload_size);
- void publish(string event, const char *data, Client client);
- void publish(string event, const char *data, Client client,
- unsigned char payload[], int payload_size);
- void publish(string event, const char *data, list<Client> clients);
- void publish(string event, const char *data, list<Client> clients,
- unsigned char payload[], int payload_size);
- void publishMessage(string event, const char *data, const char *to,
- unsigned char payload[], int payload_size);
- void publishMessage(string method, string event, const char *data,
- const char *to, unsigned char payload[],
- int payload_size);
- // unsigned char *createBinaryMessage(string json, unsigned char payload[],
- // int payload_size);
- static void init_json_key_map();
- static void foreach_json_object(JsonObject *object, const gchar *name,
- JsonNode *node, gpointer user_data);
- static void foreach_json_array(JsonArray *object, guint index,
- JsonNode *node, gpointer user_data);
-
- void set_isWrite(bool flag);
- static int callback_lws_mirror(struct lws *wsi,
- enum lws_callback_reasons reason, void *user,
- void *in, size_t len);
- static void *pt_startConnect(void *arg);
-
- Clients *clients; //=new Clients(this );
-
-protected:
- void start_app(char *data, int, string);
- bool connect(Result_Base *result1);
- bool connect(map<string, string>, Result_Base *result1);
- void disconnect(Result_Base *result1);
- void registerCallback(string, void *, int);
- void handleError(string, Error);
- string getipaddressfromUri(string uri);
- string getapifromUri(string uri);
- string getUID();
-
- string ChannelID;
- bool connected;
- bool waitForOnReady;
- Service *service;
- string m_uri;
- int errstatus;
- int errcode;
- string errMsg;
- OnErrorListener *onErrorListener = NULL;
- OnConnectListener *onConnectListener = NULL;
- OnDisconnectListener *onDisconnectListener = NULL;
- OnClientConnectListener *onClientConnectListener = NULL;
- OnClientDisconnectListener *onClientDisconnectListener = NULL;
- OnReadyListener *onReadyListener = NULL;
- map<string, list<OnMessageListener *> > messageListeners;
- Result_Base *connect_cb = NULL;
- Result_Base *disconnect_cb = NULL;
- static map<Channel *, int> channel_alive_map;
-
-private:
- void emit(string event, const char *msg, string from, unsigned char *payld,
- int payld_size);
- void release_callback(string uid);
- pair<void *, int> getcallback(string uid);
- void handleSocketClosed();
- void handleSocketClosedAndNotify();
- void handleConnect(string);
- void handleBinaryMessage(unsigned char payload[]);
- void json_parse(const char *in);
- void handleConnectMessage(string UID);
- void handleMessage(string UID);
- void handleMessage(string UID, unsigned char payload[]);
- void handleApplicationMessage(string);
- void doApplicationCallback(Result_Base *);
- void handleClientConnectMessage();
- void handleClientDisconnectMessage();
- void handleErrorMessage(string);
- void handleReadyMessage();
- void handleDisconnectMessage();
- void handleClientMessage(const char *msg, unsigned char payload[]);
- void create_websocket(void *att);
- unsigned char *prepareMessageMap(string, string, const char *data,
- const char *to, long *,
- unsigned char payload[], int payload_size);
-
- static string ROUTE;
- static string ERROR_EVENT;
- static string CONNECT_EVENT;
- static string CLIENT_CONNECT_EVENT;
- static string CLIENT_DISCONNECT_EVENT;
- static string READY_EVENT;
- unsigned char
- buf[LWS_SEND_BUFFER_PRE_PADDING + 4096 + LWS_SEND_BUFFER_POST_PADDING];
- static pthread_t connect_thread;
- int mirror_lifetime;
- int force_exit;
- char *messagedata;
- bool isWrite;
- bool binary_message;
- bool disconnecting;
- long buflen;
- unsigned char cl_payload[1000];
- int cl_payload_size;
- int was_closed;
- Client client;
- long long clientconnectTime;
- bool clientisHost;
- string clientid;
- map<string, string> clientattributes;
- JsonObject *resultobj;
- bool errobj;
- string data;
- string method;
- string eventType;
- string from;
- bool resultresp;
- string UID;
- struct lws *wsi_mirror;
- struct lws_context *Context;
- list<Client> clientList;
- Client me;
- string msg_subject;
- _message_receive_cb message_receive_cb = NULL;
- OnMessageListener *everyMessageListener = NULL;
- int msg_id;
- bool isLaunched;
- map<string, pair<void *, int> > callbacks;
- map<void *, int> onReadyCallbacks;
- static map<string, int> json_keys;
-};
-
-#endif
+++ /dev/null
-#ifndef _CLIENT_H_
-#define _CLIENT_H_
-
-#include <stdio.h>
-#include<iostream>
-#include <string.h>
-#include<map>
-//#include"Channel.h"
-
-using namespace std;
-
-class Channel;
-
-class Client
-{
- static string ID_KEY;
- static string IS_HOST_KEY;
- static string CONNECT_TIME_KEY;
- static string ATTRIBUTES_KEY;
-
- string id;
- bool host;
- long long connectTime;
- map<string, string> attributes;
- Channel *m_channel;
-
-public:
- Client();
- void create(Client &client);
- void create(Channel *channel, string, long long, /*map<string, string> data,*/bool, map<string, string>);
- bool isHost();
- const char *getId();
- long long getConnectTime();
- map<string, string> getAttributesKey();
- Channel *getChannel();
-};
-
-#endif
+++ /dev/null
-#ifndef _CLIENTS_H_
-#define _CLIENTS_H_
-
-#include"Client.h"
-#include"Channel.h"
-#include<vector>
-
-using namespace std;
-
-class Channel;
-class Client;
-
-class Clients
-{
- map<string, Client> clients;
- string myClientId;
- Client *host;
- Client varme;
- Channel *m_channel;
-
-public:
- void setMyClientId(string clientId);
- void reset();
- void add(list <Client> clientList);
- void add(Client client);
- void remove(Client client);
- int size();
- Clients();
- Clients(Channel *channel);
- Client get(string clientId);
- Client *getHost() ;//need better way to find host
- Client me(void);
- bool isMe(Client client);
- list<Client> lists();
- Channel *getChannel();
-};
-
-#endif
+++ /dev/null
-#ifndef __DEF_MSF_DBG_H_
-#define __DEF_MSF_DBG_H_
-
-#ifndef LINUX
-#include <dlog.h>
-#undef LOG_TAG
-#define LOG_TAG "MSF_API"
-#define MSF_DBG(format, args...) SLOGD(format, ##args)
-#define MSF_ERR(format, args...) SLOGE(format, ##args)
-#endif
-
-#ifdef LINUX
-#define MSF_DBG printf
-#define MSF_ERR printf
-#endif
-
-#endif
-
+++ /dev/null
-#ifndef DEVICE_H
-#define DEVICE_H
-
-#include <stdio.h>
-#include <iostream>
-#include <string.h>
-#include <json-glib/json-glib.h>
-#include <json-glib/json-parser.h>
-
-using namespace std;
-
-class Device
-{
- static string DUID_KEY;
- static string MODEL_KEY;
- static string MODELNAME_KEY;
- static string DESCRIPTION_KEY;
- static string NETWORK_TYPE_KEY;
- static string SSID_KEY;
- static string IP_KEY;
- static string FIRMWARE_VERSION_KEY ;
- static string NAME_KEY ;
- static string ID_KEY ;
- static string UDN_KEY ;
- static string RESOLUTION_KEY;
- static string COUNTRY_CODE_KEY;
- static string TYPE;
- static string MSF_VERSION;
- static string SMARTHUB_AGREEMENT;
- static string WIFIMAC;
- static string DEVELOPER_MODE;
- static string DEVELOPER_IP;
- static string OS;
-
- string duid;
- string model;
- string description;
- string networkType;
- string ssid;
- string ip;
- string firmwareVersion;
- string name;
- string id;
- string udn;
- string resolution;
- string countryCode;
- string type;
- string msf_version;
- string smarthub_agreement;
- string wifimac;
- string developer_mode;
- string deveoper_ip;
- string os;
-
-public:
- string getduid();
- string getmodel();
- string getdescription();
- string getnetworkType();
- string getssid();
- string getip();
- string getfirmwareVersion();
- string getname();
- string getudn();
- string getresolution();
- string getcountryCode();
- string getid();
-
- Device();
- Device(JsonNode *node);
- static Device create(JsonNode *node);
- void json_parse(JsonNode *node);
- static void foreach_json_object(JsonObject *object, const gchar *name, JsonNode *node, gpointer user_data);
-};
-
-#endif
+++ /dev/null
-#ifndef _MSF_ERROR_H
-#define _MSF_ERROR_H
-
-#include <stdio.h>
-#include<iostream>
-#include<string>
-
-using namespace std;
-
-class Error
-{
-private:
- long code;
- string name;
- string message;
-
-public:
- Error();
- Error(long code, string name, string message);
- static Error create(string message);
- static Error create(long code, string name , string message);
- const char *get_error_message();
- //write other create funcs
-};
-
-#endif
+++ /dev/null
-#ifndef MSFDSEARCHPROVIDER_H
-#define MSFDSEARCHPROVIDER_H
-
-#include <map>
-#include <json-glib/json-glib.h>
-#include <json-glib/json-parser.h>
-#include"SearchProvider.h"
-
-using namespace std;
-
-class Search;
-
-class MSFDSearchProvider: public SearchProvider
-{
- bool receive;
- string state;
- string id;
- long ttl;
- string url;
-
-public:
-
- static string KEY_TYPE_STATE;
- static string KEY_TTL;
- static string KEY_SID;
- static string KEY_DATA;
- static string KEY_VERSION_1;
- static string KEY_VERSION_2;
- static string KEY_URI;
- static string TYPE_DISCOVER;
- static string STATE_UP;
- static string STATE_DOWN;
- static string STATE_ALIVE;
- static int SERVICE_CHECK_TIMEOUT;
- static int flag;
- int fd;
- map<string, long> aliveMap;
- MSFDSearchProvider();
- MSFDSearchProvider(Search *);
- void start() ;
- bool stop();
- void createMSFD();
- void processReceivedMsg(char *, int);
- static SearchProvider create();
- static SearchProvider create(Search *);
- void json_parse(const char *in);
- void reapServices();
- void updateAlive(string id , long ttl);
- static void foreach_json_object(JsonObject *object, const gchar *key, JsonNode *node, gpointer user_data);
-};
-
-#endif //MSFDSEARCHPROVIDER_H
+++ /dev/null
-#ifndef _MESSAGE_H_
-#define _MESSAGE_H_
-
-#include "Client.h"
-#include <stdio.h>
-#include <iostream>
-#include <string>
-#include <vector>
-
-
-using namespace std;
-
-class Message
-{
-public:
- Channel *m_channel;
- string m_event;
- string m_data;
- string m_from;
-
- unsigned char *m_payload;
- int m_payload_size;
- //std::vector<unsigned char> m_payload;
-
-public:
- static string TARGET_BROADCAST;
- static string TARGET_ALL;
- static string TARGET_HOST;
-
- static string METHOD_APPLICATION_GET;
- static string METHOD_APPLICATION_START;
- static string METHOD_APPLICATION_STOP;
- static string METHOD_APPLICATION_INSTALL;
- static string METHOD_WEB_APPLICATION_GET;
- static string METHOD_WEB_APPLICATION_START;
- static string METHOD_WEB_APPLICATION_STOP;
- static string METHOD_EMIT;
-
- static string PROPERTY_MESSAGE;
- static string PROPERTY_METHOD;
- static string PROPERTY_MESSAGE_ID;
- static string PROPERTY_PARAMS;
- static string PROPERTY_ID;
- static string PROPERTY_URL;
- static string PROPERTY_ARGS;
- static string PROPERTY_EVENT;
- static string PROPERTY_DATA;
- static string PROPERTY_TO;
- static string PROPERTY_FROM;
- static string PROPERTY_CLIENTS;
- static string PROPERTY_RESULT;
- static string PROPERTY_ERROR;
-
- Message(Channel *ch, string event, string data, string from, unsigned char *payload, int payload_size);
- Message();
- virtual ~Message();
- Message(const Message&);
-};
-
-#endif
+++ /dev/null
-#ifndef _MSF_RESULT_H_
-#define _MSF_RESULT_H_
-
-#include <iostream>
-
-using namespace std;
-
-class Service;
-class ApplicationInfo;
-class Client;
-class Device;
-class Error;
-
-//template <class T>
-
-typedef enum {
- RESULT_BASE_APP_INFO,
- RESULT_BASE_CLIENT,
- RESULT_BASE_DEVICE,
- RESULT_BASE_BOOL,
- RESULT_BASE_SERVICE,
- RESULT_BASE_ERROR
-} result_base_e;
-
-typedef void(*_appinfo_result_cb)(ApplicationInfo appinfo, void *user_data);
-typedef void(*_client_result_cb)(Client client, void *user_data);
-typedef void(*_device_result_cb)(Device dev, void *user_data);
-typedef void(*_bool_result_cb)(bool result, void *user_data);
-typedef void(*_service_result_cb)(Service service, void *user_data);
-typedef void(*_error_result_cb)(Error err, void *user_data);
-
-class Result_Base
-{
-public:
-
- _appinfo_result_cb appinfo_result_cb = NULL;
- _client_result_cb client_result_cb = NULL;
- _device_result_cb device_result_cb = NULL;
- _bool_result_cb bool_result_cb = NULL;
- _service_result_cb service_result_cb = NULL;
- _error_result_cb error_result_cb = NULL;
- void *user_data;
- Result_Base();
- Result_Base(void*, void*, result_base_e);
- virtual ~Result_Base();
-
- virtual void onSuccess(ApplicationInfo argu);
- virtual void onSuccess(Client argu);
- virtual void onSuccess(Device argu);
- virtual void onSuccess(bool argu);
- virtual void onSuccess(Service argu);
- virtual void onError(Error);
-};
-
-#endif
-
+++ /dev/null
-#ifndef _MSF_SEARCH_H
-#define _MSF_SEARCH_H
-
-//#include"Service.h"
-#include <list>
-#include"SearchProvider.h"
-#include <list>
-#include <pthread.h>
-#include <string>
-#include"mDNSSearchProvider.h"
-//#include"MSFDSearchProvider.h"
-
-#define NUM_OF_THREADS 2
-#define MDNS_THREAD_NUMBER 0
-#define MSFD_THREAD_NUMBER 1
-
-using namespace std;
-
-class Service;
-class MSFDSearchProvider;
-class mDNSSearchProvider;
-
-class OnStartListener
-{
-public:
- virtual void onStart() { }
-};
-
-class OnStopListener
-{
-public:
- virtual void onStop() { }
-};
-
-class OnServiceFoundListener
-{
-public:
- virtual void onFound(Service) = 0;
-};
-
-class OnServiceLostListener
-{
-public:
- virtual void onLost(Service) = 0;
-};
-
-class SearchListener:public OnStartListener, public OnStopListener, public OnServiceFoundListener, public OnServiceLostListener
-{
-public:
- virtual ~SearchListener(){}
- virtual void onStart();
- virtual void onStop();
- virtual void onFound(Service);
- virtual void onLost(Service);
-};
-
-class Search:public SearchListener
-{
-private :
- static int SERVICE_CHECK_TIMEOUT;
- static Search *instance;
- list<SearchProvider> providers ;
- list<SearchProvider> removedProviders ;
- static list<Service> services;
-
- static int numRunning;
- SearchListener *searchListener;
- static bool clearProviders;
- static bool starting;
- static int search_ref_count;
- static bool stopping;
- bool searching_now;
- static mDNSSearchProvider provider1;
- static MSFDSearchProvider provider2;
- //OnStartListener *onStartListener;
- //OnStopListener *onStopListener;
- //OnServiceFoundListener *onServiceFoundListener;
- //OnServiceLostListener *onServiceLostListener;
-
-public:
- static pthread_t threads[NUM_OF_THREADS];
- static int onStartNotified;
- //static Search* getInstance();
- Search();
- ~Search();
- //bool isSearching();
- bool start();
- bool stop();
-
- static list<Search*> search_list;
- void onStart();
- void onStop();
- void onFound(Service);
- void onLost(Service);
- static void st_onStart();
- static void st_onStop();
- static void st_onFound(Service);
- static void st_onLost(Service);
-
- bool isEqualto(SearchProvider, SearchProvider);
- list<Service> getServices();
- bool remove(list<SearchProvider> *, SearchProvider);
- void addProvider(SearchProvider);
- //bool removeProvider(SearchProvider);
- //void processRemovedProviders();
- //void removeAllProviders();
- void startDiscovery();
- void stopDiscovery();
- static bool addService(Service);
- bool removeService(Service);
- void removeAndNotify(Service);
- void validateService(Service);
- //void setOnStartListener(OnStartListener *);
- //void setOnStopListener(OnStopListener);
- //void setOnServiceFoundListener(OnServiceFoundListener);
- //void setOnServiceLostListener(OnServiceLostListener);
- Service getServiceById(string id);
-
- void setSearchListener(SearchListener*);
- void releaseSearchListener();
- static void *pt_startMDNS(void *);
- static void *pt_startMSFD(void *);
-};
-
-#endif
+++ /dev/null
-#ifndef _MSF_SEARCHPROVIDER_H
-#define _MSF_SEARCHPROVIDER_H
-
-#include<iostream>
-#include<list>
-#include<string>
-//#include "Service.h"
-//#include "Search.h"
-
-using namespace std;
-
-class Service;
-class Search;
-
-class SearchProvider
-{
-private:
- Search *searchListener;
- static list<Service> services;
-
-public:
- SearchProvider();
- SearchProvider(Search *);
- virtual void start() {}
- virtual bool stop() { return true; }
- static list<Service> getServices();
- bool isSearching();
- void setSearchListener(Search *obj);
-
-protected:
- bool searching;
- void setServices(list<Service>);
- void addService(Service service);
- void removeService(Service service);
- void removeServiceAndNotify(Service service);
- void clearServices();
- Service getServiceById(string id);
-};
-
-#endif
+++ /dev/null
-#ifndef _MSF_SERVICE_H
-#define _MSF_SERVICE_H
-
-#include <string>
-#include <map>
-#include <json-glib/json-glib.h>
-#include <json-glib/json-parser.h>
-
-
-using namespace std;
-
-class Application;
-class Search;
-class Result_Base;
-class Channel;
-
-struct position {
- int start;
- int end;
-};
-
-struct ServiceInfo {
- string infoId;
- string infoVersion;
- string infoName;
- string infotype;
- string infoURI;
-};
-
-class Service
-{
- static string ID_PROPERTY;
- static string VERSION_PROPERTY;
- static string NAME_PROPERTY;
- static string TYPE_PROPERTY;
- static string ENDPOINT_PROPERTY;
- string id = "";
- string version = "";
- string name = "";
- string type = "";
- string uri = "";
- static string curl_data;
- typedef std::map<std::string, std::string> map_type;
- static Service local_service;
- void *result_ptr;
-
-public:
- Service();
- Service(string, string, string, string, string);
- static ServiceInfo serviceval;
- static Result_Base *Resulturi;
- Result_Base *Resultdevice;
-
- position findServiceValue(string, char *);
- void getDeviceInfo(Result_Base*);
- void create(char*);
- string getUri();
- string getName();
- string getType();
- string getId();
- string getVersion();
- static Service getLocal(void);
- static void getByURI(string, Result_Base*);
- static void getByURI(string, long, Result_Base *result);
- static void getById(string id, Result_Base *result);
- static int curl_service_calling(string uri, long, void *);
- //static Search *search();
- static size_t createdata(char *buf, size_t size, size_t nmemb, void *up);
- static void createdata_process(string data, void *);
- static int json_parse_service(const char *in, void *);
- static Service create(ServiceInfo);
- static Service create(map<string, string>);
- static void foreach_json_object(JsonObject *object, const gchar *key, JsonNode *node, gpointer user_data);
- Channel *createChannel(string uri);
- Application createApplication(string uri);
- Application createApplication(string uri, string channelId);
- Application createApplication(string uri, string channelId, map<string, string> startArgs) ;
-};
-#endif
+++ /dev/null
-#ifndef _URI_PARSER_H_
-#define _URI_PARSER_H_
-
-#include <vector>
-#include <string>
-
-namespace uri_parser
-{
-
-class URIParse
-{
-public:
-
- URIParse();
-
- URIParse(const std::string& uri);
-
- URIParse(const char *uri);
-
- ~URIParse();
- void clear();
-
- const std::string& getURIScheme() const;
-
- void setURIScheme(const std::string& scheme);
-
- const std::string& getURIHost() const;
-
- bool empty() const;
-
- static void decodeURI(const std::string& str, std::string& decodedStr, long _flags2);
-
- static bool isIPAddressinURI(const std::string& str);
-
-protected:
-
- unsigned short getWellKnownPortforURI() const;
-
- void parseURI(const std::string& uri);
-
- void URIparseAuthority(std::string::const_iterator& it, const std::string::const_iterator& end);
-
- void URIparseHostAndPort(std::string::const_iterator& it, const std::string::const_iterator& end);
-
- void URIparsePath(std::string::const_iterator& it, const std::string::const_iterator& end);
-
- void URIparsePathEtc(std::string::const_iterator& it, const std::string::const_iterator& end);
-
- void URIparseQuery(std::string::const_iterator& it, const std::string::const_iterator& end);
-
- void URIparseFragment(std::string::const_iterator& it, const std::string::const_iterator& end);
-
- static const std::string URIRESERVED_PATH;
- static const std::string URIRESERVED_QUERY;
- static const std::string URIRESERVED_FRAGMENT;
- static const std::string URIILLEGAL;
-
-private:
- template <class S>
- S& toLowerInPlaceURI(S& str){
- typename S::iterator it = str.begin();
- typename S::iterator end = str.end();
- while (it != end) { *it = tolower(*it); ++it; }
- return str;
- }
- std::string _URIscheme;
- std::string _URIuserInfo;
- std::string _URIhost;
- unsigned short _URIport;
- std::string _URIportStr;
- std::string _URIpath;
- std::string _URIquery;
- std::string _URIfragment;
- long _URIflags;
-};
-
-inline const std::string& URIParse::getURIScheme() const
-{
- return _URIscheme;
-}
-
-inline const std::string& URIParse::getURIHost() const
-{
- return _URIhost;
-}
-
-}
-
-#endif //_URI_PARSER_H_
+++ /dev/null
-#ifndef MDNSSEARCHPROVIDER_H
-#define MDNSSEARCHPROVIDER_H
-
-using namespace std;
-
-#include"SearchProvider.h"
-#include <nsd/dns-sd.h>
-
-class mDNSSearchProvider : public SearchProvider
-{
-private:
-
-public:
-
- mDNSSearchProvider();
- ~mDNSSearchProvider();
- void addService(Service service);
- mDNSSearchProvider(Search *sListener);
- void start();
- bool stop();
- static SearchProvider create();
- static SearchProvider create(Search *);
-};
-
-#endif
+++ /dev/null
-#Package Information for pkg-config\r
-\r
-prefix=@PREFIX@\r
-exec_prefix=@PREFIX@\r
-libdir=@PC_LIBDIR@\r
-includedir=@PC_INCLUDE@\r
-\r
-Name: @PC_NAME@\r
-Description: @PC_DESCRIPTION@\r
-Version: @VERSION@\r
-Requires: @PC_REQUIRED@\r
-Libs: -L${libdir} @PC_LDFLAGS@\r
-Cflags: -I${includedir}\r
+++ /dev/null
-#include"Application.h"
-#include<curl/curl.h>
-#include <dlog.h>
-#include "Debug.h"
-#include<cstring>
-#include"URIparser.h"
-#include"Message.h"
-#include"Clients.h"
-
-using namespace std;
-using namespace uri_parser;
-
-string Application::ROUTE_APPLICATION = "applications/";
-string Application::curl_data = "";
-
-class ResultConnectboolCallback : public Result_Base
-{
-public:
- Client client;
- Result_Base** in_connect_cb = NULL;
-
- void onSuccess(bool abc)
- {
- dlog_print(DLOG_INFO, "MSF", "ResultConnectboolCallback success result");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-
- if (in_connect_cb != NULL) {
- if (((*in_connect_cb) != NULL) && (!strncmp(client.getId(), "", 1) == 0)) {
- dlog_print(DLOG_INFO, "MSF", "start success result");
- (*in_connect_cb)->onSuccess(client);
- } else {
- }
- }
-
- delete this;
- }
-
- void onError(Error)
- {
- dlog_print(DLOG_ERROR, "MSF", "start error result");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-
- dlog_print(DLOG_ERROR, "MSF", "start result.");
- //app_pointer->handleSocketClosed();
- delete this;
- }
-};
-
-class connectCallback : public Result_Base
-{
-public:
- ResultConnectboolCallback* start_cb;
- Application* app_pointer = NULL;
- Result_Base** in_connect_cb = NULL;
-
-public:
- void onSuccess(Client abc)
- {
- static Client client12 = abc;
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-
- if (app_pointer != NULL) {
- start_cb = new ResultConnectboolCallback();
- start_cb->in_connect_cb = in_connect_cb;
- start_cb->client = abc;
- app_pointer->start(start_cb);
- }
-
- if (in_connect_cb != NULL) {
- if ((*in_connect_cb) != NULL) {
- (*in_connect_cb)->onSuccess(true);
- }
- }
- delete this;
- }
-
- void onError(Error error)
- {
- // On error
- if (in_connect_cb != NULL) {
- if ((*in_connect_cb) != NULL) {
- (*in_connect_cb)->onError(error);
- }
- }
- delete this;
- }
-};
-
-class DisconnectboolCallback : public Result_Base
-{
-public:
- Application* app_p = NULL;
- Result_Base** in_disconnect_cb = NULL;
-
- // server application stop success
- void onSuccess(bool abc)
- {
- dlog_print(DLOG_INFO, "MSF", "application disconnect(bool, result) 3");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- if (abc) {
- dlog_print(DLOG_INFO, "MSF", "application disconnect(bool, result) 4");
-
- if (in_disconnect_cb != NULL) {
- if ((*in_disconnect_cb) != NULL) {
- app_p->realDisconnect(*in_disconnect_cb);
- //temp->onSuccess(me);
- } else {
- }
- }
- } else {
- dlog_print(DLOG_INFO, "MSF", "application disconnect(bool, result) 5");
- if (in_disconnect_cb != NULL) {
- if ((*in_disconnect_cb) != NULL) {
- Error err(-1, "error", "stop failed");
- DisconnectboolCallback *r = new DisconnectboolCallback();
- r->app_p = this->app_p;
- r->in_disconnect_cb = this->in_disconnect_cb;
- r->onError(err);
- }
- } else {
- }
-
- //temp->onSuccess(me);
- }
-
- delete (this);
- }
-
- void onError(Error error)
- {
- dlog_print(DLOG_ERROR, "MSF", "application disconnect(bool, result) 6");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- if (in_disconnect_cb != NULL) {
- if ((*in_disconnect_cb) != NULL) {
- dlog_print(DLOG_ERROR, "MSF", "application disconnect(bool, result) 7");
- (*in_disconnect_cb)->onError(error);
- }
- }
-
- delete (this);
- }
-};
-Application::Application()
-{
- dlog_print(DLOG_INFO, "MSF", "Application()");
- waitForOnReady = false;
- webapp = false;
- install_result_listener = NULL;
- install_result = false;
-}
-
-Application::Application(Service *se, string Uri, string Id)
-{
- dlog_print(DLOG_INFO, "MSF", "Application(service, uri, id, startargs)");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- map<string, string> startargs = std::map<std::string, std::string>();
- service = se;
- m_uri = Uri;
- ChannelID = Id;
- bool webApp = false;
- uri_parser::URIParse uri2(m_uri);
- if (!(uri2.getURIScheme() == "")) {
- dlog_print(DLOG_INFO, "MSF", "webapp set as true");
- webApp = true;
- }
-
- this->webapp = webApp;
- this->startArgs = &startargs;
- waitForOnReady = false;
- install_result_listener = NULL;
- install_result = false;
-}
-
-Application::Application(Service *se, string Uri, string Id, map<string, string> startargs)
-{
- dlog_print(DLOG_INFO, "MSF", "Application(service, uri, id, startargs)");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- service = se;
- m_uri = Uri;
- ChannelID = Id;
- bool webApp = false;
- uri_parser::URIParse uri2(m_uri);
- if (!(uri2.getURIScheme() == "")) {
- dlog_print(DLOG_INFO, "MSF", "webapp set as true");
- webApp = true;
- }
-
- this->webapp = webApp;
- this->startArgs = &startargs;
- waitForOnReady = false;
- install_result_listener = NULL;
- install_result = false;
-}
-
-Application::~Application()
-{
- dlog_print(DLOG_INFO, "MSF", "~Application()");
-}
-
-bool Application::isConnected()
-{
- dlog_print(DLOG_INFO, "MSF", "Channel::isConnected() = %s", Channel::isConnected() ? "true" : "false");
- dlog_print(DLOG_INFO, "MSF", "connected = %s", connected ? "true" : "false");
- //return (Channel::isConnected() && connected);
- return (Channel::isConnected());
-}
-
-bool Application::isWebapp()
-{
- return webapp;
-}
-
-void Application::getinfo(Result_Base *result1)
-{
- string uri = service->getUri();
- if (isWebapp()) {
- uri += "webapplication/";
- } else {
- //TODO
- //uri += "applications/" + service->getid() + "/";
- }
-
- result = result1;
- int ret = curl_application_calling(uri);
- if (ret == -1) {
- if (result1 != NULL)
- result1->onError(Error::create("Failed to get info"));
- }
-}
-
-void Application::start(Result_Base *result)
-{
- Clients *clientstemp = Channel::getclients();
-
- if (clientstemp->getHost() == NULL)
- waitForOnReady = true;
-
- map<string, string> params = getparams();
-
- invokeMethod(webapp?Message::METHOD_WEB_APPLICATION_START : Message::METHOD_APPLICATION_START, params, result);
-}
-
-void Application::stop(Result_Base *result)
-{
- map<string, string> params = getparams();
- invokeMethod(webapp?Message::METHOD_WEB_APPLICATION_STOP : Message::METHOD_APPLICATION_STOP, params, result);
-}
-
-void Application::install()
-{
- int ret;
- if (webapp) {
- string randID = Channel::getUID();
- dlog_print(DLOG_INFO, "MSF", "install call registercallback");
- if (install_result_listener) {
- install_result_listener->onError(Error::create("Unsupported Method"));
- }
- /* Channel::registerCallback(randID,(void*)result,Result_bool); *
- * handleError(randID,Error::create("Unsupported Method")); */
- } else {
- string Uri = service->getUri().append(ROUTE_APPLICATION).append(m_uri);
- dlog_print(DLOG_INFO, "MSF", "install uri = %s", Uri.c_str());
- ret = Application::curl_install(Uri);
- if (ret == -1) {
- if (install_result_listener)
- install_result_listener->onError(Error::create("Failed to Install"));
- }
- }
-}
-
-map<string, string> Application::getparams()
-{
- string messagekey = Message::PROPERTY_ID;
- string id = m_uri;
- if (webapp) {
- messagekey = Message::PROPERTY_URL;
- }
- map <string, string> params;
- params[messagekey] = id;
- return params;
-}
-
-
-void Application::connect()
-{
- //Channel::connect();
- connect(NULL);
-}
-
-void Application::connect(Result_Base *res)
-{
- connect(map<string, string>(), res);
-}
-
-void Application::connect(map<string, string> attributes, Result_Base *res)
-{
- dlog_print(DLOG_INFO, "MSF", "Application::connect(at, res)");
-
- connectCallback* r = new connectCallback();
- r->in_connect_cb = &connect_cb;
- r->app_pointer = this;
-
- Channel::connect(attributes, r);
-}
-
-void Application::disconnect()
-{
- dlog_print(DLOG_INFO, "MSF", "application disconnect()");
-
- disconnect(true);
-}
-
-void Application::disconnect(Result_Base *r)
-{
- dlog_print(DLOG_INFO, "MSF", "application disconnect(result)");
- disconnect(true);
-}
-
-void Application::disconnect(bool stopOnDisconnect)
-{
- dlog_print(DLOG_INFO, "MSF", "application disconnect(bool, result) 1");
-
- if (stopOnDisconnect) {
- dlog_print(DLOG_INFO, "MSF", "application disconnect(bool, result) 2");
- int numClients = 0;
- numClients = clients->size();
- static Client me ;
- me = clients->me();
-
- fprintf(stderr, "\n MYCLIENT ID IS[%s] and Number of clients is [%d]\n", me.getId(), numClients);
-
- dlog_print(DLOG_INFO, "MSF", "numClients = %d", numClients);
- dlog_print(DLOG_INFO, "MSF", "clients->getHost : %s", clients->getHost() ? "true" : "false");
- dlog_print(DLOG_INFO, "MSF", "strncmp(me.getId(),"",1) : %d", strncmp(me.getId(), "", 1));
- if (((numClients == 2) && (clients->getHost() != NULL) && strncmp(me.getId(), "", 1)) ||
- ((numClients == 1) && (strncmp(me.getId(), "", 1))) ||
- (numClients == 0)) {
- dlog_print(DLOG_INFO, "MSF", "application disconnect(bool, result) 3");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-
- //Result_Base *rbool = NULL;;
-
- DisconnectboolCallback *r = new DisconnectboolCallback();
- r->in_disconnect_cb = &disconnect_cb;
- r->app_p = this;
-
- //rbool= r1bool;
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- stop(r);
- return;
- }
- }
-
- realDisconnect(disconnect_cb);
-}
-
-void Application:: realDisconnect(Result_Base *result)
-{
- Channel::disconnect(result);
-}
-
-void Application::invokeMethod(string method, map<string, string> params, string messageID, Result_Base *callback)
-{
- dlog_print(DLOG_INFO, "MSF", "invokeMethod ()");
- if (!Channel::isConnected()) {
- dlog_print(DLOG_ERROR, "MSF", "invokeMethod() 1");
- Channel::handleError(messageID, Error::create("Not Connected"));
- return;
- }
-
- dlog_print(DLOG_INFO, "MSF", "invokeMethod() 2");
- int l = 0;
- string id = webapp?"url":"id";
- char buffer[2000];
- l += snprintf((char *)&buffer, sizeof(buffer), " {\n \"method\": \"%s\",\n \"id\": %s, \n \"params\" : { \n \"%s\": \"%s\" \n } \n }", method.c_str(), messageID.c_str(), id.c_str(), params[id].c_str());
- buffer[l] ='\0';
- dlog_print(DLOG_INFO, "MSF", "invokeMethod() 3");
- dlog_print(DLOG_INFO, "MSF", "invokeMethod() buf = %s", buffer);
- Channel::start_app(buffer, l, messageID);
-}
-
-void Application::invokeMethod(string method, map<string, string> params, Result_Base *callback)
-{
- string messageID = Channel::getUID();
- dlog_print(DLOG_INFO, "MSF", "invokeMethod call registercallback");
- Channel::registerCallback(messageID, (void*)callback, Result_bool);
- invokeMethod(method, params, messageID, callback);
-}
-
-
-Application Application::create(Service *service, string uri)
-{
- dlog_print(DLOG_INFO, "MSF", "Application::create(service, uri)");
- fprintf(stderr, "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- if (!((service == NULL) || (uri == ""))) {
- string id = uri;
- uri_parser::URIParse uri2(uri);
- if (!(uri2.getURIScheme() == "")) {
- id = uri2.getURIHost();
- }
- //Application *application=new Application(service, uri, id , std::map<std::string, std::string>());
- Application app(service, uri, id , std::map<std::string, std::string>());
- return app;
- } else {
- Application app;
- return app;
- }
-}
-
-Application Application::create(Service *service, string uri, string id, map<string, string> startargs)
-{
- dlog_print(DLOG_INFO, "MSF", "Application::create(service, uri, id, startargs)");
-
- if (!((service == NULL) || (uri == "") || (id == ""))) {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- /*Application *application= new Application(service, uri, id , startargs); */
- Application app(service, uri, id , startargs);
- return app;
- } else {
- Application app;
- return app;
- }
-}
-
-void Application::createdata_process(string data)
-{
- printf("ApplicationInfo curl data : %s", data.c_str());
- ApplicationInfo InfoObj;
- InfoObj.create(data);
- result->onSuccess(InfoObj);
-}
-
-size_t Application::createdata(char* buf, size_t size, size_t nmemb, void* up)
-{
- MSF_DBG("\n Debug Log: SERVICE FOUND THROUGH WITH URI [%s] [%d] in %s \n", __FUNCTION__, __LINE__, __FILE__);
- if (buf != NULL) {
- curl_data.append(buf, size*nmemb);
- } else {
- dlog_print(DLOG_ERROR, "MSF", "createdata() buf is null");
- }
-
- return size*nmemb;
-}
-
-size_t Application::read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
-{
- //((char*)ptr)[size*nmemb-1] = 0;
- dlog_print(DLOG_ERROR, "MSF", "read_callback = %s", (char*)ptr);
- if (ptr != NULL)
- static_cast<Application*>(stream)->curl_install_data.append(static_cast<const char*>(ptr), size*nmemb);
-
- return size*nmemb;
-}
-
-int Application::curl_application_calling(string uri)
-{
- CURL *curl;
- CURLcode res = CURLE_FAILED_INIT;
- struct curl_slist *headers = NULL;
- headers = curl_slist_append(headers, "Accept: application/json");
- headers = curl_slist_append(headers, "Content-Type: application/json");
-
- curl = curl_easy_init();
- dlog_print(DLOG_INFO, "MSF", "uri = %s", uri.c_str());
-
- if (curl) {
- const char *c = uri.c_str();
- curl_easy_setopt(curl, CURLOPT_URL, c);
- curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Application::createdata);
- curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
- res = curl_easy_perform(curl);
-
- if (res != CURLE_OK) {
- dlog_print(DLOG_ERROR, "MSF", "####Application curl ERROR = %d ####", res);
- MSF_DBG("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
- } else {
- createdata_process(curl_data);
- }
-
- curl_install_data.clear();
- curl_easy_cleanup(curl);
-
- if (res != CURLE_OK)
- return -1;
- else
- return 0;
- }
-
- return -1;
-}
-
-void Application::foreach_json_object(JsonObject* object, const gchar* key, JsonNode* node, gpointer user_data)
-{
- Application* p = static_cast<Application*>(user_data);
-
- if (!strncmp(key, "ok", 2)) {
- p->install_result = json_node_get_boolean(node);
- } else if (!strncmp(key, "status", 6)) {
- p->errstatus = json_node_get_int(node);
- } else if (!strncmp(key, "message", 7)) {
- p->errMsg = json_node_get_string(node);
- } else if (!strncmp(key, "code", 4)) {
- p->errcode = json_node_get_int(node);
- p->install_result = false;
- }
-}
-
-void Application::json_parse(const char* in)
-{
- JsonParser* parser = json_parser_new();
- if (json_parser_load_from_data(parser, in, -1, NULL)) {
- JsonNode* node = json_parser_get_root(parser);
-
- if (json_node_get_node_type(node) == JSON_NODE_OBJECT) {
- json_object_foreach_member(json_node_get_object(node), foreach_json_object, this);
- }
-
- } else {
- }
-}
-
-int Application::curl_install(string uri)
-{
- CURL *curl;
- CURLcode res = CURLE_FAILED_INIT;
- struct curl_slist *headers = NULL;
- headers = curl_slist_append(headers, "Accept: application/json");
- headers = curl_slist_append(headers, "Content-Type: application/json");
- curl_global_init(CURL_GLOBAL_ALL);
- curl = curl_easy_init();
-
- if (curl) {
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Application::read_callback);
- curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
- curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- curl_easy_setopt(curl, CURLOPT_URL, uri.c_str());
-
- dlog_print(DLOG_ERROR, "MSF", "install curl put send");
- res = curl_easy_perform(curl);
-
- if (res != CURLE_OK) {
- dlog_print(DLOG_ERROR, "MSF", "####Application curl ERROR = %d ####", res);
- MSF_DBG("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
- } else {
- dlog_print(DLOG_ERROR, "MSF", "####Application curl success ####");
- json_parse(curl_install_data.c_str());
-
- if (install_result_listener != NULL) {
- if (install_result) {
- install_result_listener->onSuccess(install_result);
- } else {
- string err = "";
- err.append("status:");
- err.append(to_string(errstatus));
- err.append(" message:");
- err.append(errMsg);
- err.append(" code:");
- err.append(to_string(errcode));
- install_result_listener->onError(Error::create(err));
- }
- }
- }
-
-
-
- curl_install_data.clear();
-
- curl_easy_cleanup(curl);
- curl_global_cleanup();
- }
-
- if (res != CURLE_OK)
- return -1;
- else
- return 0;
-}
-
-void Application::setonInstallListener(Result_Base* listener)
-{
- install_result_listener = listener;
-}
-
-void Application::unsetonInstallListener()
-{
- install_result_listener = NULL;
-}
+++ /dev/null
-#include"ApplicationInfo.h"
-
-string ApplicationInfo::PROPERTY_ID = "id";
-string ApplicationInfo::PROPERTY_STATE = "running";
-string ApplicationInfo::PROPERTY_NAME = "name";
-string ApplicationInfo::PROPERTY_VERSION = "version";
-
-ApplicationInfo::ApplicationInfo()
-{
-}
-
-ApplicationInfo::ApplicationInfo(string iD, bool state, string Name, string Version)
-{
- id = iD;
- running = state;
- name = Name;
- msf_version = Version;
-}
-
-string ApplicationInfo::getID()
-{
- return id;
-}
-
-string ApplicationInfo::getName()
-{
- return name;
-}
-
-string ApplicationInfo::getVersion()
-{
- return msf_version;
-}
-
-bool ApplicationInfo::isRunning()
-{
- return running;
-}
-
-void ApplicationInfo::foreach_json_object(JsonObject* object, const gchar* key, JsonNode* node, gpointer user_data)
-{
- ApplicationInfo* p = static_cast<ApplicationInfo*>(user_data);
-
- if (json_node_get_node_type(node) == JSON_NODE_VALUE) {
- if (!strncmp(key, ApplicationInfo::PROPERTY_STATE.c_str(), 7)) {
- p->running = json_node_get_boolean(node);
- } else if (!strncmp(key, ApplicationInfo::PROPERTY_ID.c_str(), 2)) {
- p->id = json_node_get_string(node);
- } else if (!strncmp(key, ApplicationInfo::PROPERTY_NAME.c_str(), 4)) {
- p->name = json_node_get_string(node);
- } else if (!strncmp(key, ApplicationInfo::PROPERTY_VERSION.c_str(), 7)) {
- p->msf_version = json_node_get_string(node);
- }
- } else if (json_node_get_node_type(node) == JSON_NODE_OBJECT) {
- json_object_foreach_member(json_node_get_object(node), foreach_json_object, user_data);
- }
-}
-
-void ApplicationInfo::json_parse(const char* in)
-{
- JsonParser* parser = json_parser_new();
- if (json_parser_load_from_data(parser, in, -1, NULL)) {
- JsonNode* node = json_parser_get_root(parser);
-
- if (json_node_get_node_type(node) == JSON_NODE_OBJECT) {
- json_object_foreach_member(json_node_get_object(node), foreach_json_object, this);
- }
-
- } else {
- }
-}
-
-ApplicationInfo ApplicationInfo::create(string data)
-{
- json_parse(data.c_str());
-
- ApplicationInfo appinfo(id, running, name, msf_version);
-
- return appinfo;
-}
+++ /dev/null
-#include <stdlib.h>
-#include <ctime>
-#include <time.h>
-#include <sstream>
-#include <string>
-#include <iterator>
-#include "Clients.h"
-#include "Service.h"
-#include "Channel.h"
-#include "Message.h"
-#include "Debug.h"
-
-#define JSON_KEY_IS_HOST 0
-#define JSON_KEY_CONNECT_TIME 1
-#define JSON_KEY_STATUS 2
-#define JSON_KEY_CODE 3
-#define JSON_KEY_ATTRIBUTES 4
-#define JSON_KEY_RESULT 5
-#define JSON_KEY_MESSAGE_ID 6
-#define JSON_KEY_ERROR 7
-#define JSON_KEY_EVENT 8
-#define JSON_KEY_FROM 9
-#define JSON_KEY_MESSAGE 10
-#define JSON_KEY_METHOD 11
-#define JSON_KEY_DATA 12
-#define JSON_KEY_CLIENTS 13
-
-class Application;
-
-using namespace std;
-
-string ChannelConnectionHandler::PING = "channel.ping";
-string ChannelConnectionHandler::PONG = "pong";
-Channel *ChannelConnectionHandler::channel_ptr = NULL;
-string Channel::ROUTE = "channels";
-string Channel::ERROR_EVENT = "ms.error";
-string Channel::CONNECT_EVENT = "ms.channel.connect";
-string Channel::CLIENT_CONNECT_EVENT = "ms.channel.clientConnect";
-string Channel::CLIENT_DISCONNECT_EVENT = "ms.channel.clientDisconnect";
-string Channel::READY_EVENT = "ms.channel.read";
-map<Channel *, int> Channel::channel_alive_map;
-map<string, int> Channel::json_keys;
-pthread_t Channel::connect_thread;
-pthread_t ChannelConnectionHandler::ping_thread = 0;
-
-ChannelConnectionHandler::ChannelConnectionHandler() {
- pingTimeout = 5000000;
- lastPingReceived = 0;
- running = false;
-}
-
-Channel::Channel() {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- clientisHost = false;
- isWrite = false;
- buflen = 0;
- was_closed = 1;
- wsi_mirror = NULL;
- Context = NULL;
- mirror_lifetime = 0;
- disconnecting = false;
- from = "";
- clients = new Clients(this); // new to destroy in destructer
- isLaunched = false;
- connectionHandler = new ChannelConnectionHandler();
- resultresp = false;
- channel_alive_map.insert({this, 1});
- init_json_key_map();
- cl_payload_size = 0;
-}
-
-Channel::Channel(Service *service1, string uri1) {
- dlog_print(DLOG_INFO, "MSF", "Channel()");
- clientisHost = false;
- isWrite = false;
- buflen = 0;
- was_closed = 1;
- wsi_mirror = NULL;
- Context = NULL;
- mirror_lifetime = 0;
- disconnecting = false;
- from = "";
- clients = new Clients(this); // new to destroy in destructer
- isLaunched = false;
- connectionHandler = new ChannelConnectionHandler();
- resultresp = false;
- service = service1;
- ChannelID = uri1;
- channel_alive_map.insert({this, 1});
- init_json_key_map();
- cl_payload_size = 0;
-}
-
-Channel *Channel::create(Service *service, string uri) {
- dlog_print(DLOG_INFO, "MSF", "Channel()");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- fprintf(stderr, "\n********************************\n");
- if ((service == NULL) || uri.length() <= 0)
- return NULL;
- Channel *channel = new Channel(service, uri);
- return channel;
-}
-
-Channel::~Channel() {
- dlog_print(DLOG_INFO, "MSF", "~Channel()");
- connect_cb = NULL;
- disconnect_cb = NULL;
- onConnectListener = NULL;
- onDisconnectListener = NULL;
- onClientConnectListener = NULL;
- onClientDisconnectListener = NULL;
- onReadyListener = NULL;
- channel_alive_map[this] = 0;
-
- if (clients != NULL) {
- delete clients;
- clients = NULL;
- }
- if (connectionHandler != NULL) {
- delete connectionHandler;
- connectionHandler = NULL;
- }
-}
-
-void Channel::init_json_key_map() {
- static bool done = false;
-
- if (!done) {
- json_keys["isHost"] = JSON_KEY_IS_HOST;
- json_keys["connectTime"] = JSON_KEY_CONNECT_TIME;
- json_keys["status"] = JSON_KEY_STATUS;
- json_keys["code"] = JSON_KEY_CODE;
- json_keys["attributes"] = JSON_KEY_ATTRIBUTES;
- json_keys[Message::PROPERTY_RESULT] = JSON_KEY_RESULT;
- json_keys[Message::PROPERTY_MESSAGE_ID] = JSON_KEY_MESSAGE_ID;
- json_keys[Message::PROPERTY_ERROR] = JSON_KEY_ERROR;
- json_keys[Message::PROPERTY_EVENT] = JSON_KEY_EVENT;
- json_keys[Message::PROPERTY_FROM] = JSON_KEY_FROM;
- json_keys[Message::PROPERTY_MESSAGE] = JSON_KEY_MESSAGE;
- json_keys[Message::PROPERTY_METHOD] = JSON_KEY_METHOD;
- json_keys[Message::PROPERTY_DATA] = JSON_KEY_DATA;
- json_keys[Message::PROPERTY_CLIENTS] = JSON_KEY_CLIENTS;
-
- done = true;
- }
-}
-
-void Channel::foreach_json_object(JsonObject *object, const gchar *name,
- JsonNode *node, gpointer user_data) {
- dlog_print(DLOG_INFO, "MSF", "foreach_json_object name : %s", name);
- if (json_keys.find(name) == json_keys.end()) {
- dlog_print(DLOG_INFO, "MSF",
- "foreach_json_object : there is no %s in map", name);
- return;
- }
-
- int key = json_keys[name];
- Channel *p = static_cast<Channel *>(user_data);
- static int iferror = 0;
- static bool arrayofclients = false;
-
- switch (key) {
- // key : isHost
- case JSON_KEY_IS_HOST: {
- p->clientisHost = json_node_get_boolean(node);
- dlog_print(DLOG_INFO, "MSF", "isHost set as %s",
- p->clientisHost ? "true" : "false");
-
- if (!strncmp(p->eventType.c_str(), CLIENT_CONNECT_EVENT.c_str(), 25) ||
- !strncmp(p->eventType.c_str(), CONNECT_EVENT.c_str(), 25)) {
- p->client.create(p, p->clientid, p->clientconnectTime,
- p->clientisHost, map<string, string>());
- dlog_print(DLOG_INFO, "MSF", "add clientList");
- p->clientList.push_back(p->client);
- }
- } break;
-
- // key : connectTime
- case JSON_KEY_CONNECT_TIME: {
- p->clientconnectTime = json_node_get_int(node);
- dlog_print(DLOG_INFO, "MSF", "clientconnectTime set as %lld",
- p->clientconnectTime);
- } break;
-
- // key : status
- case JSON_KEY_STATUS: {
- if (iferror) {
- p->errstatus = json_node_get_int(node);
- dlog_print(DLOG_INFO, "MSF", "p->errstatus set");
- }
- } break;
-
- // key : code
- case JSON_KEY_CODE: {
- if (iferror) {
- p->errcode = json_node_get_int(node);
- string eid = std::to_string(p->msg_id);
- dlog_print(DLOG_INFO, "MSF", "p->errcode set");
-
- if (p->callbacks.find(eid) != p->callbacks.end()) {
- dlog_print(DLOG_INFO, "MSF", "test 1");
- pair<void *, int> temp = p->getcallback(eid);
- if (temp.first != NULL) {
- Result_Base *temp1 = (Result_Base *)(temp.first);
- string err = "";
- err.append("status:");
- err.append(to_string(p->errstatus));
- err.append(" message:");
- err.append(p->errMsg);
- err.append(" code:");
- err.append(to_string(p->errcode));
- dlog_print(DLOG_INFO, "MSF", "test 2");
- if (temp1)
- temp1->onError(Error::create(err));
- if (p->onErrorListener)
- p->onErrorListener->onError();
- }
- }
- }
- } break;
-
- // key : attributes
- case JSON_KEY_ATTRIBUTES: {
- } break;
-
- // key : MESSAGE::PROPERTY_RESULT
- case JSON_KEY_RESULT: {
- if (json_node_get_node_type(node) == JSON_NODE_VALUE) {
- p->resultresp = json_node_get_boolean(node);
- if (p->resultresp) {
- dlog_print(DLOG_INFO, "MSF", "set resultresp as true");
- } else {
- dlog_print(DLOG_INFO, "MSF", "set resultresp as false");
- }
- p->msg_subject = Message::PROPERTY_RESULT;
- } else if (json_node_get_node_type(node) == JSON_NODE_OBJECT) {
- dlog_print(DLOG_INFO, "MSF", "set resultobj");
- g_free(p->resultobj);
- p->resultobj = json_node_dup_object(node);
- }
- } break;
-
- // key : MESSAGE::PROPERTY_MESSAGE_ID
- case JSON_KEY_MESSAGE_ID: {
- if (json_node_get_node_type(node) == JSON_NODE_VALUE) {
- if (json_node_get_value_type(node) == G_TYPE_INT ||
- json_node_get_value_type(node) == G_TYPE_INT64) {
- p->msg_id = json_node_get_int(node);
- dlog_print(DLOG_INFO, "MSF", "msg-id set as %d", p->msg_id);
- } else if (json_node_get_value_type(node) == G_TYPE_STRING) {
- if ((p->eventType == CLIENT_CONNECT_EVENT) || arrayofclients) {
- p->clientid = json_node_get_string(node);
- dlog_print(DLOG_INFO, "MSF", "clientid set as = %s",
- p->clientid.c_str());
- } else {
- p->from = json_node_get_string(node);
- dlog_print(DLOG_INFO, "MSF", "from set as = %s",
- p->from.c_str());
- }
- }
- }
- } break;
-
- // key : MESSAGE::PROPERTY_ERROR
- case JSON_KEY_ERROR: {
- if (json_node_get_node_type(node) == JSON_NODE_VALUE) {
- iferror = 1;
- dlog_print(DLOG_INFO, "MSF", "iferror set as 1");
- } else if (json_node_get_node_type(node) == JSON_NODE_OBJECT) {
- iferror = 1;
- dlog_print(DLOG_INFO, "MSF", "iferror set as 1");
- // g_free(p->errobj);
- p->errobj = true;
- json_object_foreach_member(json_node_get_object(node),
- foreach_json_object, user_data);
- }
- } break;
-
- // key : MESSAGE::PROPERTY_EVENT
- case JSON_KEY_EVENT: {
- p->eventType = json_node_get_string(node);
- dlog_print(DLOG_INFO, "MSF", "eventType set as = %s",
- p->eventType.c_str());
- } break;
-
- // key : MESSAGE::PROPERTY_FROM
- case JSON_KEY_FROM: {
- p->from = json_node_get_string(node);
- dlog_print(DLOG_INFO, "MSF", "from set as = %s", p->from.c_str());
- } break;
-
- // key : MESSAGE::PROPERTY_MESSAGE
- case JSON_KEY_MESSAGE: {
- p->errMsg = json_node_get_string(node);
- dlog_print(DLOG_INFO, "MSF", "errMsg set as = %s", p->errMsg.c_str());
- } break;
-
- // key : MESSAGE::PROPERTY_METHOD
- case JSON_KEY_METHOD: {
- p->method = json_node_get_string(node);
- dlog_print(DLOG_INFO, "MSF", "method set as = %s", p->method.c_str());
- } break;
- // key : MESSAGE:PROPERTY_DATA
- case JSON_KEY_DATA: {
- if (json_node_get_node_type(node) == JSON_NODE_VALUE) {
- if (json_node_get_value_type(node) == G_TYPE_STRING) {
- p->data = json_node_get_string(node);
- dlog_print(DLOG_INFO, "MSF", "data set as = %s",
- p->data.c_str());
- }
- } else if (json_node_get_node_type(node) == JSON_NODE_OBJECT) {
- json_object_foreach_member(json_node_get_object(node),
- foreach_json_object, user_data);
- }
- } break;
-
- // key : MESSAGE:PROPERTY_CLIENTS
- case JSON_KEY_CLIENTS: {
- arrayofclients = true;
- dlog_print(DLOG_INFO, "MSF", "array start");
- json_array_foreach_element(json_node_get_array(node),
- foreach_json_array, user_data);
- dlog_print(DLOG_INFO, "MSF", "array end");
- arrayofclients = false;
- } break;
-
- default:
- break;
- }
-}
-
-void Channel::foreach_json_array(JsonArray *array, guint index, JsonNode *node,
- gpointer user_data) {
- json_object_foreach_member(json_node_get_object(node), foreach_json_object,
- user_data);
-}
-
-void Channel::json_parse(const char *in) {
- dlog_print(DLOG_INFO, "MSF", "Channel::json_parse : %s", in);
-
- JsonParser *parser = json_parser_new();
-
- if (json_parser_load_from_data(parser, in, -1, NULL)) {
- JsonNode *node = json_parser_get_root(parser);
-
- if (json_node_get_node_type(node) == JSON_NODE_OBJECT) {
- json_object_foreach_member(json_node_get_object(node),
- foreach_json_object, this);
- }
-
- } else {
- dlog_print(DLOG_ERROR, "MSF", "json_parsing error");
- }
-}
-
-Clients *Channel::getclients() {
- if (clients->size())
- return clients;
- else
- return NULL;
-}
-
-void Channel::setConnectionTimeout(long timeout) {
- if (timeout < 0)
- return;
- else if (timeout == 0)
- connectionHandler->stopPing();
- else
- {
- connectionHandler->setPingTimeout(timeout);
- if (isWebSocketOpen())
- connectionHandler->startPing(this);
- }
-}
-
-void Channel::handleConnectMessage(string UID) {
- dlog_print(DLOG_INFO, "MSF", "handleConnectMessage(uid)");
-
- clients->reset();
- clients->add(clientList);
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
-
- clients->setMyClientId(from);
-
- handleConnect(UID);
- dlog_print(DLOG_INFO, "MSF", "handleConnectMessage(uid) 1");
-}
-
-void Channel::handleMessage(string UID) { handleMessage(UID, NULL); }
-
-void Channel::handleMessage(string UID, unsigned char payload[]) {
- if (eventType.length() == 0) {
- // if (msg_subject == Message::PROPERTY_RESULT) {
- // handleClientMessage(NULL,NULL);
- // return;
- //}
-
- handleApplicationMessage(UID);
- } else if (eventType == CLIENT_CONNECT_EVENT) {
- dlog_print(DLOG_INFO, "MSF", "call handleClientConnectMessage");
- handleClientConnectMessage();
- } else if (eventType == CLIENT_DISCONNECT_EVENT) {
- dlog_print(DLOG_INFO, "MSF", "call handleclientdisconnect");
- handleClientDisconnectMessage();
- } else if (eventType == ERROR_EVENT) {
- dlog_print(DLOG_INFO, "MSF", "call handleErrorMessage");
- handleErrorMessage(UID);
- } else if (eventType == READY_EVENT) {
- dlog_print(DLOG_INFO, "MSF", "call handleReadyMessage");
- handleReadyMessage();
- } else {
- dlog_print(DLOG_INFO, "MSF", "call handleClientMessage 2");
- handleClientMessage(data.c_str(), payload);
- }
-}
-
-void Channel::handleApplicationMessage(string uid) {
- dlog_print(DLOG_INFO, "MSF", "handleApplicationMessage 1");
- MSF_DBG(
- "[MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- string messageId = uid;
- bool errorMap = errobj;
- dlog_print(DLOG_INFO, "MSF", "handleApplicationMessage 2");
- pair<void *, int> temp = getcallback(messageId);
-
- dlog_print(DLOG_INFO, "MSF", "handleApplicationMessage 3");
-
- if (temp.first != NULL) {
- dlog_print(DLOG_INFO, "MSF", "handleApplicationMessage 4");
- if ((waitForOnReady) && (errorMap == false)) {
- dlog_print(DLOG_INFO, "MSF", "handleApplicationMessage 5");
- MSF_DBG("[MSF : API] Debug log Function : [%s] and line [%d] in "
- "file [%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- onReadyCallbacks.insert(temp);
- if (!isLaunched) {
- dlog_print(DLOG_INFO, "MSF", "handleApplicationMessage 6");
- MSF_DBG("[MSF : API] Debug log Function : [%s] and line [%d] "
- "in file [%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- isLaunched = true;
- } else {
- dlog_print(DLOG_INFO, "MSF", "handleApplicationMessage 7");
- MSF_DBG("[MSF : API] Debug log Function : [%s] and line [%d] "
- "in file [%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- // handleClientDisconnectMessage();
- isLaunched = false;
-
- if (temp.second == Result_bool) {
- dlog_print(DLOG_INFO, "MSF", "handleApplicationMessage 8");
- doApplicationCallback((Result_Base *)(temp.first));
- }
- }
- return;
- }
-
- if (temp.second == Result_bool) {
- dlog_print(DLOG_INFO, "MSF", "handleApplicationMessage 8");
- MSF_DBG("[MSF : API] Debug log Function : [%s] and line [%d] in "
- "file [%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- doApplicationCallback((Result_Base *)(temp.first));
- }
- } else {
- doApplicationCallback(NULL);
- }
-}
-
-void Channel::doApplicationCallback(Result_Base *result1) {
- dlog_print(DLOG_INFO, "MSF", "doApplicationCallback 1");
- MSF_DBG(
- "[MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- if (resultobj != NULL) {
- dlog_print(DLOG_INFO, "MSF", "doApplicationCallback 2");
- MSF_DBG("[MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- }
-
- bool errorMap = errobj;
-
- if (errorMap != false) {
- dlog_print(DLOG_ERROR, "MSF", "doApplicationCallback 3");
- MSF_DBG("[MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- int code = errcode;
- stringstream ss;
- ss << code;
- string str = ss.str();
- if (result1 != NULL)
- result1->onError(Error::create(str));
- } else {
- dlog_print(DLOG_INFO, "MSF", "doApplicationCallback 4");
-
- MSF_DBG("[MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- // ApplicationInfo *InfoObj=new ApplicationInfo();
- if (resultobj != NULL) {
- dlog_print(DLOG_INFO, "MSF", "doApplicationCallback 5");
- // string json=json_object_to_json_string(resultobj);
- // InfoObj->create(json);
- if (result1 != NULL) {
- dlog_print(DLOG_INFO, "MSF", "doApplicationCallback 6");
- result1->onSuccess(true);
- }
- }
-
- if (msg_subject == Message::PROPERTY_RESULT) {
- dlog_print(DLOG_INFO, "MSF", "doApplicationCallback 7");
- if (result1 != NULL) {
- dlog_print(DLOG_INFO, "MSF", "doApplicationCallback 8");
- result1->onSuccess(true);
- }
- }
- }
-}
-
-void Channel::handleErrorMessage(string UID) {
- Error err = Error::create(errMsg);
- handleError(UID, err);
-}
-
-void Channel::handleError(string UID, Error err) {
- if (UID.length() != 0) {
- pair<void *, int> temp = Channel::getcallback(UID);
- MSF_DBG("[MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- if (temp.first != NULL) {
- if (temp.second == Result_Client) {
- Result_Base *temp1 = (Result_Base *)(temp.first);
- if (temp1)
- temp1->onError(err);
- } else if (temp.second == Result_bool) {
- Result_Base *temp1 = (Result_Base *)(temp.first);
- if (temp1)
- temp1->onError(err);
- }
-
- if (onErrorListener)
- onErrorListener->onError();
- }
- }
-}
-
-void Channel::handleClientMessage(const char *msg, unsigned char payload[]) {
- dlog_print(DLOG_INFO, "MSF", "handleClientMessage 0");
-
- emit(eventType, msg, from, cl_payload, cl_payload_size);
-}
-
-void Channel::emit(string event, const char *msg, string from,
- unsigned char *payld, int payld_size) {
- dlog_print(DLOG_INFO, "MSF", "emit");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- if (msg == NULL) {
- dlog_print(DLOG_INFO, "MSF", "emit msg = NULL");
- return;
- }
-
- if (message_receive_cb) {
- Message mesg(this, event, msg, from, payld, payld_size);
- message_receive_cb(mesg);
- }
-
- if (everyMessageListener) {
- Message mesg(this, event, msg, from, payld, payld_size);
- everyMessageListener->onMessage(mesg);
- }
-
- if (messageListeners.size() != 0) {
- dlog_print(DLOG_INFO, "MSF", "emit 1");
-
- if (messageListeners.find(event) == messageListeners.end()) {
- dlog_print(DLOG_INFO, "MSF", "map not found");
- return;
- }
-
- list<OnMessageListener *> &onMessageListeners =
- (messageListeners.find(event))->second;
- dlog_print(DLOG_INFO, "MSF", "emit 2");
-
- if (onMessageListeners.size() != 0) {
- dlog_print(DLOG_INFO, "MSF", "emit 3");
- std::list<OnMessageListener *>::const_iterator iterator;
- for (iterator = onMessageListeners.begin();
- iterator != onMessageListeners.end(); ++iterator) {
- Message mesg(this, event, msg, from, payld, payld_size);
- (*iterator)->onMessage(mesg);
- }
- } else {
- dlog_print(DLOG_INFO, "MSF", "empty listeners");
- }
- }
-}
-
-bool Channel::connect() { return connect(connect_cb); }
-
-bool Channel::connect(Result_Base *result1) {
- bool ret = connect(map<string, string>(), result1);
- return ret;
-}
-
-bool Channel::connect(map<string, string> attributes, Result_Base *result1) {
- dlog_print(DLOG_INFO, "MSF", "Channel::connect(at, res)");
-
- string uid = getUID();
-
- dlog_print(DLOG_INFO, "MSF", "connect call registercallback");
- registerCallback(uid, (void *)result1, Result_Client);
-
- UID = uid;
- if (isWebSocketOpen()) {
- handleError(uid, Error::create("Already Connected"));
- return false;
- }
-
- map<string, string> *at_data = new map<string, string>(attributes);
- map<Channel *, map<string, string> *> *pt_user_data =
- new map<Channel *, map<string, string> *>();
- pt_user_data->insert({this, at_data});
-
- int status = pthread_create(&connect_thread, NULL, pt_startConnect,
- (void *)pt_user_data);
-
- if (status)
- return true;
- else
- return false;
-}
-
-void Channel::disconnect() {
- dlog_print(DLOG_INFO, "MSF", "channel disconnect()");
- disconnect(disconnect_cb);
-}
-
-void Channel::disconnect(Result_Base *result1) {
- dlog_print(DLOG_INFO, "MSF", "channel disconnect(result) 1");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- string randID = getUID();
- UID = randID;
- dlog_print(DLOG_INFO, "MSF", "disconnect call registercallback");
- registerCallback(randID, (void *)result1, Result_Client);
- string message = "";
- if (!isWebSocketOpen())
- message = "Already Disconnected";
- if (disconnecting)
- message = "Already Disconnecting";
- if (message != "")
- handleError(UID, Error::create(message));
- else
- {
- dlog_print(DLOG_INFO, "MSF", "channel disconnect(result) 2");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in "
- "file [%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- disconnecting = true;
- // consume the callback
- getcallback(randID);
-
- dlog_print(DLOG_INFO, "MSF", "channel disconnect(result) 3");
-
- while (1) {
- if (mirror_lifetime > 0)
- mirror_lifetime--;
-
- if (!mirror_lifetime) {
- dlog_print(DLOG_INFO, "MSF", "channel disconnect(result) 4");
- break;
- }
- }
-
- was_closed = 1;
-
- if (result1) {
- dlog_print(DLOG_INFO, "MSF", "channel disconnect(result) 5");
-
- if (Channel::onDisconnectListener != NULL) {
- dlog_print(DLOG_INFO, "MSF", "disconnect()");
- // Channel::onDisconnectListener->onDisconnect(client);
- }
-
- result1->onSuccess(clients->me());
- }
-
- if (disconnecting) {
- disconnecting = false;
- }
-
- connectionHandler->stopPing();
- }
-}
-
-void Channel::handleReadyMessage() {
- waitForOnReady = false;
- std::map<void *, int>::const_iterator iterator;
- for (iterator = onReadyCallbacks.begin();
- iterator != onReadyCallbacks.end(); ++iterator) {
- Result_Base *res = (Result_Base *)iterator->first;
- onReadyCallbacks.erase(res);
- doApplicationCallback(res);
- }
- if (onConnectListener)
- onConnectListener->onConnect(clients->me());
-
- if (onReadyListener != NULL)
- onReadyListener->onReady();
-}
-
-void Channel::handleClientConnectMessage() {
- dlog_print(DLOG_INFO, "MSF", "handleClientConnectMessage");
-
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- if (client.isHost())
- connected = true;
-
- clients->add(client);
-
- dlog_print(DLOG_INFO, "MSF", "handleClientConnectMessage client = %s",
- client.getId());
- MSF_DBG("\n Debug Log: CLIENTLIST SIZE IS [%d], %s %d in %s \n",
- clients->size(), __FUNCTION__, __LINE__, __FILE__);
- if (onClientConnectListener != NULL)
- onClientConnectListener->onClientConnect(client);
-}
-
-void Channel::handleClientDisconnectMessage() {
- dlog_print(DLOG_INFO, "MSF", "handle client disconnect Message event = %s",
- eventType.c_str());
-
- if (resultresp && isLaunched) {
- dlog_print(DLOG_INFO, "MSF", "handleclientdisconnectMessage 1");
- handleSocketClosed();
- return;
- }
-
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- Client client = clients->get(clientid);
- if (client.isHost()) {
- dlog_print(DLOG_INFO, "MSF", "handleclientdisconnectMessage 2");
- connected = false;
- }
- clients->remove(client);
-
- if (onClientDisconnectListener != NULL) {
- dlog_print(DLOG_INFO, "MSF", "handleclientdisconnectMessage 3");
- onClientDisconnectListener->onClientDisconnect(client);
- }
-}
-
-void Channel::handleConnect(string UID) {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- dlog_print(DLOG_INFO, "MSF", "handleConnect");
- Client clienttemp = clients->me();
-
- pair<void *, int> temp;
-
- temp = Channel::getcallback(UID);
- if (temp.second == Result_Client) {
- Result_Base *temp1 = (Result_Base *)(temp.first);
- if (temp1)
- temp1->onSuccess(clienttemp);
- } else if (temp.second == Result_bool) {
- Result_Base *temp1 = (Result_Base *)(temp.first);
- if (temp1)
- temp1->onSuccess(true);
- }
-
- me = clients->me();
-
- if (onConnectListener)
- onConnectListener->onConnect(clienttemp);
- // To start channnel heath check
- if (isWebSocketOpen()) {
- // connectionHandler->startPing(this);
- }
-
- dlog_print(DLOG_INFO, "MSF", "handleConnect 1");
-}
-
-void Channel::handleSocketClosedAndNotify() {
- Client client = clients->me();
- handleSocketClosed();
-
- if (Channel::onDisconnectListener != NULL) {
- dlog_print(DLOG_INFO, "MSF", "handleSocketClosedAndNotify");
- Channel::onDisconnectListener->onDisconnect(client);
- }
-}
-
-void Channel::handleSocketClosed() {
- dlog_print(DLOG_INFO, "MSF", "handleSocketClosed");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- connectionHandler->stopPing();
- wsi_mirror = NULL;
- connected = false;
- was_closed = 1;
- if (disconnecting)
- disconnecting = false;
- callbacks.clear();
- clients->reset();
-}
-
-int Channel::callback_lws_mirror(struct lws *wsi,
- enum lws_callback_reasons reason, void *user,
- void *in, size_t len) {
- int n;
- void *user_data;
- Channel *this_ptr = NULL;
- struct lws_context *context = lws_get_context(wsi);
- user_data = lws_context_user(context);
- this_ptr = static_cast<Channel *>(user_data);
-
- if (channel_alive_map.find(this_ptr) != channel_alive_map.end()) {
- if (channel_alive_map[this_ptr] == 0) {
- return -1;
- }
- } else {
- return -1;
- }
-
- switch (reason) {
- case LWS_CALLBACK_ESTABLISHED:
- break;
-
- case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
- break;
-
- case LWS_CALLBACK_CLOSED:
- if (this_ptr->disconnecting) {
- dlog_print(DLOG_INFO, "MSF_SOCKET", "socket closed diconnecting");
- MSF_DBG("mirror: LWS_CALLBACK_CLOSED\n");
- this_ptr->wsi_mirror = NULL;
- this_ptr->mirror_lifetime = 0;
- this_ptr->disconnecting = false;
-
- } else {
- dlog_print(DLOG_INFO, "MSF_SOCKET",
- "socket closed not diconnecting");
- dlog_print(DLOG_INFO, "MSF_SOCKET",
- "call handleSocketClosedAndNotify");
- this_ptr->handleSocketClosedAndNotify();
- }
- break;
-
- case LWS_CALLBACK_CLIENT_ESTABLISHED:
- MSF_DBG("[MSF LOG]: LWS_CALLBACK_CLIENT_ESTABLISHED [%s]\n",
- __FUNCTION__);
- lws_callback_on_writable(wsi);
- break;
-
- case LWS_CALLBACK_CLIENT_RECEIVE:
- if (this_ptr == NULL) {
- dlog_print(DLOG_INFO, "MSF", "user ptr is NULL. return.");
- // it means Channel object was deleted
- return -1;
- } else {
- dlog_print(DLOG_INFO, "MSF", "user ptr is not NULL.");
- }
-
- this_ptr->eventType = "";
-
- if (lws_frame_is_binary(wsi)) {
- dlog_print(DLOG_INFO, "MSF", "BINARY MESSAGE ARRIVED");
-
- int header_size = 0;
-
- header_size = (int)((unsigned char *)in)[0];
- header_size = header_size << 8;
- header_size = header_size & 0xff00;
- header_size = header_size | (int)((unsigned char *)in)[1];
- dlog_print(DLOG_INFO, "MSF", "header_size = %d", header_size);
-
- char header_json[header_size + 1] = {0};
-
- memcpy(&header_json[0], &(((unsigned char *)in)[2]), header_size);
- header_json[header_size + 1] = 0;
-
- dlog_print(DLOG_INFO, "MSF", "in = %s", &header_json[0]);
-
- this_ptr->json_parse(header_json);
- memcpy(&(this_ptr->cl_payload),
- &(((unsigned char *)in)[2 + header_size]),
- len - 2 - header_size);
-
- this_ptr->cl_payload[len - 2 - header_size] = 0;
- this_ptr->cl_payload_size = len - 2 - header_size;
-
- dlog_print(DLOG_INFO, "MSF", "payload = %s",
- &(this_ptr->cl_payload[0]));
-
- this_ptr->connectionHandler->resetLastPingReceived();
-
- if (this_ptr->eventType == CONNECT_EVENT) {
- this_ptr->handleConnectMessage(this_ptr->UID);
- } else {
- // this_ptr->handleMessage(this_ptr->UID);
- this_ptr->handleMessage(this_ptr->UID, this_ptr->cl_payload);
- }
- } else {
- dlog_print(DLOG_INFO, "MSF", "TEXT MESSAGE ARRIVED");
- MSF_DBG("[MSF LOG]LWS_CALLBACK_RECEIVE_ESTABLISHED:\t");
- MSF_DBG("\n%s\n", (char *)in);
- fprintf(stderr, "\n %s \n", (char *)in);
- dlog_print(DLOG_INFO, "MSF", "socket in = %s", (char *)in);
- this_ptr->json_parse((char *)in);
- this_ptr->connectionHandler->resetLastPingReceived();
-
- // dead code.
- // server do not send METHOD_EMIT now
- /*
- if (!((this_ptr->method).compare(Message::METHOD_EMIT))) {
- this_ptr->emit(this_ptr->eventType, (this_ptr->data).c_str(),
- this_ptr->from, this_ptr->Payload);
- break;
- }
- */
- if (this_ptr->eventType == CONNECT_EVENT) {
- this_ptr->handleConnectMessage(this_ptr->UID);
- } else {
- // this_ptr->handleMessage(this_ptr->UID);
- this_ptr->handleMessage(this_ptr->UID, NULL);
- }
- }
-
- dlog_print(DLOG_INFO, "MSF", "Socket receive end ");
- break;
-
- case LWS_CALLBACK_CLIENT_WRITEABLE:
- if (this_ptr->isWrite) {
- this_ptr->isWrite = false;
-
- if (&(this_ptr->buf[LWS_SEND_BUFFER_PRE_PADDING]) == NULL ||
- this_ptr->buf[LWS_SEND_BUFFER_PRE_PADDING] == 0 ||
- this_ptr->buf[LWS_SEND_BUFFER_PRE_PADDING] == '\0') {
- printf("\ntry write NULL data");
- fflush(stdout);
- } else {
- // printf("\ntry write data = %s",
- // &(this_ptr->buf[LWS_SEND_BUFFER_PRE_PADDING]));
- // printf("\ndata size = %d", this_ptr->buflen);
- fflush(stdout);
- }
-
- if (this_ptr->buflen <= 0) {
- printf("\ntry write 0 size data");
- fflush(stdout);
- }
-
- // printf("\nwrite socket");
- // fflush(stdout);
- if (this_ptr->binary_message) {
- n = lws_write(wsi,
- &(this_ptr->buf[LWS_SEND_BUFFER_PRE_PADDING]),
- this_ptr->buflen, LWS_WRITE_BINARY);
- } else {
- n = lws_write(wsi,
- &(this_ptr->buf[LWS_SEND_BUFFER_PRE_PADDING]),
- this_ptr->buflen, LWS_WRITE_TEXT);
- }
-
- if (n < 0) {
- MSF_DBG("Writing failed\n");
- dlog_print(DLOG_ERROR, "MSF", "socket write failed");
- printf("\nwrite socket failed");
- printf("\ncallback isWrite=false");
- fflush(stdout);
- return -1;
- }
- }
- lws_callback_on_writable(wsi);
- break;
-
- case LWS_CALLBACK_RECEIVE:
- dlog_print(DLOG_INFO, "MSF_SOCKET", "socket LWS_CALLBACK_RECEIVE %d",
- reason);
- break;
-
- case LWS_CALLBACK_PROTOCOL_DESTROY:
- dlog_print(DLOG_INFO, "MSF_SOCKET",
- "socket LWS_CALLBACK_PROTOCOL_DESTROY %d", reason);
- break;
-
- case LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED:
- case LWS_CALLBACK_ADD_POLL_FD:
- case LWS_CALLBACK_DEL_POLL_FD:
- case LWS_CALLBACK_CONFIRM_EXTENSION_OKAY:
- case LWS_CALLBACK_CLIENT_RECEIVE_PONG:
- case LWS_CALLBACK_HTTP:
- case LWS_CALLBACK_HTTP_WRITEABLE:
- case LWS_CALLBACK_HTTP_FILE_COMPLETION:
- case LWS_CALLBACK_SERVER_WRITEABLE:
- case LWS_CALLBACK_FILTER_NETWORK_CONNECTION:
- case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION:
- case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS:
- case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER:
- case LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION:
- case LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH:
- break;
-
- default:
- break;
- }
-
- return 0;
-}
-
-Client Channel::getclient(string id) { return clients->get(id); }
-
-bool Channel::isConnected() { return isWebSocketOpen(); }
-
-bool Channel::isWebSocketOpen() { return wsi_mirror == NULL ? false : true; }
-
-string Channel::getChannelUri(map<string, string> *attributes) {
- return service->getUri();
-}
-
-void Channel::publish(string event, const char *data) {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- string to = "\"";
- to.append(Message::TARGET_ALL.c_str());
- to.append("\"");
-
- publishMessage(event, data, to.c_str(), NULL, 0);
-}
-
-void Channel::publish(string event, const char *data, unsigned char payload[],
- int payload_size) {
- dlog_print(DLOG_INFO, "MSF", "publishMessage");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
-
- string to = "\"";
- to.append(Message::TARGET_ALL.c_str());
- to.append("\"");
- publishMessage(event, data, to.c_str(), payload, payload_size);
-}
-
-void Channel::publish(string event, const char *data, const char *target) {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
-
- string to = "\"";
- to.append(target);
- to.append("\"");
- publishMessage(event, data, to.c_str(), NULL, 0);
-}
-
-void Channel::publish(string event, const char *data, const char *target,
- unsigned char payload[], int payload_size) {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
-
- string to = "\"";
- to.append(target);
- to.append("\"");
- publishMessage(event, data, to.c_str(), payload, payload_size);
-}
-
-void Channel::publish(string event, const char *data, Client client) {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
-
- string to = "\"";
- to.append(client.getId());
- to.append("\"");
- publishMessage(event, data, to.c_str(), NULL, 0);
-}
-
-void Channel::publish(string event, const char *data, Client client,
- unsigned char payload[], int payload_size) {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
-
- string to = "\"";
- to.append(client.getId());
- to.append("\"");
- publishMessage(event, data, to.c_str(), payload, payload_size);
-}
-
-void Channel::publish(string event, const char *data, list<Client> clients) {
- publish(event, data, clients, NULL, 0);
-}
-
-void Channel::publish(string event, const char *data, list<Client> clients,
- unsigned char payload[], int payload_size) {
- string to = "[";
-
- std::list<Client>::iterator iterator;
- for (iterator = clients.begin(); iterator != clients.end(); ++iterator) {
- to.append("\"");
- to.append(iterator->getId());
- to.append("\"");
-
- if (std::next(iterator, 1) != clients.end()) {
- to.append(",");
- } else {
- to.append("]");
- }
- }
-
- // TODO
- publishMessage(event, data, to.c_str(), payload, payload_size);
-}
-
-void Channel::publishMessage(string event, const char *data, const char *to,
- unsigned char payload[], int payload_size) {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
-
- publishMessage(Message::METHOD_EMIT, event, data, to, payload,
- payload_size);
-}
-
-void Channel::publishMessage(string method, string event, const char *data,
- const char *to, unsigned char payload[],
- int payload_size) {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
-
- if (!isWebSocketOpen()) {
- handleError(string(), Error::create("Not Connected"));
- return;
- } else {
- // int l=0;
- // l += sprintf((char *)&buf[LWS_SEND_BUFFER_PRE_PADDING]," {\n
- // \"method\": \"%s\",\n \"params\": {\n \"event\": \"%s\",\n \"data\":
- // \"%s\",\n \"to\": \"%s\"\n }\n}",method.c_str(),event.c_str(),
- // (unsigned char*)data, (unsigned char*)to);
-
- // unsigned char *bufer=new char[LWS_SEND_BUFFER_PRE_PADDING + 4096
- // +LWS_SEND_BUFFER_POST_PADDING];
- // bufer=prepareMessageMap(method,event,data,to);
-
- long prepare_buf_len = 0;
- unsigned char *prepare_buf = prepareMessageMap(
- method, event, data, to, &prepare_buf_len, payload, payload_size);
-
- memcpy(&buf[LWS_SEND_BUFFER_PRE_PADDING],
- &prepare_buf[LWS_SEND_BUFFER_PRE_PADDING], prepare_buf_len);
-
- buf[LWS_SEND_BUFFER_PRE_PADDING + prepare_buf_len] = 0;
-
- buflen = prepare_buf_len;
- // buf code
- // for(int i=0; i<buflen;i++)
- // buf[i]=prepare_buf[i];
-
- // buf[buflen] = 0;
-
- delete[](prepare_buf);
-
- MSF_DBG("buf is = %s %d \n", &buf[LWS_SEND_BUFFER_PRE_PADDING], buflen);
- // buflen=l;
- // messagedata=((char*)data);
-
- if (binary_message) {
- dlog_print(DLOG_INFO, "MSF", "publish buffer = %s",
- &buf[LWS_SEND_BUFFER_PRE_PADDING + 2]);
- } else {
- dlog_print(DLOG_INFO, "MSF", "publish buffer = %s",
- &buf[LWS_SEND_BUFFER_PRE_PADDING]);
- }
-
- // if (bufer)
- // free(bufer);
-
- isWrite = true;
- // printf("\npublish isWrite=true\n");
- }
-}
-
-unsigned char *Channel::prepareMessageMap(string method, string event,
- const char *data, const char *to,
- long *prepare_buf_len,
- unsigned char payload[],
- int payload_size) {
- int l = 0;
- int header_size = 0;
-
- int prepare_buf_size = LWS_SEND_BUFFER_PRE_PADDING + 4096 + LWS_SEND_BUFFER_POST_PADDING;
- unsigned char *prepare_buf = new unsigned char[prepare_buf_size];
-
- if (payload) {
- l += snprintf((char *)&prepare_buf[LWS_SEND_BUFFER_PRE_PADDING + 2],
- prepare_buf_size - (LWS_SEND_BUFFER_PRE_PADDING + 2),
- "{\n \"method\": \"%s\",\n \"params\": {\n \"event\": "
- "\"%s\",\n \"data\": \"%s\",\n \"to\": %s\n }\n}",
- method.c_str(), event.c_str(), (unsigned char *)data,
- (unsigned char *)to);
-
- header_size = l;
-
- prepare_buf[LWS_SEND_BUFFER_PRE_PADDING + 1] =
- (unsigned char)header_size;
- prepare_buf[LWS_SEND_BUFFER_PRE_PADDING] =
- (unsigned char)((header_size) >> 8);
-
- dlog_print(DLOG_INFO, "MSF", "publish header size = %d", header_size);
- dlog_print(DLOG_INFO, "MSF", "buf[1] = %d",
- (char)prepare_buf[LWS_SEND_BUFFER_PRE_PADDING + 1]);
- dlog_print(DLOG_INFO, "MSF", "buf[0] = %d",
- (char)prepare_buf[LWS_SEND_BUFFER_PRE_PADDING]);
-
- l += 2;
-
- memcpy(&prepare_buf[LWS_SEND_BUFFER_PRE_PADDING + l], payload,
- payload_size);
-
- l += payload_size;
-
- binary_message = true;
- } else {
- l += snprintf((char *)&prepare_buf[LWS_SEND_BUFFER_PRE_PADDING],
- prepare_buf_size - LWS_SEND_BUFFER_PRE_PADDING,
- "{\n \"method\": \"%s\",\n \"params\": {\n \"event\": "
- "\"%s\",\n \"data\": \"%s\",\n \"to\": %s\n }\n}",
- method.c_str(), event.c_str(), (unsigned char *)data,
- (unsigned char *)to);
- binary_message = false;
- }
- MSF_DBG("buf is = %s %d \n", &buf[LWS_SEND_BUFFER_PRE_PADDING], l);
-
- *prepare_buf_len = l;
- return prepare_buf;
-}
-
-void Channel::handleBinaryMessage(unsigned char payload[]) {}
-
-void Channel::start_app(char *data, int buflength, string msgID) {
- dlog_print(DLOG_INFO, "MSF", "start_app() buf = %s", data);
- UID = msgID;
- int l = 0;
-
- l += snprintf((char *)&buf[LWS_SEND_BUFFER_PRE_PADDING], sizeof(buf) - LWS_SEND_BUFFER_PRE_PADDING, data);
- MSF_DBG("buf is = %s %d \n", &buf[LWS_SEND_BUFFER_PRE_PADDING], l);
- buflen = l;
- buf[LWS_SEND_BUFFER_PRE_PADDING + l] = 0;
-
- dlog_print(DLOG_INFO, "MSF", "start_app() buf = %s",
- &buf[LWS_SEND_BUFFER_PRE_PADDING]);
- binary_message = false;
-
- isWrite = true;
- printf("start_app isWrite=true");
-
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
-}
-
-void Channel::registerCallback(string uid, void *callback, int value_type) {
- dlog_print(DLOG_INFO, "MSF", "registerCallback uid = %s value_type = %d",
- uid.c_str(), value_type);
- callbacks[uid] = make_pair(callback, value_type);
-}
-
-void Channel::release_callback(string uid) { callbacks.erase(uid); }
-
-pair<void *, int> Channel::getcallback(string uid) {
- map<string, pair<void *, int>>::iterator check_it = callbacks.find(uid);
-
- if (check_it == callbacks.end()) {
- dlog_print(DLOG_ERROR, "MSF",
- "callbacks map not found. critical error");
- return pair<void *, int>();
- }
-
- if (uid.length() != 0) {
- pair<void *, int> r1 = callbacks[uid];
-
- callbacks.erase(uid);
-
- dlog_print(DLOG_INFO, "MSF", "getcallback success uid = %s",
- uid.c_str());
- return r1;
- }
-
- dlog_print(DLOG_INFO, "MSF", "getcallback failed", uid.c_str());
- return pair<void *, int>();
-}
-
-string Channel::getUID() {
- std::stringstream ss;
- unsigned int seed = time(NULL);
- ss << (rand_r(&seed) % 9000 + 1000);
- string randID = ss.str();
- return randID;
-}
-
-void *Channel::pt_startConnect(void *att) {
- map<Channel *, map<string, string> *> *pt_user_data =
- static_cast<map<Channel *, map<string, string> *> *>(att);
- map<string, string> *attributes = pt_user_data->begin()->second;
-
- pt_user_data->begin()->first->create_websocket(attributes);
-
- delete attributes;
- delete pt_user_data;
-
- return NULL;
-}
-
-void Channel::create_websocket(void *att) {
- struct lws_protocols protocols[] = {
- {"lws-mirror-protocol", Channel::callback_lws_mirror, sizeof(int), 0, 0,
- NULL},
-
- // libwebsockets 1.7 has a bug.
- {NULL, NULL, 0, 0, 0, NULL} // this is anti-bug code
- };
-
- int port = 8001;
- int use_ssl = 0;
- int n = 0;
- // int ret = 0;
- map<string, string> *attributes = (map<string, string> *)(att);
- string uri = getChannelUri(attributes);
-
- was_closed = 0;
- struct lws_context *context;
-
- int ietf_version = -1; /* latest */
-
- struct lws_context_creation_info info;
-
- memset(&info, 0, sizeof info);
-
- info.port = CONTEXT_PORT_NO_LISTEN;
- info.protocols = protocols;
- info.extensions = NULL;
- info.ssl_cert_filepath = NULL;
- info.ssl_private_key_filepath = NULL;
- info.gid = -1;
- info.uid = -1;
- info.options = 0;
- info.user = this;
-
-#ifndef LWS_NO_EXTENSIONS
-// info.extensions = lws_get_internal_extensions();
-#endif
-
- if (isWebSocketOpen()) {
- MSF_DBG("\nAlready Connected");
- dlog_print(DLOG_INFO, "MSF", "create_websocket already Connected");
- // return 0;
- }
- context = lws_create_context(&info);
- Context = context;
- if (context == NULL) {
- MSF_DBG("Creating libwebsocket context failed\n");
- dlog_print(DLOG_ERROR, "MSF", "create_websocket context failed");
- // return 1;
- }
- n = 0;
- string address = getipaddressfromUri(uri);
- string api = getapifromUri(uri);
- api.append("channels/").append(ChannelID);
-
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
-
- struct lws_client_connect_info connect_info;
- connect_info.context = context;
- connect_info.address = address.c_str();
- connect_info.port = port;
- connect_info.ssl_connection = use_ssl;
- connect_info.path = api.c_str();
- connect_info.host = address.c_str();
- connect_info.origin = address.c_str();
- connect_info.protocol = protocols[0].name;
- connect_info.ietf_version_or_minus_one = ietf_version;
- connect_info.userdata = NULL;
- connect_info.client_exts = NULL;
-
- // loop until socket closed
- while (n >= 0 && !was_closed) {
- n = lws_service(context, 500);
- if (n < 0)
- continue;
- if (wsi_mirror)
- continue;
- if (was_closed)
- goto bail;
- MSF_DBG("Creating wsi_mirror [%s] [%d]\n", __FUNCTION__, __LINE__);
- // wsi_mirror = lws_client_connect_via_info(context, address.c_str(),
- // port, use_ssl, api.c_str(),address.c_str(),address.c_str(),
- // protocols[0].name, ietf_version);
- wsi_mirror = lws_client_connect_via_info(&connect_info);
- if (wsi_mirror == NULL) {
- MSF_DBG("Fail to create was_mirror[%s] [%d]\n", __FUNCTION__,
- __LINE__);
- dlog_print(DLOG_ERROR, "MSF", "create_websocket create wsi failed");
- handleError(UID, Error::create("ConnectFailed"));
- // ret = 1;
- goto bail;
- }
- }
-// return 0;
-bail:
- dlog_print(DLOG_INFO, "MSF", "create_websocket destroy context");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- if (context)
- lws_context_destroy(context);
- context = NULL;
- wsi_mirror = NULL;
-}
-
-string Channel::getipaddressfromUri(string uri) {
- string startpt = "http://";
- const char *src = strstr(uri.c_str(), startpt.c_str());
- int startpoint = (src - uri.c_str()) + sizeof(startpt);
-
- std::string endpt = ":8001";
- const char *dest = strstr(src, endpt.c_str());
- int endpoint = (dest - uri.c_str());
- std::string address =
- uri.substr((startpoint + sizeof(startpt) - 1),
- (endpoint - startpoint + 1 - sizeof(startpt)));
- return address;
-}
-
-string Channel::getapifromUri(string uri) {
- string startpt = "/api";
- const char *api = strstr(uri.c_str(), startpt.c_str());
- return api;
-}
-void Channel::setonConnectListener(OnConnectListener *obj) {
- onConnectListener = obj;
-}
-
-void Channel::unsetonConnectListener() { onConnectListener = NULL; }
-
-void Channel::setonDisconnectListener(OnDisconnectListener *obj) {
- onDisconnectListener = obj;
-}
-
-void Channel::unsetonDisconnectListener() { onDisconnectListener = NULL; }
-void Channel::setonClientConnectListener(OnClientConnectListener *obj) {
- onClientConnectListener = obj;
-}
-
-void Channel::unsetonClientConnectListener() { onClientConnectListener = NULL; }
-
-/*
- void Channel::setmessageListeners(list<OnMessageListener>
- onMessageListenerlist){
- std::list<OnMessageListener>::const_iterator iterator;
- std::list<OnMessageListener>::const_iterator it;
- for (iterator = onMessageListenerlist.begin(),it =onMessageListeners.begin();
- iterator != onMessageListenerlist.end(); ++iterator,++it)
- {
- it=iterator;
- }
-
- }
- }
- */
-
-void Channel::addOnMessageListener(string event,
- OnMessageListener *onMessageListener) {
- if (event.length() == 0 || onMessageListener == NULL)
- return;
-
- if (messageListeners.find(event) == messageListeners.end()) {
- messageListeners.insert({event, list<OnMessageListener *>()});
- }
-
- list<OnMessageListener *> &onMessageListeners =
- (messageListeners.find(event))->second;
-
- onMessageListeners.push_back(onMessageListener);
-}
-
-void Channel::addOnAllMessageListener(OnMessageListener *onMessageListener) {
- everyMessageListener = onMessageListener;
-}
-
-void Channel::removeAllMessageListener() { everyMessageListener = NULL; }
-
-void Channel::removeOnMessageListeners(string event) {
- if (event.length() == 0)
- return;
-
- if (messageListeners.find(event) == messageListeners.end()) {
- return;
- }
-
- list<OnMessageListener *> &onMessageListeners =
- (messageListeners.find(event))->second;
- onMessageListeners.clear();
-}
-
-void Channel::removeOnMessageListener(string event,
- OnMessageListener *onMessageListener) {
- if ((event.length() == 0) || (onMessageListener != NULL))
- return;
-
- if (messageListeners.find(event) == messageListeners.end()) {
- return;
- }
-
- list<OnMessageListener *> &onMessageListeners =
- (messageListeners.find(event))->second;
-
- if (onMessageListeners.size() != 0) {
- onMessageListeners.remove(onMessageListener);
- }
-}
-
-void Channel::removeOnMessageListeners() { messageListeners.clear(); }
-
-void Channel::removeAllListeners() {
- setonConnectListener(NULL);
- setonDisconnectListener(NULL);
- setonClientConnectListener(NULL);
- setonClientDisconnectListener(NULL);
- setonReadyListener(NULL);
- setonErrorListener(NULL);
- removeOnMessageListeners();
-}
-
-void Channel::register_message_receive_cb(_message_receive_cb cb) {
- message_receive_cb = cb;
-}
-
-void Channel::setonClientDisconnectListener(OnClientDisconnectListener *obj) {
- onClientDisconnectListener = obj;
-}
-
-void Channel::unsetonClientDisconnectListener() {
- onClientDisconnectListener = NULL;
-}
-
-void Channel::setonErrorListener(OnErrorListener *obj) {
- onErrorListener = obj;
-}
-
-void Channel::unsetonErrorListener() { onErrorListener = NULL; }
-
-void Channel::setonReadyListener(OnReadyListener *obj) {
- onReadyListener = obj;
-}
-
-void Channel::unsetonReadyListener() { onReadyListener = NULL; }
-
-void Channel::set_isWrite(bool flag) {}
-
-void ChannelConnectionHandler::resetLastPingReceived() {
- this->lastPingReceived = time(0);
-}
-
-void ChannelConnectionHandler::calculateAverageRT() {
- long lastRT = lastPingReceived - pingSent;
- if (lastRT > longestRT) {
- longestRT = lastRT;
- }
- // average=((numPings++ * average)+lastRT)/numPings; //will check ankit
-}
-
-void ChannelConnectionHandler::stopPing() {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- if (ping_thread != 0) {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in "
- "file [%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- pthread_cancel(ping_thread);
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in "
- "file [%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- pthread_join(ping_thread, NULL);
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in "
- "file [%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- running = false;
- ping_thread = 0;
- printf("ping thread close");
- fflush(stdout);
- }
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
-}
-
-void ChannelConnectionHandler::startPing(Channel *ptr) {
- dlog_print(DLOG_INFO, "MSF", "## startPing ###");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- if (running) {
- dlog_print(DLOG_INFO, "MSF",
- "## startPing already running. return ###");
- return;
- }
- stopPing();
- if (pingTimeout <= 0) {
- dlog_print(DLOG_INFO, "MSF", "## startPing ping timeout. return ###");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in "
- "file [%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- return;
- }
- running = true;
- numPings = 0;
- average = 0;
- longestRT = 0;
- startTime = time(0);
- pingSent = startTime;
- channel_ptr = ptr;
-
- int err = pthread_create(&ping_thread, NULL, Pinging, ptr);
- if (err) {
- dlog_print(DLOG_INFO, "MSF", "pthread_create failed err = %d", err);
- }
- // Need to check this
- // Pinging(ptr);
-}
-
-void ChannelConnectionHandler::ping_again(void *arg) {
- dlog_print(DLOG_INFO, "MSF", "## ping again ###");
- Channel *ptr = static_cast<Channel *>(arg);
- long now = time(0);
-
- if (now > ptr->connectionHandler->lastPingReceived +
- ptr->connectionHandler->pingTimeout) {
- dlog_print(DLOG_INFO, "MSF", "## Pinging timeout. disconnect ###");
- ptr->disconnect();
- } else {
- ptr->publish("msfVersion2", "msfVersion2", ptr->clients->me());
- sleep(1);
- ptr->publish(PING, PONG.c_str(), ptr->clients->me());
- ptr->connectionHandler->pingSent = time(0);
- }
-}
-
-void *ChannelConnectionHandler::Pinging(void *arg) {
- dlog_print(DLOG_INFO, "MSF", "## Pinging ###");
-
- Channel *ptr = static_cast<Channel *>(arg);
-
- while (1) {
- ping_again(ptr);
- dlog_print(DLOG_INFO, "MSF", "## pinging 1 ###");
- // usleep(ptr->connectionHandler->pingTimeout);
- sleep(5);
- }
-}
-
-void ChannelConnectionHandler::setPingTimeout(long t) {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file "
- "[%s] \n",
- __FUNCTION__, __LINE__, __FILE__);
- pingTimeout = t;
-}
-
-void Channel::set_connect_result(Result_Base *r) { connect_cb = r; }
-
-void Channel::unset_connect_result() { connect_cb = NULL; }
-
-void Channel::set_disconnect_result(Result_Base *r) { disconnect_cb = r; }
-
-void Channel::unset_disconnect_result() { disconnect_cb = NULL; }
+++ /dev/null
-#include "Channel.h"
-#include"Client.h"
-
-string Client::ID_KEY = "id";
-string Client::IS_HOST_KEY = "isHost";
-string Client::CONNECT_TIME_KEY = "connectTime";
-string Client::ATTRIBUTES_KEY = "attributes";
-
-Client::Client()
-{
- id = string();
- host = false ;
- connectTime = 0;
-}
-
-void Client::create(Client &client)
-{
- id = client.id;
- host = client.host ;
- connectTime = client.connectTime;
-}
-
-void Client::create(Channel *channel, string Id, long long ConnectTime, /*map<string, string> data,*/ bool Host, map<string, string> attr)
-{
- id = Id;
- host = Host;
- connectTime = ConnectTime;
- attributes = attr;
- m_channel = channel;
- //return client;
-}
-
-bool Client::isHost()
-{
- return host;
-}
-
-const char *Client::getId()
-{
- return id.c_str();
-}
-
-long long Client::getConnectTime()
-{
- return connectTime;
-}
-map<string, string> Client::getAttributesKey()
-{
- return attributes;
-}
-
-Channel *Client::getChannel()
-{
- return m_channel;
-}
-
+++ /dev/null
-#include"Clients.h"
-
-Clients::Clients()
-{
- host = NULL;
- m_channel = NULL;
-}
-
-Clients::Clients(Channel *channel)
-{
- host = NULL;
- m_channel = channel;
-}
-
-Client Clients::get(string clientId)
-{
- Client cl = clients.find(clientId)->second;
- return cl;
-}
-
-Client* Clients::getHost()
-{
- if (host == NULL) {
- std::vector<Client> clients;
- for (std::vector<Client>::iterator it = clients.begin() ; it != clients.end(); ++it) {
- if ((*it).isHost()) {
- host = new Client();
- host->create(*it);
- }
- }
- }
- return host;
-}
-
-Client Clients::me(void)
-{
- if (myClientId != "") {
- Client client = get(myClientId);
- if ((&client != NULL) && !(client.getId() == varme.getId())) {
- varme = client;
- }
- }
- return varme;
-}
-
-bool Clients::isMe(Client client)
-{
- return (client.getId()== myClientId);
-}
-
-/*int Clients::ssize()
- {
- return sizeof(clients);
- }*/
-
-list<Client> Clients::lists()
-{
- list<Client> client_list;
- std::map<string, Client>::iterator clients_itr;
-
- for (clients_itr = clients.begin(); clients_itr != clients.end(); clients_itr++) {
- client_list.push_back(clients_itr->second);
- }
-
- return client_list;
-}
-
-void Clients::setMyClientId(string clientId)
-{
- myClientId = clientId;
- Client client = get(myClientId);
- varme = client;
-}
-
-void Clients::reset()
-{
- clients.clear();
- if (host != NULL)
- delete host;
- host = NULL;
- myClientId = "";
-}
-
-void Clients::add(list <Client> clientList)
-{
- std::list<Client>::const_iterator iterator;
- for (iterator = clientList.begin(); iterator != clientList.end(); ++iterator) {
- add(*iterator);
- }
-}
-
-void Clients::add(Client client)
-{
- clients.insert({string(client.getId()), client});
-}
-
-int Clients::size()
-{
- return clients.size();
-}
-
-void Clients::remove(Client client)
-{
- clients.erase(client.getId());
-}
-
-Channel* Clients::getChannel()
-{
- return m_channel;
-}
+++ /dev/null
-#include "Device.h"
-
-string Device::DUID_KEY = "duid";
-string Device::MODEL_KEY = "model";
-string Device::MODELNAME_KEY = "modelName";
-string Device::DESCRIPTION_KEY = "description";
-string Device::NETWORK_TYPE_KEY = "networkType";
-string Device::SSID_KEY = "ssid";
-string Device::IP_KEY = "ip";
-string Device::FIRMWARE_VERSION_KEY = "firmwareVersion";
-string Device::NAME_KEY = "name";
-string Device::ID_KEY = "id";
-string Device::UDN_KEY = "udn";
-string Device::RESOLUTION_KEY = "resolution";
-string Device::COUNTRY_CODE_KEY = "countryCode";
-string Device::TYPE = "type";
-string Device::MSF_VERSION = "msfVersion";
-string Device::SMARTHUB_AGREEMENT = "smartHubAgreement";
-string Device::WIFIMAC = "wifiMac";
-string Device::DEVELOPER_MODE = "developerMode";
-string Device::DEVELOPER_IP = "developerIP";
-string Device::OS = "OS";
-
-void Device::foreach_json_object(JsonObject *object, const gchar *key, JsonNode *node, gpointer user_data)
-{
- Device *p = static_cast<Device*>(user_data);
-
- if (json_node_get_node_type(node) == JSON_NODE_VALUE) {
- if (!strncmp(key , Device::DUID_KEY.c_str(), 4)) {
- p->duid = json_node_get_string(node);
- } else if (!strncmp(key, Device::MODELNAME_KEY.c_str(), 9)) {
- } else if (!strncmp(key, Device::MODEL_KEY.c_str(), 5)) {
- p->model = json_node_get_string(node);
- } else if (!strncmp(key, Device::DESCRIPTION_KEY.c_str(), 11)) {
- p->description = json_node_get_string(node);
- } else if (!strncmp(key, Device::NETWORK_TYPE_KEY.c_str(), 11)) {
- p->networkType = json_node_get_string(node);
- } else if (!strncmp(key, Device::SSID_KEY.c_str(), 4)) {
- p->ssid = json_node_get_string(node);
- } else if (!strncmp(key, Device::IP_KEY.c_str(), 2)) {
- p->ip = json_node_get_string(node);
- } else if (!strncmp(key, Device::FIRMWARE_VERSION_KEY.c_str(), 15)) {
- p->firmwareVersion = json_node_get_string(node);
- } else if (!strncmp(key, Device::NAME_KEY.c_str(), 4)) {
- p->name = json_node_get_string(node);
- } else if (!strncmp(key, Device::ID_KEY.c_str(), 2)) {
- p->id = json_node_get_string(node);
- } else if (!strncmp(key, Device::UDN_KEY.c_str(), 3)) {
- p->udn = json_node_get_string(node);
- } else if (!strncmp(key, Device::RESOLUTION_KEY.c_str(), 9)) {
- p->resolution = json_node_get_string(node);
- } else if (!strncmp(key, Device::COUNTRY_CODE_KEY.c_str(), 11)) {
- p->countryCode = json_node_get_string(node);
- } else if (!strncmp(key, "running", 7)) {
- //running = json_object_get_boolean(val);
- }
- } else if (json_node_get_node_type(node) == JSON_NODE_OBJECT) {
- json_object_foreach_member(json_node_get_object(node), foreach_json_object, user_data);
- }
-}
-
-
-void Device::json_parse(JsonNode *node)
-{
- if (json_node_get_node_type(node) == JSON_NODE_OBJECT) {
- json_object_foreach_member(json_node_get_object(node), foreach_json_object, this);
- }
-}
-
-Device::Device()
-{
-}
-
-Device::Device(JsonNode *node)
-{
- json_parse(node);
-}
-
-string Device::getduid()
-{
- return duid ;
-}
-
-string Device:: getmodel()
-{
- return model;
-}
-
-string Device::getdescription()
-{
- return description;
-}
-
-string Device::getnetworkType()
-{
- return networkType;
-}
-
-string Device::getssid()
-{
- return ssid;
-}
-
-string Device::getip()
-{
- return ip;
-}
-
-string Device::getfirmwareVersion()
-{
- return firmwareVersion;
-}
-
-string Device::getudn()
-{
- return udn;
-}
-
-string Device::getresolution()
-{
- return resolution;
-}
-
-string Device::getcountryCode()
-{
- return countryCode;
-}
-
-string Device::getname()
-{
- return name;
-}
-
-string Device::getid()
-{
- return id;
-}
-
-Device Device::create(JsonNode *node)
-{
- Device device = Device(node);
- return device;
-}
+++ /dev/null
-#include"Error.h"
-
-Error::Error()
-{
-}
-
-Error::Error(long code, string name, string message)
-{
- this->code = code;
- this->name = name;
- this->message = message;
-}
-
-Error Error::create(string message)
-{
- return create(-1, "error", message);
-}
-
-Error Error::create(long code, string name, string message)
-{
- if ((name == "") || (message == "")) {
- name = "error";
- }
-
- Error *error = new Error(code, name, message);
- return *error;
-}
-const char *Error::get_error_message()
-{
- return message.c_str();
-}
+++ /dev/null
-#include <ctime>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-#include "MSFDSearchProvider.h"
-#include "Service.h"
-#include "Debug.h"
-#include "Error.h"
-#include "Result.h"
-#define MSGBUFSIZE 1000
-#define MULTICAST_PORT 8001
-#define MULTICAST_GROUP "224.0.0.7"
-
-string MSFDSearchProvider::KEY_TYPE_STATE = "type";
-string MSFDSearchProvider::KEY_TTL = "ttl";
-string MSFDSearchProvider::KEY_SID = "sid";
-string MSFDSearchProvider::KEY_DATA = "data";
-string MSFDSearchProvider::KEY_VERSION_1 = "v1";
-string MSFDSearchProvider::KEY_VERSION_2 = "v2";
-string MSFDSearchProvider::KEY_URI = "uri";
-string MSFDSearchProvider::TYPE_DISCOVER = "discover";
-string MSFDSearchProvider::STATE_UP = "up";
-string MSFDSearchProvider::STATE_DOWN = "down";
-string MSFDSearchProvider::STATE_ALIVE = "alive";
-int MSFDSearchProvider::SERVICE_CHECK_TIMEOUT = 5000;
-
-int MSFDSearchProvider::flag = 0;
-
-MSFDSearchProvider::MSFDSearchProvider()
-{
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- SearchProvider();
-}
-
-MSFDSearchProvider::MSFDSearchProvider(Search *sListener):SearchProvider(sListener)
-{
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-}
-
-SearchProvider MSFDSearchProvider::create()
-{
- return (SearchProvider)MSFDSearchProvider();
-}
-
-SearchProvider MSFDSearchProvider::create(Search *searchListener)
-{
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- return (SearchProvider)MSFDSearchProvider(searchListener);
-}
-
-void MSFDSearchProvider::start()
-{
- dlog_print(DLOG_INFO, "MSF", "MSFD start()");
- if (searching) {
- stop();
- }
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- clearServices();
-
- aliveMap.clear();
- receive = false;
- createMSFD();
-}
-
-void MSFDSearchProvider::createMSFD()
-{
- struct sockaddr_in addr;
- struct sockaddr_in msf_server_addr;
- int nbytes;
- unsigned int addrlen;
- struct ip_mreq mreq;
- char msgbuf[MSGBUFSIZE];
- fd = 0;
- u_int yes = 1; /*** MODIFICATION TO ORIGINAL */
-
- /* create what looks like an ordinary UDP socket */
- if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- perror("socket");
- dlog_print(DLOG_ERROR, "MSF", "MSFD socket faile");
- return;
- }
-
- /**** MODIFICATION TO ORIGINAL */
- /* allow multiple sockets to use the same PORT number */
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
- perror("Reusing ADDR failed");
- dlog_print(DLOG_ERROR, "MSF", "MSFD reusing ADDR failed");
- }
- /*** END OF MODIFICATION TO ORIGINAL */
-
- /* set up destination address */
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = htonl(INADDR_ANY); /* N.B.: differs from sender */
- addr.sin_port = htons(MULTICAST_PORT);
-
- dlog_print(DLOG_INFO, "MSF", "MSFD try bind socket");
- /* bind to receive address */
- if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- perror("bind");
- dlog_print(DLOG_ERROR, "MSF", "MSFD bind failed");
- }
- dlog_print(DLOG_INFO, "MSF", "MSFD try bind socket success");
-
- /* use setsockopt() to request that the kernel join a multicast group */
- mreq.imr_multiaddr.s_addr = inet_addr(MULTICAST_GROUP);
- mreq.imr_interface.s_addr = htonl(INADDR_ANY);
- if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
- perror("setsockopt");
- dlog_print(DLOG_ERROR, "MSF", "MSFD setsockopt failed");
- }
-
- struct timeval tv = {2, 0};
-
- if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
- perror("setsockopt");
- dlog_print(DLOG_ERROR, "MSF", "MSFD setsockopt(SOL_SOCKET) failed");
- }
-
- while (1) {
- addrlen = sizeof(msf_server_addr);
-
- dlog_print(DLOG_INFO, "MSF", "MSFD waiting packet");
- if ((nbytes = recvfrom(fd, msgbuf, MSGBUFSIZE, 0, (struct sockaddr *) &msf_server_addr, &addrlen)) < 0) {
- //dlog_print(DLOG_INFO, "MSF", "MSFD packet < 0");
- receive = false;
- dlog_print(DLOG_INFO, "MSF", "MSFD packet not received");
- reapServices();
- } else {
- msgbuf[nbytes] = '\0';
- dlog_print(DLOG_INFO, "MSF", "MSFD packet = %s", msgbuf);
- receive = true;
- processReceivedMsg(msgbuf, nbytes);
- }
- }
-}
-
-void MSFDSearchProvider::reapServices()
-{
- dlog_print(DLOG_ERROR, "MSF", "MSFD reapServices");
- long now = time(0);
- map<string, long>::iterator it;
- for(it = aliveMap.begin(); it != aliveMap.end(); ++it) {
- long expires = it->second;
- if (expires < now) {
- dlog_print(DLOG_ERROR, "MSF", "MSFD reapServices remove service");
- Service service = getServiceById(it->first);
- aliveMap.erase(it->first);
- removeServiceAndNotify(service);
- }
- }
-}
-
-void MSFDSearchProvider::updateAlive(string id, long ttl)
-{
- long now = time(0);
- ttl = ttl/1000;
- long expires = now+ttl;
- aliveMap[id] = expires;
-}
-
-void MSFDSearchProvider::processReceivedMsg(char *buf, int buflen)
-{
- dlog_print(DLOG_INFO, "MSF", "MSFD processReceivedMsg start");
- if (buf != NULL) {
- }
-
- while(receive) {
- dlog_print(DLOG_INFO, "MSF", "MSFD processReceivedMsg 1");
- reapServices();
- dlog_print(DLOG_INFO, "MSF", "MSFD processReceivedMsg 2");
- string data;
- data.append(buf, buflen);
- json_parse(data.c_str());
-
- dlog_print(DLOG_INFO, "MSF", "MSFD processReceivedMsg after parse");
-
- if (state == TYPE_DISCOVER) {
- dlog_print(DLOG_INFO, "MSF", "MSFD processReceivedMsg state = discover");
- continue;
- }
-
- if (id.length() > 0) {
- dlog_print(DLOG_INFO, "MSF", "MSFD processReceivedMsg id length > 0");
- Service serv = getServiceById(id);
- Service *serv1 = &serv;
-
- if (serv.getId() != "") {
- receive = false;
- }
-
- if (state == STATE_ALIVE || state == STATE_UP) {
- map<string, long>::iterator i = aliveMap.find(id);
- if (((serv.getId()).length() == 0)) {//&&(i==aliveMap.end()))
- updateAlive(id, ttl);
- static map<string, long>* tempaliveMap = &aliveMap;
- static MSFDSearchProvider *MSFDSearchProvider_pointer = this;
- static string tempid = id;
- static long tempttl = ttl;
-
- class ResultMSFDServiceCallback : public Result_Base
- {
- public:
- void onSuccess(Service abc)
- {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- MSFDSearchProvider_pointer->updateAlive(tempid, tempttl);
- //(*tempaliveMap)[tempid]=tempttl;
- MSFDSearchProvider_pointer->addService(abc);
- }
-
- void onError(Error)
- {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- tempaliveMap->erase(tempid);
- //aliveMap.erase(id);
- }
- };
- Result_Base *rService = NULL;
- ResultMSFDServiceCallback *r1Service = new ResultMSFDServiceCallback();
- rService = r1Service;
- Service::getByURI(url, SERVICE_CHECK_TIMEOUT, rService);
-
- // ........ critical bug
- //delete r1Service;
- //r1Service = rService = NULL;
- } else {
- updateAlive(id, ttl);
- }
- } else if ((serv1->getId() != "") && (state == STATE_DOWN)) {
- aliveMap.erase(id);
- removeServiceAndNotify(serv);
- }
- } else {
- receive = false;
- }
- }
- dlog_print(DLOG_INFO, "MSF", "MSFD processReceivedMsg end");
-}
-
-void MSFDSearchProvider::foreach_json_object(JsonObject *object, const gchar *key, JsonNode *node, gpointer user_data)
-{
- MSFDSearchProvider *p = static_cast<MSFDSearchProvider*>(user_data);
-
- if (json_node_get_node_type(node) == JSON_NODE_VALUE) {
- if (!strncmp(key , MSFDSearchProvider::KEY_TTL.c_str(), 2)) {
- p->ttl = json_node_get_int(node);
- dlog_print(DLOG_INFO, "MSF", "MSFD ttl = %d", p->ttl);
- } else if (!strncmp(key , MSFDSearchProvider::KEY_TYPE_STATE.c_str(), 2)) {
- p->state = json_node_get_string(node);
- dlog_print(DLOG_INFO, "MSF", "MSFD state = %s", p->state.c_str());
- } else if (!strncmp(key, MSFDSearchProvider::KEY_SID.c_str(), 4)) {
- p->id = json_node_get_string(node);
- dlog_print(DLOG_INFO, "MSF", "MSFD id = %s", p->id.c_str());
- } else if (!strncmp(key, MSFDSearchProvider::KEY_URI.c_str(), 7)) {
- if (flag == 1) {
- p->url = json_node_get_string(node);
- dlog_print(DLOG_INFO, "MSF", "MSFD url = %s", p->url.c_str());
- flag = 0;
- }
- }
-
- } else if (json_node_get_node_type(node) == JSON_NODE_OBJECT) {
- if (!strncmp(key , KEY_VERSION_2.c_str(), 7)) {
- flag = 1;
- }
- json_object_foreach_member(json_node_get_object(node), foreach_json_object, user_data);
- }
-}
-
-void MSFDSearchProvider::json_parse(const char *in)
-{
- JsonParser *parser = json_parser_new();
-
- if (json_parser_load_from_data(parser, in, -1, NULL)) {
- JsonNode *node = json_parser_get_root(parser);
-
- if (json_node_get_node_type(node) == JSON_NODE_OBJECT) {
- json_object_foreach_member(json_node_get_object(node), foreach_json_object, this);
- }
-
- } else {
- dlog_print(DLOG_ERROR, "MSF", "json_parsing error");
- }
-}
-
-bool MSFDSearchProvider::stop()
-{
- dlog_print(DLOG_INFO, "MSF", "MSFD stop()");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- //if (!searching) {
- // return false;
- //}
- receive = false;
- close(fd);
- return true;
-}
-
+++ /dev/null
-#include <dlog.h>
-#include"Message.h"
-
-string Message::TARGET_BROADCAST = "broadcast";
-string Message::TARGET_ALL = "all";
-string Message::TARGET_HOST = "host";
-
-string Message::METHOD_APPLICATION_GET = "ms.application.get";
-string Message::METHOD_APPLICATION_START = "ms.application.start";
-string Message::METHOD_APPLICATION_STOP = "ms.application.stop";
-string Message::METHOD_APPLICATION_INSTALL = "ms.application.install";
-string Message::METHOD_WEB_APPLICATION_GET = "ms.webapplication.get";
-string Message::METHOD_WEB_APPLICATION_START = "ms.webapplication.start";
-string Message::METHOD_WEB_APPLICATION_STOP = "ms.webapplication.stop";
-string Message::METHOD_EMIT = "ms.channel.emit";
-
-string Message::PROPERTY_MESSAGE = "message";
-string Message::PROPERTY_METHOD = "method";
-string Message::PROPERTY_MESSAGE_ID = "id";
-string Message::PROPERTY_PARAMS = "params";
-string Message::PROPERTY_ID = "id";
-string Message::PROPERTY_URL = "url";
-string Message::PROPERTY_ARGS = "args";
-string Message::PROPERTY_EVENT = "event";
-string Message::PROPERTY_DATA = "data";
-string Message::PROPERTY_TO = "to";
-string Message::PROPERTY_FROM = "from";
-string Message::PROPERTY_CLIENTS = "clients";
-string Message::PROPERTY_RESULT = "result";
-string Message::PROPERTY_ERROR = "error";
-
-Message::Message(Channel *ch, string event, string data, string from, unsigned char *payload, int payload_size)
-{
- m_channel = ch;
- m_event = event;
- m_data = data;
- m_from = from;
- m_payload_size = payload_size;
-
- m_payload = new unsigned char[payload_size+1];
-
- for (int i = 0; i < payload_size; i++) {
- m_payload[i] = payload[i];
- }
-
- m_payload[payload_size] = 0;
-
- dlog_print(DLOG_INFO, "MSF", "Message Test 1");
-}
-
-Message::Message()
-{
-}
-
-Message::~Message()
-{
- delete[] m_payload;
-}
-
-Message::Message(const Message& m)
-{
- m_channel = m.m_channel;
- m_event = m.m_event;
- m_data = m.m_data;
- m_from = m.m_from;
- m_payload_size = m.m_payload_size;
-
- m_payload = new unsigned char[m_payload_size+1];
-
- for (int i = 0; i < m_payload_size; i++) {
- m_payload[i] = m.m_payload[i];
- }
-}
+++ /dev/null
-#include "Result.h"
-#include "ApplicationInfo.h"
-#include "Service.h"
-#include "Client.h"
-#include "Device.h"
-#include "Error.h"
-
-Result_Base::Result_Base()
-{
-}
-
-Result_Base::Result_Base(void *user_cb, void *data, result_base_e subject)
-{
- appinfo_result_cb = NULL;
- client_result_cb = NULL;
- device_result_cb = NULL;
- bool_result_cb = NULL;
- service_result_cb = NULL;
- error_result_cb = NULL;
-
- switch (subject) {
- case RESULT_BASE_APP_INFO:
- appinfo_result_cb = reinterpret_cast<_appinfo_result_cb>(user_cb);
- break;
- case RESULT_BASE_CLIENT:
- client_result_cb = reinterpret_cast<_client_result_cb>(user_cb);
- break;
- case RESULT_BASE_DEVICE:
- device_result_cb = reinterpret_cast<_device_result_cb>(user_cb);
- break;
- case RESULT_BASE_BOOL:
- bool_result_cb = reinterpret_cast<_bool_result_cb>(user_cb);
- break;
- case RESULT_BASE_SERVICE:
- service_result_cb = reinterpret_cast<_service_result_cb>(user_cb);
- break;
- case RESULT_BASE_ERROR:
- error_result_cb = reinterpret_cast<_error_result_cb>(user_cb);
- break;
- }
-
- user_data = data;
-}
-
-Result_Base::~Result_Base()
-{
-}
-
-
-void Result_Base::onSuccess(ApplicationInfo arg)
-{
- if (appinfo_result_cb)
- appinfo_result_cb(arg, user_data);
-}
-
-void Result_Base::onSuccess(Client arg)
-{
- if (client_result_cb)
- client_result_cb(arg, user_data);
-}
-
-void Result_Base::onSuccess(Device arg)
-{
- if (device_result_cb)
- device_result_cb(arg, user_data);
-}
-
-void Result_Base::onSuccess(bool arg)
-{
- if (bool_result_cb)
- bool_result_cb(arg, user_data);
-}
-
-void Result_Base::onSuccess(Service arg)
-{
- if (service_result_cb)
- service_result_cb(arg, user_data);
-}
-
-void Result_Base::onError(Error er)
-{
- if (error_result_cb)
- error_result_cb(er, user_data);
-}
+++ /dev/null
-#include "Search.h"
-#include "Error.h"
-#include "Service.h"
-#include "Debug.h"
-#include "mDNSSearchProvider.h"
-#include "MSFDSearchProvider.h"
-#include "Result.h"
-
-int Search::SERVICE_CHECK_TIMEOUT = 5000;
-bool Search::clearProviders;
-pthread_t Search::threads[NUM_OF_THREADS];
-mDNSSearchProvider Search::provider1;
-MSFDSearchProvider Search::provider2;
-Search *Search::instance = NULL;
-bool Search::starting = false;
-bool Search::stopping = false;
-int Search::search_ref_count = 0;
-list<Search*> Search::search_list;
-list<Service> Search::services;
-int Search::onStartNotified;
-
-int Search::numRunning;
-
-/*
- if (--onStartNotified==0)
- {
- if (onStartListener!=NULL)
- onStartListener->onStart();
- }*/
-
-void Search::onStart()
-{
- st_onStart();
-}
-
-void Search::onStop()
-{
- st_onStop();
-}
-
-void Search::onFound(Service service)
-{
- st_onFound(service);
-}
-
-void Search::onLost(Service service)
-{
- st_onLost(service);
-}
-
-void Search :: st_onStart()
-{
- dlog_print(DLOG_INFO, "MSF", "Search::onStart()");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-
- // ....... ==0 ??
- if (onStartNotified > 0) {
- onStartNotified = 0;
- starting = false; //not sure why ankit
- list<Search*>::iterator itr;
- for (itr = search_list.begin(); itr != search_list.end(); itr++) {
- if ((*itr)->searchListener != NULL && (*itr)->searching_now) {
- dlog_print(DLOG_INFO, "MSF", "call onStart");
- (*itr)->searchListener->onStart();
- }
- }
- }
-}
-
-void Search::st_onStop()
-{
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- list<Search*>::iterator itr;
- for (itr = search_list.begin(); itr != search_list.end(); itr++) {
- if ((*itr)->searchListener != NULL && (*itr)->searching_now) {
- (*itr)->searchListener->onStop();
- }
- }
-}
-
-void Search::st_onFound(Service service)
-{
- dlog_print(DLOG_INFO, "MSF", "Search::onFound()");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-
- addService(service);
-
- list<Search*>::iterator itr;
-
- dlog_print(DLOG_INFO, "MSF", "Search::onFound() list size = %d", search_list.size());
-
- for (itr = search_list.begin(); itr != search_list.end(); itr++) {
- if ((*itr)->searchListener != NULL && (*itr)->searching_now) {
- (*itr)->searchListener->onFound(service);
- }
- }
-}
-
-void Search::st_onLost(Service service)
-{
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- //validateService(service);
-
- list<Search*>::iterator itr;
-
- for (itr = search_list.begin(); itr != search_list.end(); itr++) {
- if ((*itr)->searchListener != NULL && (*itr)->searching_now) {
- (*itr)->searchListener->onLost(service);
- }
- }
-}
-
-void SearchListener :: onStart()
-{
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-}
-
-void SearchListener :: onStop()
-{
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-}
-
-void SearchListener :: onFound(Service service)
-{
- //addService(service);
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-}
-
-void SearchListener :: onLost(Service service)
-{
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-}
-
-/*void Search::setOnStartListener(OnStartListener *obj){
- cout<<obj;
- onstartlistener=obj;
- }
-
- void Search::setOnStopListener(OnStopListener obj){
- onstoplistener=obj;
- }
-
- void Search::setOnServiceFoundListener(OnServiceFoundListener obj){
- onservicefoundlistener=obj;
- }
-
- void Search::setOnServiceLostListener(OnServiceLostListener obj){
- onservicelostlistener=obj;
- }*/
-
-/*
-Search *Search::getInstance()
-{
- if (instance == NULL)
- instance = new Search();
-
- return instance;
-}
-*/
-
-Search::Search()
-{
- searching_now = false;
- searchListener = NULL;
-
- search_list.push_back(this);
- printf("Search::Search()\n");
- fflush(stdout);
-}
-
-Search::~Search()
-{
- search_list.remove(this);
- printf("Search::~Search()\n");
- fflush(stdout);
-
- if (instance) {
- //delete instance;
- //instance = NULL;
- }
-
- if (searchListener) {
- //delete searchListener;
- //searchListener = NULL;
- }
-}
-
-void Search::setSearchListener(SearchListener *obj)
-{
- dlog_print(DLOG_INFO, "MSF", "setSearchListener");
- searchListener = obj;
-}
-
-void Search::releaseSearchListener()
-{
- if (searchListener) {
- searchListener = NULL;
- }
-}
-
-/*
-bool Search::isSearching()
-{
- std::list<SearchProvider>::iterator iterator;
- for (iterator = providers.begin(); iterator != providers.end(); ++iterator) {
- if (iterator->isSearching()) {
- return true;
- }
- }
- return starting||stopping;
-}
-*/
-
-Service Search::getServiceById(string id)
-{
- std::list<Service>::iterator iterator;
- for (iterator = services.begin(); iterator != services.end(); ++iterator) {
- if ((iterator->getId()) == id) {
- return(*iterator);
- }
- }
- return Service("", "", "", "", "");
-}
-
-bool Search::start()
-{
- if (searching_now == false) {
- if (search_ref_count == 0) {
- search_ref_count++;
-
- searching_now = true;
-
- dlog_print(DLOG_INFO, "MSF", "Search::start()");
-
- //if (isSearching()) {
- // return false;
- //}
-
- startDiscovery();
- } else {
- search_ref_count++;
-
- searching_now = true;
-
- if (searchListener != NULL) {
- dlog_print(DLOG_INFO, "MSF", "call onStart");
- searchListener->onStart();
- }
- }
- }
-
- return true;
-}
-
-bool Search::stop()
-{
- if (searching_now == true) {
- search_ref_count--;
- searching_now = false;
-
- if (search_ref_count == 0) {
- dlog_print(DLOG_INFO, "MSF", "search stop 1");
- stopDiscovery();
- } else {
- if (searchListener != NULL)
- searchListener->onStop();
- }
- }
-
- return true;
-}
-
-list<Service> Search::getServices()
-{
- return SearchProvider::getServices();
-}
-
-void Search::addProvider(SearchProvider provider)
-{
- providers.push_back(provider);
- provider.setSearchListener(this);
-}
-
-/*
-bool Search::removeProvider(SearchProvider provider)
-{
- if (!provider.isSearching())
- return remove(&providers,provider);
- else
- removedProviders.push_back(provider);
- return false;
-}
-*/
-
-bool Search::isEqualto(SearchProvider s1, SearchProvider s2)
-{
- list<Service> services1 = s1.getServices();
- list<Service> services2 = s1.getServices();
- int len1 = services1.size();
- int len2 = services2.size();
- if (len1 == len2)
- return false;
-
- std::list<Service>::iterator iter1;
- std::list<Service>::iterator iter2;
- for(iter1 = services1.begin(); iter1 != services1.end(); ++iter1) {
- if (services2.size() != 0) {
- iter2 = services2.begin();
- while(iter2 != services2.end()) {
- if (((*iter2).getId()) == ((*iter1).getId())) {
- services2.erase(iter2++);
- break;
- } else {
- iter2++;
- }
- }
- }
- }
- if (services2.size() == 0)
- return true;
- else
- return false;
-}
-
-bool Search::remove(list<SearchProvider> *providers, SearchProvider provider)
-{
- std::list<SearchProvider>::iterator it = providers->begin();
- while(it != providers->end()) {
- bool match = isEqualto(*it, provider);
- if (match) {
- providers->erase(it);
- return true;
- }
- }
- return false;
-}
-
-/*
-void Search::processRemovedProviders()
-{
- if (removedProviders.size()) {
- std::list<SearchProvider>::iterator iter;
- for(iter = removedProviders.begin(); iter != removedProviders.end(); ++iter) {
- if ((!((*iter).isSearching())) &&(remove(&providers,*iter)))
- remove(&removedProviders,*iter);
- }
- }
-}
-
-void Search::removeAllProviders()
-{
- clearProviders = false;
- if (!isSearching()) {
- providers.clear();
- }
- else {
- clearProviders = true;
- }
-}
-*/
-
-void *Search::pt_startMDNS(void *arg)
-{
- //provider1.start();
- return NULL;
-}
-
-void *Search::pt_startMSFD(void *arg)
-{
- provider2.start();
- return NULL;
-}
-
-void Search::startDiscovery()
-{
- dlog_print(DLOG_INFO, "MSF", "Search::startDiscovery()");
- starting = true;
- // If there are no search providers, then default to using MDNS.
- if (providers.empty()) {
- //providers.push_back(MDNSSearchProvider::create(this)); //CODE NEED TO REMOVE
- providers.push_back(MSFDSearchProvider::create(this));
- }
-
- services.clear();
-
- onStartNotified = numRunning = providers.size();
-
- int ret = -1;
-
- dlog_print(DLOG_INFO, "MSF", "try MDNS thread creat");
- provider1.start();
-// ret = pthread_create(&threads[MDNS_THREAD_NUMBER],NULL,pt_startMDNS,NULL);
- dlog_print(DLOG_INFO, "MSF", "MDNS thread created");
-
- if (ret == -1)
- cout << "Fail to create MDNS search provider\n";
-
- dlog_print(DLOG_INFO, "MSF", "try MSFD thread creat");
- ret = pthread_create(&threads[MSFD_THREAD_NUMBER], NULL, pt_startMSFD, NULL);
- dlog_print(DLOG_INFO, "MSF", "MSFD thread created");
-
- if (ret == -1)
- cout << "Fail to create MDNS search provider\n";
-
- onStart();
-}
-
-void Search::stopDiscovery()
-{
- MSF_DBG("\n[MSF API:]Function Name[%s] got called\n", __FUNCTION__);
- stopping = true;
- bool stop = false;
- stop = provider1.stop();
- stop = provider2.stop();
-
- if (stop)
- onStop();
-
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-
- pthread_cancel(threads[1]);
- pthread_join(threads[1], NULL);
-
- dlog_print(DLOG_INFO, "MSF", "MDNS MSFD thread joined");
- dlog_print(DLOG_INFO, "MSF", "Search::stop discovery end");
-}
-
-bool Search::addService(Service service)
-{
- dlog_print(DLOG_INFO, "MSF", "Search::addService()");
- bool match = false;
- for (std::list<Service>::iterator it = services.begin(); it != services.end(); it++) {
- if ((*it).getId() == service.getId()) {
- match = true;
- break;
- }
- }
- if (!match)
- services.push_back(service);
- return true;
-}
-
-bool Search::removeService(Service service)
-{
- for (std::list<Service>::iterator it = services.begin(); it != services.end(); it++) {
- if ((*it).getId() == service.getId()) {
- services.erase(it);
- break;
- }
- }
- return true;
-}
-
-void Search::removeAndNotify(Service service)
-{
- if (removeService(service)) {
- // if (onServiceLostListener != NULL) {
- // searchListener->onLost(service);
- // }
- }
-}
-
-void Search::validateService(Service service)
-{
- /*
- class ResultSearchServiceCallback : public Result_Base
- {
- public:
- void onSuccess(Service abc)
- {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- }
-
- void onError(Error)
- {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- }
- };
-
- Result_Base *rService;
-
- ResultSearchServiceCallback *r1Service = new ResultSearchServiceCallback();
-
- rService = r1Service;
-
- Service::getByURI(service.getUri(), SERVICE_CHECK_TIMEOUT, rService);
- delete r1Service;
- rService = r1Service = NULL;
- */
- /*
- @Override
- public void onSuccess(Service result) {
- // We can contact the service, so keep it in the master
- // list.
- }
-
- @Override
- public void onError(Error error) {
-
- // If we cannot validate the existence of the service,
- // then we will remove it from the master list.
- removeAndNotify(service);
-
- for (SearchProvider provider:providers) {
- provider.removeService(service);
- }
- }
- });*/
-}
-
+++ /dev/null
-#include"Service.h"
-#include "Search.h"
-#include"SearchProvider.h"
-#include "Debug.h"
-
-list<Service> SearchProvider::services;
-
-SearchProvider::SearchProvider()
-{
- searching = false;
-}
-
-SearchProvider::SearchProvider(Search *searchListen)
-{
- searchListener = searchListen;
- searching = false;
-}
-
-list<Service> SearchProvider::getServices()
-{
- return services;
-}
-
-void SearchProvider::setServices(list<Service> listofservices)
-{
- clearServices();
- if (listofservices.size() != 0) {
- std::list<Service>::const_iterator iterator;
- for (iterator = listofservices.begin(); iterator != listofservices.end(); ++iterator) {
- services.push_back(*iterator);
- }
- }
-}
-
-void SearchProvider::setSearchListener(Search *obj)
-{
- searchListener = obj;
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-}
-
-void SearchProvider::addService(Service service)
-{
- dlog_print(DLOG_INFO, "MSF", "SearchProvider::addService()");
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- bool found = false;
-
- std::list<Service>::iterator iterator;
-
- bool match = false;
-
- for (iterator = services.begin(); iterator != services.end(); ++iterator) {
- if (iterator->getId() == service.getId()) {
- match = true;
- break;
- }
- }
-
- if (!match) {
- services.push_back(service);
- found = true;
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-
- if (found) {
- Search::st_onFound(service);
- }
- } else {
- }
-}
-
-void SearchProvider::removeService(Service service)
-{
- if (&service == NULL) {
- return;
- }
-
- std::list<Service>::iterator it = services.begin();
- while (it != services.end()) {
- if (((*it).getId()) == (service.getId())) {
- services.erase(it++);
- } else {
- it++;
- }
- }
-}
-
-void SearchProvider::removeServiceAndNotify(Service service)
-{
- removeService(service);
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- Search::st_onLost(service);
-}
-
-void SearchProvider::clearServices()
-{
- services.clear();
-}
-
-Service SearchProvider::getServiceById(string id)
-{
- // MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n",__FUNCTION__ ,__LINE__,__FILE__);
- std::list<Service>::iterator iterator;
- for (iterator = services.begin(); iterator != services.end(); ++iterator) {
- if (((*iterator).getId()) == id) {
- return(*iterator);
- }
- }
- return Service("", "", "", "", "");
-}
-
-bool SearchProvider::isSearching()
-{
- if (this->searching)
- return true;
- else
- return false;
-}
+++ /dev/null
-#include "Service.h"
-#include "Search.h"
-#include "Result.h"
-#include "Channel.h"
-#include "Debug.h"
-#include "Device.h"
-#include "Application.h"
-#include<curl/curl.h>
-
-string Service::ID_PROPERTY = "id";
-string Service::VERSION_PROPERTY = "ve";
-string Service::NAME_PROPERTY = "fn";
-string Service::TYPE_PROPERTY = "md";
-string Service::ENDPOINT_PROPERTY = "se";
-
-Result_Base *Service::Resulturi = NULL;
-ServiceInfo Service::serviceval;
-
-Service Service::local_service;
-
-string Service::curl_data = "";
-
-Service::Service()
-{
- //Resulturi = NULL;
- //Resultdevice=NULL;
- //devicedata = NULL;
-}
-
-/*Service::Service(string Id,string Version,string Name,string Type,string Uri)
-{
- id=Id;
- version=Version;
- name=Name;
- type=Type;
- uri=Uri;
-}*/
-
-Service::Service(string id1, string version1, string name1, string type1, string endPoint1)
-{
- id = id1;
- version = version1;
- name = name1;
- type = type1;
- uri = endPoint1;
-}
-
-/*
-Search *Service::search()
-{
- return Search::getInstance();
-}
-*/
-
-void Service:: getById(string id, Result_Base *result)
-{
- Search search;
- Service service;
-
- bool status = search.start();
- if (!status) {
- service = search.getServiceById(id);
- } else {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- usleep(50000000);
- service = search.getServiceById(id);
- search.stop();
- }
-
- if (service.getId().length() == 0) {
- if (result != NULL)
- result->onError(Error::create("Service Not Found"));
- } else {
- if (result != NULL)
- result->onSuccess(service);
- }
-}
-
-string Service::getName()
-{
- return name;
-}
-
-string Service::getVersion()
-{
- return version;
-}
-
-string Service::getType()
-{
- return type;
-}
-
-string Service::getId()
-{
- return id;
-}
-
-string Service::getUri()
-{
- return uri;
-}
-
-void Service::create(char *service_txt)
-{
- position posvalues;
- string txt(service_txt);
-
- posvalues = findServiceValue(ID_PROPERTY, service_txt);
- id = txt.substr((posvalues.start)-1, ((posvalues.end)-(posvalues.start)+1));
-
- posvalues = findServiceValue(VERSION_PROPERTY, service_txt);
- version = txt.substr((posvalues.start)-1, ((posvalues.end)-(posvalues.start)+1));
-
- posvalues = findServiceValue(NAME_PROPERTY, service_txt);
- name = txt.substr((posvalues.start)-1, ((posvalues.end)-(posvalues.start)+1));
-
- posvalues = findServiceValue(TYPE_PROPERTY, service_txt);
- type = txt.substr((posvalues.start)-1, ((posvalues.end)-(posvalues.start)+1));
-
- posvalues = findServiceValue(ENDPOINT_PROPERTY, service_txt);
- uri = txt.substr((posvalues.start)-1, ((posvalues.end)-(posvalues.start)+1));
-
- MSF_DBG("\n Debug Log: SERVICE FOUND THROUGH MDNS WITH URI [%s] [%s] [%d] in %s \n", uri.c_str(), __FUNCTION__, __LINE__, __FILE__);
-}
-
-Service Service::create(ServiceInfo servicevalue)
-{
- //if (
- string id = servicevalue.infoId;
-// this->id=id;
- string version = servicevalue.infoVersion;
-// this->version=version;
- string name = servicevalue.infoName;
-// this->name=name;
- string type = servicevalue.infotype;
-// this->type=type;
- string endPoint = servicevalue.infoURI;//TODO
-// this->uri=endPoint;
- Service service = Service(id, version, name, type, endPoint);
- MSF_DBG("\n Debug Log: SERVICE FOUND THROUGH MSFD WITH URI [%s] [%s] [%d] in %s \n", endPoint.c_str(), __FUNCTION__, __LINE__, __FILE__);
- return service;
-}
-
-Service Service::create(map<string, string> serviceMap)
-{
- string id = serviceMap.find(ID_PROPERTY)->second;
- string version = serviceMap.find("version")->second;
- string name = serviceMap.find("name")->second;
- string type = serviceMap.find("type")->second;
- string endPoint = serviceMap.find("uri")->second;//TODO
- Service service = Service(id, version, name, type, endPoint);
- return service;
- //return Service;*/
-}
-
-position Service::findServiceValue(string substrng, char *strng)
-{
- const char *src = strstr(strng, substrng.c_str());
- int startpoint = (src-strng)+sizeof(substrng);
- std::string temp = "\"";
- const char *dest = strstr(src, temp.c_str());
- int endpoint = (dest-strng);
- position values;
- values.start = startpoint;
- values.end = endpoint;
- return values;
-}
-
-void Service::getDeviceInfo(Result_Base *dev_result)
-{
- dlog_print(DLOG_INFO, "MSF", "getDeviceInfo");
- curl_service_calling(uri, 0, dev_result);
-}
-
-Service Service::getLocal(void)
-{
- class GetLocalServiceCallback : public Result_Base
- {
- public:
- void onSuccess(Service service)
- {
- dlog_print(DLOG_INFO, "MSF", "service name : %s\n", service.getName().c_str() ? service.getName().c_str() : "name is NULL");
- local_service = service;
- }
-
- void onError(Error)
- {
- dlog_print(DLOG_ERROR, "MSF", "getLocal() : Fail to get local service info");
- }
- };
-
- GetLocalServiceCallback r1Service;
- string uri = "http://127.0.0.1:8001/api/v2/";
- getByURI(uri, 0, &r1Service);
-
- return local_service;
-}
-
-void Service::getByURI(string uri, Result_Base *result)
-{
- getByURI(uri, 0, result);
-}
-
-void Service::getByURI(string uri, long timeout, Result_Base *result)
-{
- dlog_print(DLOG_INFO, "MSF", "getByURI() uri = %s", uri.c_str());
-
- Resulturi = result;
- //Resultdevice = NULL;
- curl_service_calling(uri, timeout, NULL);
- Resulturi = NULL;
-}
-
-int Service::curl_service_calling(string uri, long timeout, void *dev_result_ptr)
-{
- dlog_print(DLOG_INFO, "MSF", "curl_service_calling() 1");
- MSF_DBG("\n Debug Log: SERVICE FOUND THROUGH WITH URI [%s] [%d] in %s \n", __FUNCTION__, __LINE__, __FILE__);
- CURL *curl;
- CURLcode res;
- struct curl_slist *headers = NULL;
- headers = curl_slist_append(headers, "Accept: application/json");
- headers = curl_slist_append(headers, "Content-Type: application/json");
-
- curl = curl_easy_init();
- if (curl) {
- const char *c = uri.c_str();
- curl_easy_setopt(curl, CURLOPT_URL, c);
- curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- //curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
- //if (timeout != 0)
- curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 5000);
-
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Service::createdata);
- //curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 5000);
- curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
- //curl_easy_setopt(curl, CURLOPT_PORT, 8001);
- //curl_easy_setopt(curl, CURLOPT_LOCALPORT, 8888);
-
- res = curl_easy_perform(curl);
-
- if (res != CURLE_OK) {
- dlog_print(DLOG_ERROR, "MSF", "####Service curl ERROR = %d ####", res);
- MSF_DBG("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
- createdata_process("", dev_result_ptr);
- } else {
- createdata_process(curl_data, dev_result_ptr);
- curl_data.clear();
- }
-
- curl_easy_cleanup(curl);
- dlog_print(DLOG_INFO, "MSF", "curl_service_calling() 4");
- }
-
- dlog_print(DLOG_INFO, "MSF", "curl_service_calling() 5");
-
- return 0;
-}
-
-size_t Service::createdata(char *buf, size_t size, size_t nmemb, void *up)
-{
- dlog_print(DLOG_INFO, "MSF", "createdata() 1");
-
- MSF_DBG("\n Debug Log: SERVICE FOUND THROUGH WITH URI [%s] [%d] in %s \n", __FUNCTION__, __LINE__, __FILE__);
- if (buf != NULL) {
- //string data;
-
- curl_data.append(buf, size*nmemb);
-
- //createdata_process(data, ptr);
- } else {
- dlog_print(DLOG_ERROR, "MSF", "createdata() buf is null");
- //createdata_process(string(), ptr);
- }
-
- return size*nmemb;
-}
-
-void Service::createdata_process(string data, void *dev_result_ptr)
-{
- MSF_DBG("\n Debug Log: SERVICE FOUND THROUGH WITH URI [%s] [%d] in %s \n", __FUNCTION__, __LINE__, __FILE__);
- if (data.length() != 0) {
- json_parse_service(data.c_str(), dev_result_ptr);
- } else {
- if (Resulturi != NULL) {
- Resulturi->onError(Error::create("Timeout"));
-
- //delete (Resulturi);
-
- //Resulturi = NULL;
- }
- if (dev_result_ptr != NULL) {
- (static_cast<Result_Base*> (dev_result_ptr))->onError(Error::create("Not Found"));
- }
- }
-}
-
-void Service::foreach_json_object(JsonObject *object, const gchar *key, JsonNode *node, gpointer user_data)
-{
- if (json_node_get_node_type(node) == JSON_NODE_VALUE) {
- if (!strncmp(key, "id", 2)) {
- serviceval.infoId = json_node_get_string(node);
- dlog_print(DLOG_ERROR, "MSF", "infoId set as %s", serviceval.infoId.c_str());
- //cout<<"\nID : \t"<<serviceval.infoId <<"\n";
- } else if (!strncmp(key, "version", 4)) {
- serviceval.infoVersion = json_node_get_string(node);
- dlog_print(DLOG_ERROR, "MSF", "infoVersion set as %s", serviceval.infoVersion.c_str());
- } else if (!strncmp(key, "name", 7)) {
- serviceval.infoName = json_node_get_string(node);
- dlog_print(DLOG_ERROR, "MSF", "infoName set as %s", serviceval.infoName.c_str());
- } else if (!strncmp(key, "type", 7)) {
- serviceval.infotype = json_node_get_string(node);
- dlog_print(DLOG_ERROR, "MSF", "infotype set as %s", serviceval.infotype.c_str());
-
- } else if (!strncmp(key, "uri", 7)) {
- serviceval.infoURI = json_node_get_string(node);
- dlog_print(DLOG_ERROR, "MSF", "infoURI set as %s", serviceval.infoURI.c_str());
- }
- } else if (json_node_get_node_type(node) == JSON_NODE_OBJECT) {
- if (!strncmp(key, "device", 7)) {
- MSF_DBG("\n Debug Log: SERVICE FOUND THROUGH WITH URI [%s] [%d] in %s \n", __FUNCTION__, __LINE__, __FILE__);
- if (user_data != NULL) {
- Device dev = Device::create(node);
- (static_cast<Result_Base *>(user_data))->onSuccess(dev);
- }
- }
- }
-}
-
-
-int Service::json_parse_service(const char *in, void *ptr)
-{
- MSF_DBG("\n Debug Log: SERVICE FOUND THROUGH WITH URI [%s] [%d] in %s \n", __FUNCTION__, __LINE__, __FILE__);
- dlog_print(DLOG_ERROR, "MSF", "Service::json_parse_service : %s", in);
-
- JsonParser *parser = json_parser_new();
-
- if (json_parser_load_from_data(parser, in, -1, NULL)) {
- JsonNode *node = json_parser_get_root(parser);
-
- if (json_node_get_node_type(node) == JSON_NODE_OBJECT) {
- json_object_foreach_member(json_node_get_object(node), foreach_json_object, ptr);
- }
-
- } else {
- dlog_print(DLOG_ERROR, "MSF", "json_parsing error");
- }
-
- /*
- dlog_print(DLOG_INFO, "MSF", "Service json_parse_service()");
- void *result_ptr = ptr;
- enum json_type typed;
- json_object_object_foreach(jobj, key, val) {
- typed = json_object_get_type(val);
- switch (typed) {
- case json_type_null:
- break;
-
- case json_type_boolean:
- break;
-
- case json_type_double:
- break;
-
- case json_type_int:
- break;
-
- case json_type_object:
- dlog_print(DLOG_INFO, "MSF", "Service json_parse_service() 2");
- if (!strncmp(key , "device", 7)) {
- dlog_print(DLOG_INFO, "MSF", "Service json_parse_service() 3");
-
- MSF_DBG("\n Debug Log: SERVICE FOUND THROUGH WITH URI [%s] [%d] in %s \n", __FUNCTION__, __LINE__, __FILE__);
- if (result_ptr != NULL) {
- dlog_print(DLOG_INFO, "MSF", "Service json_parse_service() 4");
- MSF_DBG("\n Debug Log: SERVICE FOUND THROUGH WITH URI [%s] [%d] in %s \n", __FUNCTION__, __LINE__, __FILE__);
-
- Device dev = Device::create(val);
- (static_cast<Result_Base *> (result_ptr))->onSuccess(dev);
- result_ptr=NULL;
- }
- }
- break;
-
- case json_type_array:
- break;
-
- case json_type_string:
- if (!strncmp(key , "id", 2)) {
- serviceval.infoId = json_object_get_string(val);
- //cout<<"\nID : \t"<<serviceval.infoId <<"\n";
- }
- else if (!strncmp(key , "version", 4)) {
- serviceval.infoVersion = json_object_get_string(val);
- }
- else if (!strncmp(key , "name", 7)) {
- serviceval.infoName = json_object_get_string(val);
- }
- else if (!strncmp(key , "type", 7)) {
- serviceval.infotype = json_object_get_string(val);
- }
- else if (!strncmp(key , "uri", 7)) {
- serviceval.infoURI = json_object_get_string(val);
- }
- break;
- }
- }
- */
-
- if ((Resulturi!= NULL)) {
- dlog_print(DLOG_INFO, "MSF", "json_parse_service() call onSuccess()");
- Resulturi->onSuccess(create(serviceval));
- //delete (Resulturi);
- //Resulturi=NULL;
- }
-
- return 0;
-}
-
-Application Service::createApplication(string uri)
-{
- if (!(uri == "")) {//check length and return error
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- //Application *application = Application::create(this,uri);
- Application application = Application::create(this, uri);
- return application;
- } else {
- Application app;
- return app;
- }
-}
-
-Application Service::createApplication(string uri, string channelId)
-{
- if (!((uri == "") || (channelId == ""))) {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- //Application *application=Application::create(this, uri, channelId, map_type());
- Application application = Application::create(this, uri, channelId, map_type());
- return application;
- } else {
- Application app;
- return app;
- }
-}
-
-Application Service::createApplication(string uri, string channelId, map<string, string> startArgs)
-{
- if (!((uri == "") || (channelId == ""))) {
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- //Application *application =Application::create(this, uri, channelId, startArgs);
- Application application = Application::create(this, uri, channelId, startArgs);
- return application;
- } else {
- Application app;
- return app;
- }
-}
-
-Channel *Service::createChannel(string uri)
-{
- Channel *channel = Channel::create(this, uri);
- return channel;
-}
+++ /dev/null
-#include "URIparser.h"
-#include <stdio.h>
-#include <cstdlib>
-#include <cstring>
-
-namespace uri_parser {
-
-const std::string URIParse::URIRESERVED_PATH = "?#";
-const std::string URIParse::URIRESERVED_QUERY = "#";
-const std::string URIParse::URIRESERVED_FRAGMENT = "";
-const std::string URIParse::URIILLEGAL = "%<>{}|\\\"^`";
-
-URIParse::URIParse():
- _URIport(0), _URIflags(0)
-{
-}
-
-URIParse::URIParse(const std::string& uri):
- _URIport(0), _URIflags(0)
-{
- parseURI(uri);
-}
-
-URIParse::URIParse(const char* uri):
- _URIport(0), _URIflags(0)
-{
- parseURI(std::string(uri));
-}
-
-URIParse::~URIParse()
-{
-}
-
-void URIParse::clear()
-{
- _URIscheme.clear();
- _URIuserInfo.clear();
- _URIhost.clear();
- _URIport = 0;
- _URIportStr.clear();
- _URIpath.clear();
- _URIquery.clear();
- _URIfragment.clear();
- _URIflags = 0;
-}
-
-void URIParse::setURIScheme(const std::string& scheme)
-{
- _URIscheme = scheme;
- toLowerInPlaceURI(_URIscheme);
- if (_URIport == 0) {
- _URIport = getWellKnownPortforURI();
- }
-}
-
-bool URIParse::empty() const
-{
- return _URIscheme.empty() && _URIhost.empty() && _URIpath.empty() && _URIquery.empty() && _URIfragment.empty();
-}
-
-void URIParse::decodeURI(const std::string& str, std::string& decodedStr, long _flags2)
-{
- std::string::const_iterator it = str.begin();
- std::string::const_iterator end = str.end();
-
- while (it != end) {
- char c = *it++;
- if (c == '%') {
- if (it == end) {
- if (_flags2 & 0x1)
- printf("ERROR: URI encoding: no hex digit following percent sign.\n");
- return;
- }
-
- char hi = *it++;
-
- if (it == end) {
- if (_flags2 & 0x1)
- printf("ERROR: URI encoding: two hex digits must follow percent sign.\n");
- return;
- }
-
- char lo = *it++;
-
- if (hi >= '0' && hi <= '9') {
- c = hi - '0';
- } else if (hi >= 'A' && hi <= 'F') {
- c = hi - 'A' + 10;
- } else if (hi >= 'a' && hi <= 'f') {
- c = hi - 'a' + 10;
- } else {
- if (_flags2 & 0x1)
- printf("ERROR: URI encoding: not a hex digit.\n");
- return;
- }
- c *= 16;
- if (lo >= '0' && lo <= '9') {
- c += lo - '0';
- } else if (lo >= 'A' && lo <= 'F') {
- c += lo - 'A' + 10;
- } else if (lo >= 'a' && lo <= 'f') {
- c += lo - 'a' + 10;
- } else {
- if (_flags2 & 0x1)
- printf("ERROR: URI encoding: not a hex digit.\n");
- return;
- }
- }
- decodedStr += c;
- }
-}
-
-unsigned short URIParse::getWellKnownPortforURI() const
-{
- if (_URIscheme == "ftp")
- return 21;
- else if (_URIscheme == "ssh")
- return 22;
- else if (_URIscheme == "telnet")
- return 23;
- else if (_URIscheme == "http")
- return 80;
- else if (_URIscheme == "nntp")
- return 119;
- else if (_URIscheme == "ldap")
- return 389;
- else if (_URIscheme == "https")
- return 443;
- else if (_URIscheme == "rtsp")
- return 554;
- else if (_URIscheme == "sip")
- return 5060;
- else if (_URIscheme == "sips")
- return 5061;
- else if (_URIscheme == "xmpp")
- return 5222;
- else
- return 0;
-}
-
-void URIParse::parseURI(const std::string& uri)
-{
- std::string::const_iterator it = uri.begin();
- std::string::const_iterator end = uri.end();
- if (it == end) return;
- if (*it != '/' && *it != '.' && *it != '?' && *it != '#') {
- std::string scheme;
- while (it != end && *it != ':' && *it != '?' && *it != '#' && *it != '/') scheme += *it++;
- if (it != end && *it == ':') {
- ++it;
-
- if (it == end) {
- if (_URIflags & 0x1)
- printf("ERROR: URI scheme must be followed by authority or path.\n");
- return;
- }
- setURIScheme(scheme);
- if (*it == '/') {
- ++it;
- if (it != end && *it == '/') {
- ++it;
- URIparseAuthority(it, end);
- } else {
- --it;
- }
- }
- URIparsePathEtc(it, end);
- } else {
- it = uri.begin();
- URIparsePathEtc(it, end);
- }
- } else {
- URIparsePathEtc(it, end);
- }
-}
-
-void URIParse::URIparseAuthority(std::string::const_iterator& it, const std::string::const_iterator& end)
-{
- std::string userInfo;
- std::string part;
- while (it != end && *it != '/' && *it != '?' && *it != '#') {
- if (*it == '@') {
- userInfo = part;
- part.clear();
- } else {
- part += *it;
- }
- ++it;
- }
- std::string::const_iterator pbeg = part.begin();
- std::string::const_iterator pend = part.end();
- URIparseHostAndPort(pbeg, pend);
- _URIuserInfo = userInfo;
-}
-
-void URIParse::URIparseHostAndPort(std::string::const_iterator& it, const std::string::const_iterator& end)
-{
- if (it == end) return;
-
- std::string host;
- if (*it == '[') {
- ++it;
- while (it != end && *it != ']') host += *it++;
-
- if (it == end) {
- if (_URIflags & 0x1)
- printf("ERROR: unterminated IPv6 address.\n");
- return;
- }
- ++it;
- } else {
- while (it != end && *it != ':') host += *it++;
- }
-
- if (it != end && *it == ':') {
- ++it;
- std::string port;
- while (it != end) port += *it++;
- if (!port.empty()) {
- int nport = 0;
-
- _URIportStr = port.c_str();
- nport = atoi(port.c_str());
- if (nport < 0) {
- _URIport = 0;
- } else if (nport > 65535) {
- _URIport = 65535;
- } else {
- _URIport = (unsigned short) nport;
- }
- } else {
- _URIport = getWellKnownPortforURI();
- }
- } else {
- _URIport = getWellKnownPortforURI();
- }
- _URIhost = host;
- toLowerInPlaceURI(_URIhost);
-}
-
-void URIParse::URIparsePath(std::string::const_iterator& it, const std::string::const_iterator& end)
-{
- std::string path;
- while (it != end && *it != '?' && *it != '#') path += *it++;
- decodeURI(path, _URIpath, _URIflags);
-}
-
-void URIParse::URIparsePathEtc(std::string::const_iterator& it, const std::string::const_iterator& end)
-{
- if (it == end) return;
-
- if (*it != '?' && *it != '#')
- URIparsePath(it, end);
-
- if (it != end && *it == '?') {
- ++it;
- URIparseQuery(it, end);
- }
-
- if (it != end && *it == '#') {
- ++it;
- URIparseFragment(it, end);
- }
-}
-
-void URIParse::URIparseQuery(std::string::const_iterator& it, const std::string::const_iterator& end)
-{
- _URIquery.clear();
- while (it != end && *it != '#') _URIquery += *it++;
-}
-
-void URIParse::URIparseFragment(std::string::const_iterator& it, const std::string::const_iterator& end)
-{
- std::string fragment;
- while (it != end) fragment += *it++;
- decodeURI(fragment, _URIfragment, _URIflags);
-}
-
-bool URIParse::isIPAddressinURI(const std::string& str)
-{
- const char *str2 = str.c_str();
- const char *ptr = strrchr(str2, (int)'.');
- if (ptr && *ptr == '.') {
- ++ptr;
- if (strchr("0123456789", *ptr))
- return 1;
- }
- return 0;
-}
-
-}
+++ /dev/null
-#include"mDNSSearchProvider.h"
-#include <stdlib.h>
-#include "Debug.h"
-#include <list>
-#include "Service.h"
-
-#define SERVICE_TYPE "_samsungmsf._tcp"
-
-dnssd_service_h g_service = 0;
-
-mDNSSearchProvider::~mDNSSearchProvider()
-{
- MSF_DBG("mDNS off.");
-}
-
-static const char *dnssd_error_to_string(dnssd_error_e error)
-{
- switch (error) {
- case DNSSD_ERROR_NONE:
- return "DNSSD_ERROR_NONE";
- case DNSSD_ERROR_OUT_OF_MEMORY:
- return "DNSSD_ERROR_OUT_OF_MEMORY";
- case DNSSD_ERROR_INVALID_PARAMETER:
- return "DNSSD_ERROR_INVALID_PARAMETER";
- case DNSSD_ERROR_NOT_SUPPORTED:
- return "DNSSD_ERROR_NOT_SUPPORTED";
- case DNSSD_ERROR_NOT_INITIALIZED:
- return "DNSSD_ERROR_NOT_INITIALIZED";
- case DNSSD_ERROR_ALREADY_REGISTERED:
- return "DNSSD_ERROR_ALREADY_REGISTERED";
- case DNSSD_ERROR_NAME_CONFLICT:
- return "DNSSD_ERROR_NAME_CONFLICT";
- case DNSSD_ERROR_SERVICE_NOT_RUNNING:
- return "DNSSD_ERROR_SERVICE_NOT_RUNNING";
- case DNSSD_ERROR_OPERATION_FAILED:
- return "DNSSD_ERROR_OPERATION_FAILED";
- default:
- return "UNSUPPORTED_ERROR";
- }
-}
-
-mDNSSearchProvider::mDNSSearchProvider()
-{
- MSF_DBG(" [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] ", __FUNCTION__, __LINE__, __FILE__);
- SearchProvider();
-}
-
-mDNSSearchProvider::mDNSSearchProvider(Search *sListener) : SearchProvider(sListener)
-{
- MSF_DBG(" [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] ", __FUNCTION__, __LINE__, __FILE__);
-}
-
-SearchProvider mDNSSearchProvider::create()
-{
- return (SearchProvider)mDNSSearchProvider();
-}
-
-SearchProvider mDNSSearchProvider::create(Search *searchListener)
-{
- MSF_DBG("\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- return (SearchProvider)mDNSSearchProvider(searchListener);
-}
-
-void mDNSSearchProvider::addService(Service service)
-{
- this->SearchProvider::addService(service);
-}
-
-void extract_service_info(ServiceInfo &info, string text)
-{
- int id_pos = text.find("id=");
- int remote_pos = text.find("remote=");
- int se_pos = text.find("se=");
- int ve_pos = text.find("ve=");
- int fn_pos = text.find("fn=");
- int md_pos = text.find("md=");
-
- char c_text[100];
- int j = 0;
-
- MSF_DBG("TxT Record : %s", text.c_str());
-
- for(int i = id_pos + 3; remote_pos > i; i++, j++) {
- c_text[j] = text[i];
- }
-
- c_text[j-1] = '\0';
- info.infoId = c_text;
- MSF_DBG("ID : %s", c_text);
-
- j = 0;
- for(int i = ve_pos + 3; md_pos > i; i++, j++) {
- c_text[j] = text[i];
- }
-
- c_text[j-1] = '\0';
- info.infoVersion = c_text;
- MSF_DBG("Version : %s", c_text);
-
- j = 0;
- for(int i = fn_pos + 3; se_pos > i; i++, j++) {
- c_text[j] = text[i];
- }
-
- c_text[j-1] = '\0';
- info.infoName = c_text;
- MSF_DBG("Name : %s", c_text);
-
- j = 0;
- for(unsigned int i = se_pos + 3; text.size() > i; i++, j++) {
- c_text[j] = text[i];
- }
-
- c_text[j] = '\0';
- info.infoURI = c_text;
- MSF_DBG("Uri : %s", c_text);
-}
-
-static void dnssd_browse_reply(dnssd_service_state_e service_state, dnssd_service_h remote_service, void *user_data)
-{
- MSF_DBG("[MSF : API] Debug log Function : [%s] and line [%d] in file [%s] ", __FUNCTION__, __LINE__, __FILE__);
- mDNSSearchProvider *provider = (mDNSSearchProvider*)user_data;
- int rv = 0;
- MSF_DBG("Handler : %u", remote_service);
- MSF_DBG("State : ");
- switch (service_state) {
- case DNSSD_SERVICE_STATE_AVAILABLE:
- MSF_DBG("Available");
- break;
- case DNSSD_SERVICE_STATE_UNAVAILABLE:
- MSF_DBG("Un-Available");
- break;
- case DNSSD_SERVICE_STATE_NAME_LOOKUP_FAILED:
- MSF_DBG("Lookup failure for service name");
- break;
- case DNSSD_SERVICE_STATE_HOST_NAME_LOOKUP_FAILED:
- MSF_DBG("Lookup failure for host name and port number");
- break;
- case DNSSD_SERVICE_STATE_ADDRESS_LOOKUP_FAILED:
- MSF_DBG("Lookup failure for IP address");
- break;
- default:
- MSF_DBG("Unknown Browse State");
- break;
- }
-
- char *name = NULL;
- char *type = NULL;
-
- rv = dnssd_service_get_name(remote_service, &name);
- if (rv == DNSSD_ERROR_NONE && name != NULL)
- MSF_DBG("Service Name : %s", name);
-
- rv = dnssd_service_get_type(remote_service, &type);
- if (rv == DNSSD_ERROR_NONE && type != NULL)
- MSF_DBG("Service Type : %s", type);
-
- if (service_state == DNSSD_SERVICE_STATE_AVAILABLE) {
- char *ip_v4_address = NULL;
- char *ip_v6_address = NULL;
- char *txt_record = NULL;
- unsigned short txt_len = 0;
- int port = 0;
-
- rv = dnssd_service_get_ip(remote_service, &ip_v4_address, &ip_v6_address);
- if (rv == DNSSD_ERROR_NONE) {
- if (ip_v4_address)
- MSF_DBG("IPv4 Address : %s", ip_v4_address);
- if (ip_v6_address)
- MSF_DBG("IPv6 Address : %s", ip_v6_address);
- }
-
- rv = dnssd_service_get_port(remote_service, &port);
- MSF_DBG("Port : %d\n", port);
-
- dnssd_service_get_all_txt_record(remote_service, &txt_len,
- (void **)&txt_record);
- MSF_DBG("TXT Record: %s", txt_record);
-
- string temp_str(txt_record, txt_len);
-
- ServiceInfo service_info; //id, version, name, type, Uri
- MSF_DBG("txt_len %d", txt_len);
- if (txt_len > 100) {
- extract_service_info(service_info, temp_str);
- service_info.infotype = SERVICE_TYPE;
- Service service = Service::create(service_info);
- provider->addService(service);
- MSF_DBG("service : id( %s ) registerd.", service_info.infoId.c_str());
- }
-
- free(ip_v4_address);
- free(ip_v6_address);
- free(name);
- free(type);
- free(txt_record);
- }
-}
-
-void mDNSSearchProvider::start()
-{
- if (g_service != 0) {
- dnssd_stop_browsing_service(g_service);
- g_service = 0;
- }
-
- int rv = dnssd_initialize();
- if (rv != DNSSD_ERROR_NONE) {
- MSF_DBG("mDNS is not initialzed.");
- return;
- } else {
- MSF_DBG("mDNS is initialzed successfully.");
- }
-
- rv = dnssd_start_browsing_service(SERVICE_TYPE, &g_service, dnssd_browse_reply, this);
- if (rv != DNSSD_ERROR_NONE) {
- MSF_DBG("Failed to browse for dns service, error %s", dnssd_error_to_string((dnssd_error_e)rv));
- } else {
- MSF_DBG("Succeeded to browse for dns service.");
- }
-}
-
-bool mDNSSearchProvider::stop()
-{
- int rv;
-
- if (g_service != 0) {
- rv = dnssd_stop_browsing_service(g_service);
- g_service = 0;
- if (rv != DNSSD_ERROR_NONE) {
- MSF_DBG("Failed to stop browse dns service %s", dnssd_error_to_string((dnssd_error_e)rv));
- return false;
- } else {
- MSF_DBG("Successfully stopped browsing dns service");
- dnssd_deinitialize();
- return true;
- }
- } else {
- MSF_DBG("Browsing is aleady stopped.");
- return false;
- }
-}
+++ /dev/null
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(msf-api-test)
-INCLUDE(GNUInstallDirs)
-
-# Targets
-SET(target "msf-api-test")
-
-# Source Lists
-SET(SRCS main.cpp)
-MESSAGE("Sources: ${SRCS}")
-
-# Dependencies
-SET(DEPS "glib-2.0 gio-2.0 json-glib-1.0 dlog openssl msf-api libwebsockets libcurl")
-
-INCLUDE(FindPkgConfig)
-INCLUDE_DIRECTORIES(
-${CMAKE_CURRENT_SOURCE_DIR}/include
-)
-ADD_DEFINITIONS(-g -O2 -Wall -fPIC -Wl,--as-needed)
-
-# Building Library
-pkg_check_modules(lib_pkg REQUIRED ${DEPS})
-
-FOREACH(flag ${lib_pkg_CFLAGS})
-SET(LIB_EXTRA_CFLAGS "${LIB_EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-ADD_EXECUTABLE(${target} ${SRCS})
-TARGET_LINK_LIBRARIES(${target} ${lib_pkg_LDFLAGS} -lcurl msf-api nsd-dns-sd glib-2.0 gio-2.0 json-glib-1.0)
-SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_FLAGS ${LIB_EXTRA_CFLAGS})
-SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_DEFINITIONS "LOG_TAG=\"MSF\"")
-SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER})
-SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER})
-
-# Installing Library
-INSTALL(TARGETS ${target} DESTINATION bin)
+++ /dev/null
-//#include <msf-api/Search.h>
-//#include <msf-api/Service.h>
-//#include <msf-api/Clients.h>
-//#include <msf-api/Client.h>
-//#include <msf-api/Application.h>
-//#include <msf-api/ApplicationInfo.h>
-//#include <msf-api/Device.h>
-//#include <msf-api/Result.h>
-//#include <msf-api/Error.h>
-//#include <msf-api/Debug.h>
-#include "Search.h"
-#include "Service.h"
-#include "Clients.h"
-#include "Client.h"
-#include "Application.h"
-#include "ApplicationInfo.h"
-#include "Device.h"
-#include "Result.h"
-#include "Error.h"
-#include "Debug.h"
-#include <map>
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <glib.h>
-
-/*
- * change this value
- * if you want to use msf c api, set 1
- */
-
-
-/* availabel appID
-'dev-multiscreen-examples.s3-website-us-west-1.amazonaws.com/examples/helloworld/tv':
-'dev-multiscreen-examples.s3-website-us-west-1.amazonaws.com/examples/helloworld/tv/index.html':
-'dev-multiscreen.samsung.com/casteroids/tv/index.html':
-'fling-tv.herokuapp.com':
-'google.com':
-'multiscreen.samsung.com/app-sample-photos/tv/index.html':
-'multiscreen.samsung.com/casteroids/tv/index.html':
-'prod-multiscreen-examples.s3-website-us-west-1.amazonaws.com/examples/helloworld/tv':
-'prod-multiscreen-examples.s3-website-us-west-1.amazonaws.com/examples/helloworld/tv/index.html':
-'prod-multiscreen-examples.s3-website-us-west-1.amazonaws.com/examples/photoshare/tv':
-'prod-multiscreen-examples.s3-website-us-west-1.amazonaws.com/examples/photoshare/tv/index.html':
-'yahoo.com':
-*/
-
-Application* application = NULL;
-
-int result_arrive = 0;
-
-using namespace std;
-class SearchListenerinherit : public SearchListener {
-public:
- std::string subject;
- void onStart()
- {
- printf("\nsubject = %s\n", subject.c_str());
- printf("\nSearch onStart");
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- }
- void onStop()
- {
- printf("\nsubject = %s\n", subject.c_str());
- printf("\nSearch onStop");
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- }
- void onFound(Service service)
- {
- printf("\nsubject = %s", subject.c_str());
- printf("\nSearch onFound");
- //fprintf(stderr,"\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- printf("\nservice name : %s\n", service.getName().c_str() ? service.getName().c_str() : "name is NULL");
- printf("\nservice uri : %s\n", service.getUri().c_str() ? service.getUri().c_str() : "uri is NULL");
- //fflush(stdout);
- fflush(stdout);
- }
- void onLost(Service service)
- {
- printf("\nsubject = %s", subject.c_str());
- printf("\nSearch onLost");
- printf("\nservice name : %s\n", service.getName().c_str() ? service.getName().c_str() : "name is NULL");
- fflush(stdout);
- //fprintf(stderr,"\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- }
-};
-
-class OnConnectListenerinherit:public OnConnectListener{
-public:
- std::string subject;
- void onConnect(Client client) {
- //string id=;
- //bool ishost =client.isHost();
- //int connecttime = client.getConnectTime();
- printf("\nsubject = %s", subject.c_str());
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- result_arrive = 1;
- }
-};
-class OnDisconnectListenerinherit:public OnDisconnectListener{
-public:
- std::string subject;
- void onDisconnect(Client client) {
- printf("\nsubject = %s", subject.c_str());
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- result_arrive = 1;
- }
-};
-class OnClientConnectListenerinherit:public OnClientConnectListener{
-public:
- Application* app;
-
- std::string subject;
- void onClientConnect(Client c) {
- printf("\nsubject = %s", subject.c_str());
- printf("\npublish hello to client %s\n", c.getId());
- fflush(stdout);
- const char* welcome = "hello welcome";
- unsigned char binary[5] = {'a', 'b', 'c', 'd', '\0'};
- app->publish("test_say", welcome, c, binary, 5);
-
- //fprintf(stderr,"\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- }
-};
-class OnClientDisconnectListenerinherit:public OnClientDisconnectListener{
-public:
- std::string subject;
- void onClientDisconnect(Client client) {
- printf("\nsubject = %s", subject.c_str());
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- }
-};
-class OnMessageListenerinherit:public OnMessageListener{
-public:
- std::string subject;
- void onMessage(Message mesg) {
- printf("\nsubject = %s\n", subject.c_str());
- printf("message: [event: %s] ", mesg.m_event.c_str());
- printf("[from: %s] ", mesg.m_from.c_str());
-
- printf("[msg: %s] ", mesg.m_data.c_str());
-
- printf("\n");
-
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- }
-};
-class OnErrorListenerinherit:public OnErrorListener{
-public:
- std::string subject;
- void onError(Client client) {
- printf("\nsubject = %s", subject.c_str());
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- result_arrive = 1;
- }
-};
-
-class ResultClient : public Result_Base
-{
-public:
- std::string subject;
- void onSuccess(Client abc)
- {
- printf("\nsubject = %s", subject.c_str());
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] ResultClient::onSuccess Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
-
- result_arrive = 1;
- }
- void onError(Error)
- {
- printf("\nsubject = %s", subject.c_str());
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] ResultClient::onError Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- result_arrive = 1;
- }
-};
-class ResultBool : public Result_Base
-{
-public:
- std::string subject;
- void onSuccess(bool abc)
- {
- printf("\nsubject = %s", subject.c_str());
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] ResultBool::onSuccess Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- result_arrive = 1;
- }
- void onError(Error e)
- {
- printf("\nsubject = %s", subject.c_str());
- printf("\nerror = %s", e.get_error_message());
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] ResultBool::onError Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- result_arrive = 1;
- }
-};
-class ResultService : public Result_Base
-{
-public:
- std::string subject;
- void onSuccess(Service abc)
- {
- printf("\nsubject = %s", subject.c_str());
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] ResultService::onSuccess Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- }
- void onError(Error)
- {
- printf("\nsubject = %s", subject.c_str());
- fprintf(stderr, "\n [MSF : API] ResultService::onError Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- }
-};
-class ResultDevice : public Result_Base
-{
-public:
- std::string subject;
- void onSuccess(Device d)
- {
- printf("\nsubject = %s\n", subject.c_str());
- fflush(stdout);
-
- printf("id : %s\n", d.getid().c_str());
- printf("countryCode : %s\n", d.getcountryCode().c_str());
- printf("description : %s\n", d.getdescription().c_str());
- printf("dduid : %s\n", d.getduid().c_str());
- printf("firmwareversion : %s\n", d.getfirmwareVersion().c_str());
- printf("ssid : %s\n", d.getssid().c_str());
- printf("ip : %s\n", d.getip().c_str());
- printf("model : %s\n", d.getmodel().c_str());
- printf("name : %s\n", d.getname().c_str());
- printf("networkType : %s\n", d.getnetworkType().c_str());
- printf("resolution : %s\n", d.getresolution().c_str());
- printf("udn : %s\n", d.getudn().c_str());
-
- fprintf(stderr, "\n [MSF : API] ResultDevice::onSuccess Debug log Function : [%s] and line [%d] in file [%s] and duid [%s] \n", __FUNCTION__, __LINE__, __FILE__, (d.getduid()).c_str());
- result_arrive = 1;
- }
- void onError(Error)
- {
- printf("\nsubject = %s\n", subject.c_str());
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] ResultDevice::onError Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- result_arrive = 1;
- }
-};
-class ResultApplicationInfo : public Result_Base
-{
-public:
- std::string subject;
- void onSuccess(ApplicationInfo abc)
- {
- printf("\nsubject = %s\n", subject.c_str());
- fflush(stdout);
-
- printf("app id : %s\n", abc.getID().c_str());
- printf("app name : %s\n", abc.getName().c_str());
- printf("app version : %s\n", abc.getVersion().c_str());
- printf("app running : %s\n", abc.isRunning() ? "true" : "false");
- fprintf(stderr, "\n [MSF : API] ResultApplicationInfo::onSuccess Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- result_arrive = 1;
- }
- void onError(Error)
- {
- printf("\nsubject = %s", subject.c_str());
- fflush(stdout);
- fprintf(stderr, "\n [MSF : API] ResultApplicationInfo::onError Debug log Function : [%s] and line [%d] in file [%s] \n", __FUNCTION__, __LINE__, __FILE__);
- result_arrive = 1;
- }
-};
-
-#if C_API
-int gl_connection_success = TIZEN_MSF_ERROR_NOT_ARRIVE;
-int gl_install_success = TIZEN_MSF_ERROR_NOT_ARRIVE;
-
-void device_info_cb(device_handle handle, int result)
-{
- printf("device_info_cb\n");
-}
-
-void service_found_cb(service_handle handle)
-{
- printf("service founded\n");
- get_device_info(handle, device_info_cb);
-}
-
-void service_lost_cb(service_handle handle)
-{
- printf("service lost\n");
-}
-
-void search_start_cb()
-{
- printf("search started\n");
-}
-
-void search_stop_cb()
-{
- printf("search stopped\n");
-}
-
-void app_connect_cb(client_handle handle)
-{
-}
-
-void app_disconnect_cb(client_handle handle)
-{
-}
-
-void app_client_connect_cb(client_handle handle)
-{
-}
-
-void app_client_disconnect_cb(client_handle handle)
-{
-}
-
-void app_message_cb(char* event, char* message, char* from, char* payld)
-{
- printf("message cb\n");
-
- if (event)
- printf("event = %s\n", event);
-
- if (message)
- printf("message = %s\n", message);
-
- if (from)
- printf("from = %s\n", from);
-}
-
-void app_error_cb()
-{
-}
-
-void connection_cb(int result, client_handle c_handle, error_handle e_handle)
-{
- printf("connection cb\n");
- gl_connection_success = result;
-}
-
-void install_cb(int result, error_handle e_handle)
-{
- gl_install_success = result;
-}
-
-#endif
-
-//Service service;
-Search search1;
-ResultDevice get_device_result;
-OnConnectListenerinherit connection_listener;
-ResultApplicationInfo result_applicationInfo;
-OnClientConnectListenerinherit client_connect_listener;
-OnClientDisconnectListenerinherit client_disconnect_listener;
-OnErrorListenerinherit error_listener;
-OnDisconnectListenerinherit disconnect_listener;
-ResultClient result_client_disconnect;
-ResultClient result_client_connect;
-ResultBool result_bool_install;
-OnMessageListenerinherit msg_listener1;
-OnMessageListenerinherit msg_listener2;
-ResultApplicationInfo appinfo;
-SearchListenerinherit search_listener1;
-SearchListenerinherit search_listener2;
-
-void Menu()
-{
- printf("\n===============================\n");
- printf("Start search ==> s\n");
- printf("Display service list ==> d\n");
- printf("Exit ==> Q\n");
- printf("===============================\n");
-}
-
-void display_service_list()
-{
- list<Service> services = search1.getServices();
-
- search1.stop();
- cout << "Length of services list is : ";
- cout << "" << services.size() << "\n";
-
- printf("service list:\n");
-
- int n = 1;
- for (std::list<Service>::iterator service = services.begin(); service != services.end(); service++) {
- printf("idx : %d, id : %s, name : %s, uri : %s\n", n++, (*service).getId().c_str(), (*service).getName().c_str(), (*service).getUri().c_str());
- }
-
-
- char c;
- cout << "\nEnter number to connect : \n";
- cin >> c;
-
- n = c - 48;
- int n2 = 1;
-
- for (std::list<Service>::iterator service = services.begin(); service != services.end(); service++) {
- if (n2 != n) {
- n2++;
- continue;
- }
-
- string appID = "http://www.google.com";
- //string appID = "org.tizen.netflix-app";
- //string appID = "http://multiscreen.samsung.com/app-sample-photos/tv/index.html";
- //string appID="111477001268";
- //string appID="11147700";
- //string appID = "youtube";
- //string channelId = "com.samsung.multiscreen.youtube";
- string channelId = "com.samsung.multiscreen.weblauncher";
-
- (*service).getDeviceInfo(&get_device_result);
- printf("wait deviceinfo arrive..");
- fflush(stdout);
-
- while (!result_arrive) {
- sleep(1);
- printf(".");
- fflush(stdout);
- }
- result_arrive = 0;
-
- application = new Application(&(*service), appID, channelId);
-
- application->setonConnectListener(&connection_listener);
- client_connect_listener.app = application;
- application->setonClientConnectListener(&client_connect_listener);
- application->setonClientDisconnectListener(&client_disconnect_listener);
- application->setonErrorListener(&error_listener);
- application->setonDisconnectListener(&disconnect_listener);
- application->addOnMessageListener("test_say", &msg_listener1);
- application->addOnAllMessageListener(&msg_listener2);
-
- application->set_connect_result(&result_client_connect);
- application->connect();
- printf("wait connect..\n");
- fflush(stdout);
-
- while (!result_arrive) {
- sleep(1);
- printf(".");
- fflush(stdout);
- }
- result_arrive = 0;
- //application->>setConnectionTimeout(5000000);
-
- //search.stop();
- //usleep(5000000);
- //usleep(5000000);
- //usleep(5000000);
- //Clients cl;
- //cl.create("5fc25160-1dd3-11b2-976d-7b60039367e0",557430,false);
- string ID = "90d105e0-1dd2-11b2-bffa-7536fc73d8d7";
- string event = "test_say";
- //Client c1=application->getclient(ID);
- //const char* messageData = "Hello !";
- //const char* messageData1="Hello sffffWorld!";
- //int messageData=12345;
- //char* target = "host";
-
- //Application installApplication=(*service).createApplication(appID, channelId);
- application->setonInstallListener(&result_bool_install);
- application->install();
- printf("wait install..\n");
- fflush(stdout);
- while (!result_arrive) {
- sleep(1);
- printf(".");
- fflush(stdout);
- }
- result_arrive = 0;
-
- //unsigned char a[6] = {'a','x', 'd', 'q', '3', 't'};
-
-
- //printf("publish message\n");
- //application->publish(event,messageData, a, 6);//,c1);
- //printf("wait message..\n");
- //fflush(stdout);
- //while (!result_arrive) {
- // sleep(1);
- // printf(".");
- //fflush(stdout);
- //}
- //result_arrive = 0;
- //application.publish(event,static_cast<void*>(messageData1));//,c1);
-
- //sleep(5);
- //printf("\n try disconnect\n");
-
- //search.stop();
-
-
-#if 0
- application->getinfo(&appinfo);
- printf("wait appinfo..\n");
- fflush(stdout);
- while (!result_arrive) {
- sleep(1);
- printf(".");
- fflush(stdout);
- }
- result_arrive = 0;
-#endif
-
-
-#if 0
- {
- bool isC = false;
- isC = application->isConnected();
- printf("connected = %s\n", isC ? "true" : "false");
- fflush(stdout);
- }
-
- {
- bool isW = false;
- isW = application->isWebapp();
- printf("webapp = %s\n", isW ? "true" : "false");
- fflush(stdout);
- }
-
-#endif
- // Clients Client test
- {
- Clients* cs = application->getclients();
-
- if (cs == NULL) {
- printf("No clients\n");
- } else {
- std::list<Client> cl = cs->lists();
- int cs_index = 0;
- Client cli;
- printf("clients size = %d\n", cs->size());
-
- for (auto cs_itr = cl.begin(); cs_itr != cl.end(); cs_itr++) {
- printf("client %d\n", cs_index++);
- printf("client id : %s\n", (*cs_itr).getId());
- printf("client clients.get().getId() : %s\n", cs->get((*cs_itr).getId()).getId());
- printf("client isHost : %s\n", (*cs_itr).isHost() ? "true" : "false");
- printf("client connectTIme : %lld\n", (*cs_itr).getConnectTime());
- Client* host = cs->getHost();
- printf("host = %s\n", host ? host->getId() : "no host");
- Channel* cha = NULL;
- cha = (*cs_itr).getChannel();
- if (cha != NULL)
- printf("client channel uri = %s\n", cha->getChannelUri(NULL).c_str());
- //printf("clients channel uri = %s\n", cs->getChannel()->getChannelUri(NULL).c_str());
- printf("channel uri : %s\n", application->getChannelUri(NULL).c_str());
- }
-
-
- application->publish(event, "Hello Im newbe", cl);//,c1);
- }
- }
-
- {
- cout << "\nEnter a to disconnect : \n";
- cin >> c;
-
- application->set_disconnect_result(&result_client_disconnect);
- application->disconnect(true);
- printf("wait disconnect..\n");
- fflush(stdout);
- while (!result_arrive) {
- sleep(1);
- printf(".");
- fflush(stdout);
- }
- result_arrive = 0;
- }
-
- exit(0);
- }
-}
-
-int test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
-{
- get_device_result.subject = "getDeviceInfo";
- connection_listener.subject = "connect_listen";
- result_applicationInfo.subject = "appinfo";
- client_connect_listener.subject = "client_connect_listen";
- client_disconnect_listener.subject = "client_disconnect_listen";
- error_listener.subject = "error_listen";
- disconnect_listener.subject = "disconnect_listen";
- result_client_connect.subject = "connect_result";
- result_client_disconnect.subject = "disconnect_result";
- result_bool_install.subject = "install_result";
- msg_listener1.subject = "msg_listener 1";
- msg_listener2.subject = "msg_listener 2";
- appinfo.subject = "app info";
- search_listener1.subject = "search_listener1";
- search_listener2.subject = "search_listener2";
-
-
- search1.setSearchListener(&search_listener1);
-
- int rv;
- char a[10];
- GMainLoop *mainloop = reinterpret_cast<GMainLoop*>(data);
-
- printf("Event received from stdin\n");
-
- rv = read(0, a, 10);
- if (rv <= 0) {
- printf("read result error : %d\n", rv);
- rv = 1;
- }
-
- if (a[0] == '\n' || a[0] == '\r') {
- printf("Press ENTER to show options menu.......\n");
- Menu();
- }
-
- switch (a[0]) {
- case 's':
- search1.start();
- break;
- case 'd':
- display_service_list();
- break;
- case 'Q':
- g_main_loop_quit(mainloop);
- break;
- default :
- return true;
- }
-
- if (rv >= 1)
- printf("\nOperation Succeeded!\n");
- else
- printf("\nOperation Failed!\n");
-
- return TRUE;
-}
-
-
-int main(int argc, char** argv) {
- GMainLoop *mainloop;
- mainloop = g_main_loop_new(NULL, FALSE);
-
- GIOChannel *channel = g_io_channel_unix_new(0);
- g_io_add_watch(channel, static_cast<GIOCondition>(G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL),
- test_thread, mainloop);
-
- printf("Test Thread created...\n");
-
- g_main_loop_run(mainloop);
-
- printf("Test Application Terminated\n");
- g_main_loop_unref(mainloop);
-
- return 0;
-}
BuildRequires: pkgconfig(argos_watchdog)
BuildRequires: pkgconfig(aul)
BuildRequires: pkgconfig(libtzplatform-config)
-BuildRequires: pkgconfig(gio-2.0)
-BuildRequires: pkgconfig(json-glib-1.0)
-BuildRequires: pkgconfig(libwebsockets)
-BuildRequires: pkgconfig(openssl)
-BuildRequires: curl
-BuildRequires: libcurl-devel
-BuildRequires: capi-network-nsd
-BuildRequires: capi-network-nsd-devel
Requires: dbus
#Requires(post): sys-assert
Requires: syspopup
/usr/share/license/%{name}
%files devel
-
-%package -n msf-api
-Summary: Msf-api Shared Library (Development)
-Group: System/Libraries
-
-%description -n msf-api
-msf-api Shared Library (DEV)
-
-%post -n msf-api
-/sbin/ldconfig
-
-%postun -n msf-api
-/sbin/ldconfig
-
-%files -n msf-api
-%manifest remote-server.manifest
-%defattr(-,root,root,-)
-%{_libdir}/libmsf-api.so*
-/usr/bin/msf-api-test*
-
-%package -n msf-api-devel
-Summary: Msf-api Shared Library (Development)
-Group: System/Libraries
-
-%description -n msf-api-devel
-msf-api Shared Library (DEV)
-
-%post -n msf-api-devel
-/sbin/ldconfig
-
-%postun -n msf-api-devel
-/sbin/ldconfig
-
-%files -n msf-api-devel
-%defattr(-,root,root,-)
-%{_includedir}/msf-api/*.h
-%{_libdir}/libmsf-api.so*
-%{_libdir}/pkgconfig/msf-api.pc