Skip to content

Commit

Permalink
做了部分注释,在sub_client.c中信息到来回调函数中添加打印,其中lib/mosquitto_broker.h和lib/uthas…
Browse files Browse the repository at this point in the history
…h.h由于原来

lib/路径下没有而copy过来的,它们都是因为修改sub_client才做的修改,还要注意src/subs.c中的修改,服务端也有相
应的打印,不过暂时还没有分析出其中的头绪
  • Loading branch information
zengang committed Oct 30, 2014
1 parent f84c52f commit 7476581
Show file tree
Hide file tree
Showing 19 changed files with 1,490 additions and 12 deletions.
Binary file modified client/mosquitto_sub
Binary file not shown.
51 changes: 51 additions & 0 deletions client/sub_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ POSSIBILITY OF SUCH DAMAGE.
#endif

#include <mosquitto.h>
#include <mosquitto_broker.h>
#include <mosquitto_internal.h>

/* This struct is used to pass data to callbacks.
* An instance "ud" is created in main() and populated, then passed to
Expand All @@ -65,10 +67,59 @@ void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquit
int i;
bool res;

#ifdef WITH_BROKER
struct mosquitto_client_msg *clientMsg; //allan adds for test
struct mosquitto_msg_store *msgStore; //allan adds for test
#else
struct mosquitto_message_all *clientMsg;
#endif
assert(obj);
ud = (struct userdata *)obj;

if(message->retain && ud->no_retain) return;



printf("userdata:topic:%s,topic count:%d, qos:%d,filreroutcount:%d, username:%s,verbose:%d,quiet:%d,no_retain:%d,eol:%d\n",ud->topics,\
ud->topic_count, ud->topic_qos, ud->filter_out_count, ud->username,ud->verbose, ud->quiet,ud->no_retain, ud->eol);
#ifdef WITH_BROKER

clientMsg = (struct mosquitto_client_msg *)malloc(sizeof(struct mosquitto_client_msg) );
msgStore = (struct mosquitto_msg_store *)malloc(sizeof(struct mosquitto_msg_store ) );
clientMsg = mosq->msgs;
while(clientMsg)
{
printf("mosq->msg:mid:%d,qos:%d,retain:%d, timestamp:%d,dup:%d,dir:%d, state:%d\n", clientMsg->mid,clientMsg->qos,clientMsg->retain,\
(int)clientMsg->timestamp, clientMsg->dup, clientMsg->direction, clientMsg->state);
msgStore = mosq->msgs->store;
while(msgStore)
{
printf("mosq->msgs->store: db_id:%ld, ref_count:%d, source_id:%s,destIDcount:%d,mid:%d\n",msgStore->db_id,msgStore->ref_count,\
msgStore->source_id, msgStore->dest_id_count, msgStore->source_id);
printf("mosq->msgs->store->msg: mid:%d, topic:%s, paload:%s, payloadlen:%d, qos:%d, retain:%d\n",msgStore->msg.mid, msgStore->msg.topic,\
msgStore->msg.payload, msgStore->msg.payloadlen, msgStore->msg.qos, msgStore->msg.retain);
msgStore = msgStore->next;
}
clientMsg = clientMsg->next;
printf("next message!\n\n");
}

printf("printf finished!\n");
#else

clientMsg = (struct mosquitto_message_all *)malloc(sizeof(struct mosquitto_message_all) );
while(clientMsg)
{
printf("timestamp:%d, state:%d, dup:%d\n",clientMsg->timestamp, (int)clientMsg->state, clientMsg->dup);
printf("msg:mid:%d,topic:%s,payload:%s,length:%d,qos:%d,retain:%d\n",clientMsg->msg.mid,clientMsg->msg.topic,clientMsg->msg.payload,\
clientMsg->msg.payloadlen,clientMsg->msg.qos,clientMsg->msg.retain);
clientMsg = clientMsg->next;
}



#endif

if(ud->filter_outs){
for(i=0; i<ud->filter_out_count; i++){
mosquitto_topic_matches_sub(ud->filter_outs[i], message->topic, &res);
Expand Down
Binary file modified client/sub_client.o
Binary file not shown.
19 changes: 19 additions & 0 deletions lib/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* ============================================================
* Control compile time options.
* ============================================================
*
* Compile time options have moved to config.mk.
*/


/* ============================================================
* Compatibility defines
*
* Generally for Windows native support.
* ============================================================ */
#ifdef WIN32
#define snprintf sprintf_s
#define strcasecmp strcmpi
#define strtok_r strtok_s
#define strerror_r(e, b, l) strerror_s(b, l, e)
#endif
Binary file modified lib/libmosquitto.a
Binary file not shown.
Loading

0 comments on commit 7476581

Please sign in to comment.