OSDN Git Service

2011/10/29 21:57:54
authorqwerty2501 <riot313@gmail.com>
Sat, 29 Oct 2011 12:57:54 +0000 (21:57 +0900)
committerqwerty2501 <riot313@gmail.com>
Sat, 29 Oct 2011 12:57:54 +0000 (21:57 +0900)
JSONParser/json_parser.c
nlib/nlib.h
nlib/nlib_myList.c
nlib/nlib_nicoLive.c
nlib/nlib_nicoLive.h
nlib_driver/nlib_driver.cpp

index 4ba6dd2..8b7b9d1 100644 (file)
@@ -197,7 +197,7 @@ static JSONResult JSONParser_ParseUTF8(JSONParser_P parser,const JSONText *jsont
 
                parser->structHandler(parser->option,JSONTypeRoot,JSONTypeObject,NULL);
 
-               ParseObjectUTF8(parser,jsontext,&jsontext);
+               rslt = ParseObjectUTF8(parser,jsontext,&jsontext);
 
                parser->dataEndHandler(parser->option,JSONTypeRoot,JSONTypeObject,NULL);
 
@@ -208,7 +208,7 @@ static JSONResult JSONParser_ParseUTF8(JSONParser_P parser,const JSONText *jsont
 
                parser->structHandler(parser->option,JSONTypeRoot,JSONTypeArray,NULL);
 
-               ParseArrayUTF8(parser,jsontext,&jsontext);
+               rslt = ParseArrayUTF8(parser,jsontext,&jsontext);
 
                parser->dataEndHandler(parser->option,JSONTypeRoot,JSONTypeArray,NULL);
 
index 45ad1e8..2153a3d 100644 (file)
@@ -44,10 +44,6 @@ typedef UINT_PTR             NICOLIVE_PARAM;
 
 
 
-///
-///nlib\82Ì\90Ý\92è\83I\83u\83W\83F\83N\83g\83|\83C\83\93\83^
-///
-//typedef struct nlibproperty_t *NlibProperty_P;
 
 ///
 ///\83j\83R\83j\83R\90\95ú\91\97\83I\83u\83W\83F\83N\83g\83|\83C\83\93\83^
@@ -101,7 +97,7 @@ typedef NLIB_RESULT (*NicoRecvCallBack)(NICOLIVE_EVENT eventType,NicoLiveStream_
 ///
 ///\83j\83R\83j\83R\83}\83C\83\8a\83X\83g\83C\83x\83\93\83g\83n\83\93\83h\83\89
 ///
-typedef NLIB_RESULT (*NicoMyListCallBack)(LPVOID option,NicoMyListItem_P pVideo,DWORD code);
+typedef NLIB_RESULT (*NicoMyListCallBack)(LPVOID option,NicoMyListItem_P pVideo,NLIB_RESULT rslt);
 
 
 
index ae563a2..2f4bf2f 100644 (file)
@@ -37,7 +37,7 @@ static JSONVoid myListItemDataEndEventHandler(JSONVoid *option,JSONUInt thisHier
 
 static VOID CALLBACK myListItemCallBack(HINTERNET handle,DWORD_PTR context,DWORD code,LPVOID info,DWORD length);
 
-static NLIB_RESULT recvMyList(HINTERNET hGetMyList,NicoMyListItemContainer_P itemContainer);
+static NLIB_RESULT recvMyList(HINTERNET hGetMyList,NicoMyListItemContainer_P itemContainer,NLIB_RESULT rslt);
 
 ///
 ///\82Æ\82è\82 \82¦\82¸\83}\83C\83\8a\83X\83g\88ê\97\97\8eæ\93¾
@@ -46,7 +46,7 @@ NLIB_RESULT NicoMyList_getDefList(NicoVideoAuth_P pAuth,NicoMyListCallBack callb
 
        NLIB_RESULT rslt = NLIB_ERR_OK;
 
-       rslt = NicoMyList_getList(pAuth,L"api/deflist/list",callback,mtFlag);
+       rslt = NicoMyList_getList(pAuth,L"api/deflist/list",callback,mtFlag,option);
        
 
 
@@ -103,7 +103,7 @@ static NLIB_RESULT NicoMyList_getList(NicoVideoAuth_P pAuth,LPCWSTR objectName,N
 
        if(mtFlag == FALSE){
 
-               rslt = recvMyList(hGetMyList,&itemContainer);
+               rslt = recvMyList(hGetMyList,&itemContainer,NLIB_ERR_OK);
 
        }
 
@@ -124,9 +124,9 @@ static VOID CALLBACK myListItemCallBack(HINTERNET handle,DWORD_PTR context,DWORD
 
 }
 
-static NLIB_RESULT recvMyList(HINTERNET hGetMyList,NicoMyListItemContainer_P itemContainer){
+static NLIB_RESULT recvMyList(HINTERNET hGetMyList,NicoMyListItemContainer_P itemContainer,NLIB_RESULT rslt){
 
-       NLIB_RESULT rslt;
+       
 
        const UINT_PTR readBufSize = LENGTH_65536 * 30;
 
@@ -169,7 +169,7 @@ static NLIB_RESULT recvMyList(HINTERNET hGetMyList,NicoMyListItemContainer_P ite
 
        readBuffer[readSize] = '\0';
 
-       if(JSONParser_Parse(jsonParser,readBuffer,JSON_ENCODE_UTF8,&itemContainer) != JSON_ERR_OK){
+       if(JSONParser_Parse(jsonParser,readBuffer,JSON_ENCODE_UTF8,itemContainer) != JSON_ERR_OK){
 
                goto jsonerr;
        }
index 19945f2..6068e8e 100644 (file)
@@ -61,44 +61,6 @@ static CRITICAL_SECTION heartBeatCs;
        }\
        (convPtr)[0] = L'\0'
 
-
-/*
-#define convertTEXT(buf,basePtr,convPtr,endPtr)\
-       (buf) = (convPtr);\
-       for(;(basePtr) < (endPtr);(basePtr)++){\
-               switch(basePtr[0]){\
-               case L'&':\
-                       strcpy((convPtr),"&amp;");\
-                       (convPtr) += strlen(convPtr);\
-                       break;\
-               case L'<':\
-                       strcpy((convPtr),"&lt;");\
-                       (convPtr) += strlen(convPtr);\
-                       break;\
-               case L'>':\
-                       strcpy((convPtr),"&gt;");\
-                       (convPtr) += strlen(convPtr);\
-                       break;\
-               case L'\"':\
-                       strcpy((convPtr),"&quot;");\
-                       (convPtr) += strlen(convPtr);\
-                       break;\
-               case L'\'':\
-                       strcpy((convPtr),"&apos;");\
-                       (convPtr) += strlen(convPtr);\
-                       break;\
-               default:\
-                       WideCharToMultiByte(CP_UTF8,0,(basePtr),1,(convPtr),LENGTH_1024,(LPCSTR)NULL,(LPBOOL)NULL);\
-                       (convPtr) += strlen(convPtr);\
-                       break;\
-               }\
-       }\
-       (convPtr)[0] = '\0'
-*/
-                       
-
-
-
 #define getBaseVpos(server_time,base_time)     (((server_time) - (base_time)) * 100)
 
 #define setMsec(mSec)\
@@ -166,11 +128,18 @@ static unsigned int WINAPI  NicoLiveHeartBeatThread(void* lpBuffer);
 ///
 static unsigned int WINAPI  NicoLiveKeapALiveThread(void* lpBuffer);
 
+
+
+
 ///
 ///\83`\83\83\83b\83g\8eó\90M\83\8b\81[\83v\8aÖ\90\94
 ///
 static BOOL NicoLiveRecvChatLoop(NicoLiveStream_P self);
 
+///
+///\83\8b\81[\83v
+///
+static unsigned int loopCommon(NicoLiveStream_P self,WSAEVENT sendEvent,WSAEVENT resetEvent ,NicoLiveOnSend nicoLiveOnSend);
 
 ///
 ///\83R\83\81\83\93\83g\89ð\90Í\8aÖ\90\94
@@ -180,6 +149,10 @@ static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_P
 static void NicoLiveError(void *buf);
 
 static void NicoLiveSelfDisconnect(void *buf);
+
+static VOID OnSendHeartBeat(NicoLiveStream_P self);
+
+static VOID OnSendKeepAllive(NicoLiveStream_P self);
 ///
 ///\83\\83P\83b\83g\8eæ\93¾\8aÖ\90\94
 ///
@@ -238,6 +211,21 @@ NicoLiveStream_P NicoLiveStream_new(){
        //\90\90¬&\8f\89\8aú\89»
        NicoLiveStream_P self = (NicoLiveStream_P)calloc(1,sizeof(NicoLiveStream));
 
+       //\8f\89\8aú\92l\82Ì\90Ý\92è
+       self->chatManager.onHeartBeatSend = OnSendHeartBeat;
+
+       self->chatManager.onKeepAlliveSend = OnSendKeepAllive;
+
+       InitializeCriticalSection(&self->sessionManager.cs);
+
+       self->chatManager.heartBeatTime = 300000;
+
+       self->chatManager.heartBeatFlag = TRUE;
+
+       self->chatManager.keepAliveTime = 300000;
+
+       self->chatManager.keapALiveFlag = TRUE;
+
        self->chatManager.endEvent = WSACreateEvent();
 
        self->chatManager.startEvent = WSACreateEvent();
@@ -254,21 +242,22 @@ NicoLiveStream_P NicoLiveStream_new(){
 
        self->chatManager.resetEvents[2] = WSACreateEvent();
 
+
+
+
+
+       //\83X\83\8c\83b\83h\82Ì\8aJ\8en
        self->chatManager.hRecvChatHandle = (HANDLE)_beginthreadex(NULL,0,NicoLiveRecvChat,self,0,&self->chatManager.recvChatThreadID);
 
        self->chatManager.hHeartBeatHandle = (HANDLE)_beginthreadex(NULL,0,NicoLiveHeartBeatThread,self,0,&self->chatManager.heartBeatThreadID);
 
        self->chatManager.hKeapALiveHandle = (HANDLE)_beginthreadex(NULL,0,NicoLiveKeapALiveThread,self,0,&self->chatManager.keapALiveThreadID);
 
-       self->chatManager.heartBeatTime = 300000;
-
-       self->chatManager.heartBeatFlag = TRUE;
 
-       self->chatManager.keepAliveTime = 300000;
 
-       self->chatManager.keapALiveFlag = TRUE;
+       
 
-       InitializeCriticalSection(&self->sessionManager.cs);
+       
 
        dumpln(TEXT("size%d"),sizeof(NicoLiveStream));
 
@@ -1335,99 +1324,39 @@ static unsigned int WINAPI  NicoLiveKeapALiveThread(void* lpBuffer){
 
        NicoLiveStream_P self = (NicoLiveStream_P)lpBuffer;
 
-       WSAEVENT events[3] = {self->chatManager.deleteEvent,self->chatManager.startEvent,self->chatManager.endEvent};   //\83C\83x\83\93\83g\94z\97ñ
-       WSAEVENT streamEvent[2] = {self->chatManager.endEvent,self->chatManager.setKeepAliveTimeEvent};
-       DWORD dwResult;                                                                                                                                                                                                 //\83C\83x\83\93\83g\8eó\90M\8c\8b\89Ê
-       DWORD endResult;
-
-       while(TRUE){
-restart:
-               WSASetEvent(self->chatManager.resetEvents[2]);
-
-               dwResult = WSAWaitForMultipleEvents(sizeof(events) / sizeof(events[0]),events,FALSE,WSA_INFINITE,FALSE);
-
-
-               //\83G\83\89\81[\82Ì\8fê\8d\87
-               if(dwResult == WSA_WAIT_FAILED){
-
-                       goto err;
-               }
-
-
-               switch(dwResult - WSA_WAIT_EVENT_0){
+       rslt = loopCommon(self,self->chatManager.setKeepAliveTimeEvent,self->chatManager.resetEvents[2],self->chatManager.onKeepAlliveSend);
 
-               case 0:
-
-                       goto end;
-
-               case 1:
-                       WSAResetEvent(self->chatManager.resetEvents[2]);
-                       break;
-
-               case 2:
-                       continue;
-
-
-               default:
-
-                       goto err;
-
-               }
-
-               while(TRUE){
-                       WSAResetEvent(self->chatManager.setKeepAliveTimeEvent);
-                       endResult = WSAWaitForMultipleEvents(sizeof(streamEvent) / sizeof(streamEvent[0]),streamEvent,FALSE,self->chatManager.keepAliveTime,FALSE);
-
-                       if(endResult == WSA_WAIT_TIMEOUT){
+       _endthreadex(rslt);
 
-                               if(self->chatManager.keapALiveFlag){
-                                       LPCWSTR mail[2] = {L"184",NULL};
-                                       NicoLiveStream_sendChat(self,L"/keapalive",mail,NULL);
-                               }
-                       }  else{ 
-                               switch(endResult - WSA_WAIT_EVENT_0){
+       return rslt;
+}
 
-                               case 0:
-                                       goto restart;
+static unsigned int WINAPI  NicoLiveHeartBeatThread(void* lpBuffer){
 
-                               case 1:
-                                       break;
+       unsigned int rslt = 0;
 
-                               default:
-                                       goto err;
+       NicoLiveStream_P self = (NicoLiveStream_P)lpBuffer;
 
-                               }
-                       }
-               }
 
+       rslt = loopCommon(self,self->chatManager.setHeartBeatTimeEvent,self->chatManager.resetEvents[1],self->chatManager.onHeartBeatSend);
 
 
-       }
-
-err:
-       _beginthread(NicoLiveError,0,self);
-
-end:
 
        _endthreadex(rslt);
 
        return rslt;
 }
+static unsigned int loopCommon(NicoLiveStream_P self,WSAEVENT sendEvent,WSAEVENT resetEvent ,NicoLiveOnSend nicoLiveOnSend){
 
-static unsigned int WINAPI  NicoLiveHeartBeatThread(void* lpBuffer){
-
-       unsigned int rslt = 0;
-
-       NicoLiveStream_P self = (NicoLiveStream_P)lpBuffer;
-
+       unsigned int rslt;
        WSAEVENT events[3] = {self->chatManager.deleteEvent,self->chatManager.startEvent,self->chatManager.endEvent};   //\83C\83x\83\93\83g\94z\97ñ
-       WSAEVENT streamEvent[2] = {self->chatManager.endEvent,self->chatManager.setHeartBeatTimeEvent};
+       WSAEVENT streamEvent[2] = {self->chatManager.endEvent,sendEvent};
        DWORD dwResult;                                                                                                                                                                                                 //\83C\83x\83\93\83g\8eó\90M\8c\8b\89Ê
        DWORD endResult;
 
        while(TRUE){
 restart:
-               WSASetEvent(self->chatManager.resetEvents[1]);
+               WSASetEvent(resetEvent);
                
                dwResult = WSAWaitForMultipleEvents(sizeof(events) / sizeof(events[0]),events,FALSE,WSA_INFINITE,FALSE);
 
@@ -1446,7 +1375,7 @@ restart:
                        goto end;
 
                case 1:
-                       WSAResetEvent(self->chatManager.resetEvents[1]);
+                       WSAResetEvent(resetEvent);
                        break;
 
                case 2:
@@ -1460,14 +1389,15 @@ restart:
                }
 
                while(TRUE){
-                       WSAResetEvent(self->chatManager.setHeartBeatTimeEvent);
+                       WSAResetEvent(sendEvent);
                        endResult = WSAWaitForMultipleEvents(sizeof(streamEvent) / sizeof(streamEvent[0]),streamEvent,FALSE,self->chatManager.heartBeatTime,FALSE);
 
                        if(endResult == WSA_WAIT_TIMEOUT){
 
-                               if(self->chatManager.heartBeatFlag){
-                                       NicoLiveStream_sendHeartBeat(self);
-                               }
+                               nicoLiveOnSend(self);
+                               //dumpln(TEXT("onSend"));
+
+                               _heapmin();
                        } else{ 
                                switch(endResult - WSA_WAIT_EVENT_0){
 
@@ -1488,16 +1418,31 @@ restart:
 
        }
 
+end:
+       return rslt;
+
 err:
        _beginthread(NicoLiveError,0,self);
+       rslt = 1;
+       goto end;
+}
 
-end:
+static VOID OnSendHeartBeat(NicoLiveStream_P self){
 
-       _endthreadex(rslt);
+       if(self->chatManager.heartBeatFlag){
+               NicoLiveStream_sendHeartBeat(self);
+       }
 
-       return rslt;
 }
 
+static VOID OnSendKeepAllive(NicoLiveStream_P self){
+       
+       if(self->chatManager.keapALiveFlag){
+               LPCWSTR mail[2] = {L"184",NULL};
+               NicoLiveStream_sendChat(self,L"/keapalive",mail,NULL);
+       }
+
+}
 
 #define NICOLIVE_RECEVE_CHAT_LENGTH    LENGTH_2048
 #define NICOLIVE_REQUEST_CHAT_LENGTH   LENGTH_256
@@ -1637,6 +1582,9 @@ end:
 }
 
 
+
+
+
 static BOOL NicoLiveRecvChatLoop(NicoLiveStream_P self){
 
 
@@ -1753,6 +1701,8 @@ end:
 }
 
 
+
+
 static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_PTR endSize,LPWSTR* mailCountBuf,SIZE_T* mailCountBufSize,SIZE_T* commentCountSum,SIZE_T* commentBufSize){
 
        LPWSTR indexPtr;                                                                                //\89ð\90Í\8e\9e\82Ì\8ew\95W\83|\83C\83\93\83^
@@ -2043,6 +1993,8 @@ static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_P
 
 }
 
+
+
 static void NicoLiveError(void *buf){
 
        NicoLiveStream_P nl = (NicoLiveStream_P)buf;
index 4b42b80..c6b073a 100644 (file)
@@ -8,6 +8,7 @@
 
 typedef UINT_PTR PROVIDERTYPE;
 
+typedef VOID(*NicoLiveOnSend)(NicoLiveStream_P self);
 
 //
 //\83j\83R\83j\83R\90\95ú\91\97\83I\83u\83W\83F\83N\83g
@@ -63,9 +64,11 @@ typedef struct {
        WSAEVENT setHeartBeatTimeEvent;
        DWORD heartBeatTime;
        BOOL heartBeatFlag;
+       NicoLiveOnSend onHeartBeatSend;
        WSAEVENT setKeepAliveTimeEvent;
        DWORD keepAliveTime;
        BOOL keapALiveFlag;
+       NicoLiveOnSend onKeepAlliveSend;
        WSAEVENT deleteEvent;
        WSAEVENT startEvent;
        WSAEVENT  endEvent;
index b23c7e0..52dd688 100644 (file)
@@ -161,7 +161,7 @@ NLIB_RESULT callback(NICOLIVE_EVENT eventType,NicoLiveStream_P pNicoLiveStream,L
        return 0;
 }
 
-NLIB_RESULT myListCallBack(LPVOID option,NicoMyListItem_P pVideo){
+NLIB_RESULT myListCallBack(LPVOID option,NicoMyListItem_P pVideo,NLIB_RESULT rslt){
 
 
 
@@ -178,8 +178,8 @@ void nicoLive_connect(void) {
        
 
        SetResFrom(1000);
-       NicoLiveStream_setHeartBeatMsec(nl,1);
-       NicoLiveStream_setKeapALiveMsec(nl,1);
+       NicoLiveStream_setHeartBeatMsec(nl,5000);
+       NicoLiveStream_setKeapALiveMsec(nl,5000);
        //NicoLiveStream_setKeapALiveFlag(nl,FALSE);
        
        //CU_ASSERT_EQUAL(NicoLiveStream_connect(nl,nva,L"lv66406941",callback,NULL), NLIB_ERR_OK);
@@ -210,7 +210,7 @@ void nicoLive_connect(void) {
                NicoLiveStream_disConnect(nl);
        }
        
-
+       CU_ASSERT_EQUAL(_heapchk(),_HEAPOK);
        
        //Sleep(3000);
 
@@ -232,7 +232,9 @@ void nicoLive_mylist(void) {
 
        
 
-       CU_ASSERT_EQUAL(NicoMyList_getDefList(nva,myListCallBack), NLIB_ERR_OK);
+       CU_ASSERT_EQUAL(NicoMyList_getDefList(nva,myListCallBack,FALSE,NULL), NLIB_ERR_OK);
+       check(_heapchk() == _HEAPOK,TEXT("heap\83G\83\89\81[\82Å\82·"));
+       dumpln(TEXT("heapchk:%d"),_heapchk());
 
 
 }