Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 23 files changed
  • 0 comments
  • 2 contributors
8 LuaScript/StreamInitialize.lua
@@ -33,14 +33,12 @@ function streamInitialize(account_id)
33 33 do return false end
34 34 end
35 35
36   - url = "https://talkgadget.google.com/talkgadget/channel/bind?VER=8&"
  36 + url = "https://talkgadget.google.com/u/0/talkgadget/_/channel/bind?VER=8&"
37 37 url = url .. "clid=" .. clid .. "&gsessionid=" .. gsessionid .. "&prop=homepage&ujidr=TalkGadget" .. talkgadget_number .. "&"
38 38 url = url .. "eid&ec=" .. Connection.escapeString("[0,0,0]") .. "&RID=" .. generateRIDValue() .. "&CVER=1&zx=" .. generateZxString() .. "&t=1"
39 39
40 40 response = connection:httpPost(url, "count=0")
41 41 response_body = response:getResponseBody()
42   - print("res:" .. response_body)
43   - print("first")
44 42
45 43 json = connection:convertResponseToJson(response_body)
46 44
@@ -67,7 +65,7 @@ function streamInitialize(account_id)
67 65
68 66 print("Stream connecting ...")
69 67
70   - url = "https://talkgadget.google.com/talkgadget/channel/bind?VER=8&clid=" .. clid .. "&gsessionid=" .. gsessionid .. "&"
  68 + url = "https://talkgadget.google.com/u/0/talkgadget/_/channel/bind?VER=8&clid=" .. clid .. "&gsessionid=" .. gsessionid .. "&"
71 69 url = url .. "prop=homepage&ujidr=TalkGadget" .. talkgadget_number .. "&eid&ec=" .. Connection.escapeString("[0,0,0]") .. "&"
72 70 url = url .. "SID=" .. sid .. "&RID=" .. generateRIDValue() .. "&AID=2&zx=" .. generateZxString() .. "&t=1"
73 71
@@ -116,8 +114,6 @@ function streamInitialize(account_id)
116 114
117 115 response = connection:httpPost(url, parameter)
118 116 response_body = response:getResponseBody()
119   - print(response_body)
120   - print("second")
121 117
122 118 -- start updating
123 119
152 LuaScript/StreamLoopUpdate.lua
@@ -44,18 +44,13 @@ function streamLoopUpdate(account_id)
44 44 do return false end
45 45 end
46 46
47   - connection = Connection()
48   - connection:setCurrentAccountID(account_id)
49   -
50   - url = "https://talkgadget.google.com/talkgadget/channel/bind?VER=8&clid=" .. clid .. "&gsessionid=" .. gsessionid .. "&"
  47 + url = "https://talkgadget.google.com/u/0/talkgadget/_/channel/bind?VER=8&clid=" .. clid .. "&gsessionid=" .. gsessionid .. "&"
51 48 url = url .. "prop=homepage&ujidr=TalkGadget" .. talkgadget_number .. "&eid&ec=" .. Connection.escapeString("[0,0,0]") .. "&"
52 49 url = url .. "RID=rpc&SID=" .. sid .. "&CI=0&AID=" .. aid .. "&TYPE=xmlhttp&zx=" .. generateZxString() .. "&t=1"
53 50
54   - response = connection:httpGet(url, false)
55   -
56   - response_body = response:getResponseBody()
  51 + stream_observer = StreamObserver()
57 52
58   - print("response_body:" .. response_body)
  53 + response = stream_observer:get(account_id, url)
59 54
60 55 status = response:getStatusCode()
61 56 if(status ~= 200) then
@@ -63,146 +58,5 @@ function streamLoopUpdate(account_id)
63 58 do return false end
64 59 end
65 60
66   - json = connection:convertResponseToJson(response_body)
67   - if(json == nil) then
68   - print("json == nil")
69   - end
70   -
71   - --print("Json Count:" .. json:count())
72   -
73   - for count = 0, json:count(), 1 do
74   -
75   - --print("count:" .. count)
76   - --print("aid" .. aid)
77   - child_json = json:selectChildNode(count)
78   -
79   - if(child_json:isNull()) then
80   - do return true end
81   - end
82   -
83   - --print("Json:" .. child_json:selectChildNode("[1].[0]"):asString())
84   - --[[
85   - if(child_json:selectChildNode("[1].[0]"):asString() == "noop") then
86   -
87   - if(aid == "0") then
88   - print("Connect Error")
89   - do return false end
90   - elseif(aid == "1") then
91   - print("Connect Error")
92   - do return false end
93   - elseif(aid == "2") then
94   - print("Connect Error")
95   - do return false end
96   - elseif(aid == "3") then
97   - print("Connect Error")
98   - do return false end
99   - elseif(aid == "4") then
100   - print("Connect Error")
101   - do return false end
102   - elseif(aid == "5") then
103   - print("Connect Error")
104   - do return false end
105   - end
106   - print("noop aid=" .. aid)
107   - break
108   - end
109   - ]]
110   - type = child_json:selectChildNode("[1].[1].[1].[0]"):asString()
111   - --print("type:" .. type)
112   - if(child_json:selectChildNode("[1].[0]"):asString() == "c") then
113   - if(type == "ei") then
114   - print("update gsessionid")
115   - gsessionid = child_json:selectChildNode("[1].[1].[1].[1]"):asString()
116   - --print("gsessionid=" .. gsessionid)
117   -
118   - aid = aid + 1
119   - InformationContainer.addInformationByAccountID("aid", aid, account_id)
120   - break
121   -
122   - end
123   -
124   - end
125   - --[[
126   - if(type == nil) then
127   - print("type=nil")
128   - else
129   - print("type=" .. type)
130   - end
131   - ]]
132   - if(type == "tu") then
133   -
134   - -- invalid json string
135   - valid_json = Utility.convertStringEscapedJson(child_json, "[1].[1].[1].[1]")
136   - sub_type = valid_json:selectChildNode("[0]"):asString()
137   -
138   - if(sub_type == nil) then
139   - print("sub_type=nil")
140   - else
141   - --print("sub_type=" .. sub_type)
142   -
143   - if(sub_type == "t.rtu") then
144   - --print(response_body)
145   - PostParser.add(valid_json)
146   - name = valid_json:selectChildNode("[1].[3]"):asString()
147   - if(isStringNullOrEmpty(name) == nil) then
148   - --print("sub_type=".. sub_type .. " name == nil")
149   - else
150   - --print(account_id .. ":" .. name .. "さんが投稿をポストしたり編集したりしました")
151   - end
152   - end
153   -
154   - if(sub_type == "t.rtc") then
155   - --print(response_body)
156   - CommentParser.add(valid_json)
157   - name = valid_json:selectChildNode("[1].[1]"):asString()
158   - if(isStringNullOrEmpty(name) == nil) then
159   - --print("sub_type=".. sub_type .. " name == nil")
160   - else
161   - --print(account_id .. ":" .. name .. "さんがコメントをポストしたり編集したりしました")
162   - end
163   - end
164   -
165   - if(sub_type == "t.rtd") then
166   - --print(response_body)
167   - post_id = valid_json:selectChildNode("[1]"):asString()
168   - comment_id = valid_json:selectChildNode("[2]"):asString()
169   -
170   - if(isStringNullOrEmpty(comment_id) == nil) then
171   - if(isStringNullOrEmpty(post_id) ~= nil) then
172   - PostParser.erase(post_id)
173   - end
174   - else
175   - CommentParser.erase(comment_id)
176   - end
177   - end
178   - end
179   - end
180   - --[[
181   - if(type == "ru") then
182   - print("ru")
183   -
184   - name = child_json:selectChildNode("[1].[1].[1].[2]"):asString()
185   - print("名前:" .. name)
186   -
187   - status = child_json:selectChildNode("[1].[1].[1].[15].[1]"):asString()
188   - print("ステータス:" .. status)
189   -
190   - end
191   - ]]
192   -
193   - if(type == "gb") then
194   - print(account_id .. ":自分がポストとかを投稿したりしました")
195   - end
196   -
197   - aid = aid + 1
198   - InformationContainer.addInformationByAccountID("aid", aid, account_id)
199   -
200   - sleep(10)
201   -
202   - end
203   -
204   - --sleep(500)
205   -
206 61 do return true end
207   -
208 62 end
169 LuaScript/StreamObserver.lua
... ... @@ -0,0 +1,169 @@
  1 +function streamObserverUpdate(account_id, message)
  2 +
  3 + print("streamObserverUpdate")
  4 +
  5 + require("LuaScript/Utility")
  6 +
  7 + if(isStringNullOrEmpty(account_id) == nil) then
  8 + print("StringNullOrEmpty(account_id) == nil")
  9 + do return false end
  10 + end
  11 +
  12 + aid = InformationContainer.getInformationByAccountID("aid", account_id)
  13 +
  14 + if(aid == nil) then
  15 + print("StringNullOrEmpty(aid) == nil")
  16 + do return false end
  17 + end
  18 +
  19 + print("message:" .. message)
  20 +
  21 + connection = Connection()
  22 + json = connection:convertResponseToJson(message)
  23 + if(json == nil) then
  24 + print("json == nil")
  25 + end
  26 +
  27 + --print("Json Count:" .. json:count())
  28 +
  29 + for count = 0, json:count(), 1 do
  30 +
  31 + --print("count:" .. count)
  32 + --print("aid" .. aid)
  33 + child_json = json:selectChildNode(count)
  34 +
  35 + if(child_json:isNull()) then
  36 + do return true end
  37 + end
  38 +
  39 + --print("Json:" .. child_json:selectChildNode("[1].[0]"):asString())
  40 + --[[
  41 + if(child_json:selectChildNode("[1].[0]"):asString() == "noop") then
  42 +
  43 + if(aid == "0") then
  44 + print("Connect Error")
  45 + do return false end
  46 + elseif(aid == "1") then
  47 + print("Connect Error")
  48 + do return false end
  49 + elseif(aid == "2") then
  50 + print("Connect Error")
  51 + do return false end
  52 + elseif(aid == "3") then
  53 + print("Connect Error")
  54 + do return false end
  55 + elseif(aid == "4") then
  56 + print("Connect Error")
  57 + do return false end
  58 + elseif(aid == "5") then
  59 + print("Connect Error")
  60 + do return false end
  61 + end
  62 + print("noop aid=" .. aid)
  63 + break
  64 + end
  65 + ]]
  66 + type = child_json:selectChildNode("[1].[1].[1].[0]"):asString()
  67 + --print("type:" .. type)
  68 + if(child_json:selectChildNode("[1].[0]"):asString() == "c") then
  69 + if(type == "ei") then
  70 + print("update gsessionid")
  71 + gsessionid = child_json:selectChildNode("[1].[1].[1].[1]"):asString()
  72 + --print("gsessionid=" .. gsessionid)
  73 +
  74 + aid = aid + 1
  75 + InformationContainer.addInformationByAccountID("aid", aid, account_id)
  76 + break
  77 +
  78 + end
  79 +
  80 + end
  81 + --[[
  82 + if(type == nil) then
  83 + print("type=nil")
  84 + else
  85 + print("type=" .. type)
  86 + end
  87 + ]]
  88 + if(type == "tu") then
  89 +
  90 + -- invalid json string
  91 + valid_json = Utility.convertStringEscapedJson(child_json, "[1].[1].[1].[1]")
  92 + sub_type = valid_json:selectChildNode("[0]"):asString()
  93 +
  94 + if(sub_type == nil) then
  95 + print("sub_type=nil")
  96 + else
  97 + --print("sub_type=" .. sub_type)
  98 +
  99 + if(sub_type == "t.rtu") then
  100 + --print(response_body)
  101 + PostParser.add(valid_json)
  102 + name = valid_json:selectChildNode("[1].[3]"):asString()
  103 + if(isStringNullOrEmpty(name) == nil) then
  104 + --print("sub_type=".. sub_type .. " name == nil")
  105 + else
  106 + --print(account_id .. ":" .. name .. "さんが投稿をポストしたり編集したりしました")
  107 + end
  108 + end
  109 +
  110 + if(sub_type == "t.rtc") then
  111 + --print(response_body)
  112 + CommentParser.add(valid_json)
  113 + name = valid_json:selectChildNode("[1].[1]"):asString()
  114 + if(isStringNullOrEmpty(name) == nil) then
  115 + --print("sub_type=".. sub_type .. " name == nil")
  116 + else
  117 + --print(account_id .. ":" .. name .. "さんがコメントをポストしたり編集したりしました")
  118 + end
  119 + end
  120 +
  121 + if(sub_type == "t.rtd") then
  122 + --print(response_body)
  123 + post_id = valid_json:selectChildNode("[1]"):asString()
  124 + comment_id = valid_json:selectChildNode("[2]"):asString()
  125 +
  126 + if(isStringNullOrEmpty(comment_id) == nil) then
  127 + if(isStringNullOrEmpty(post_id) ~= nil) then
  128 + PostParser.erase(post_id)
  129 + end
  130 + else
  131 + CommentParser.erase(comment_id)
  132 + end
  133 + end
  134 + end
  135 + end
  136 + --[[
  137 + if(type == "ru") then
  138 + print("ru")
  139 +
  140 + name = child_json:selectChildNode("[1].[1].[1].[2]"):asString()
  141 + print("名前:" .. name)
  142 +
  143 + status = child_json:selectChildNode("[1].[1].[1].[15].[1]"):asString()
  144 + print("ステータス:" .. status)
  145 +
  146 + end
  147 + ]]
  148 +
  149 + if(type == "gb") then
  150 + print(account_id .. ":自分がポストとかを投稿したりしました")
  151 + end
  152 +
  153 + aid = aid + 1
  154 + InformationContainer.addInformationByAccountID("aid", aid, account_id)
  155 +
  156 + sleep(100)
  157 +
  158 + end
  159 +
  160 + --sleep(500)
  161 +
  162 + do return true end
  163 +
  164 +end
  165 +
  166 +function sleep(milliseconds)
  167 + stream_observer = StreamObserver()
  168 + stream_observer:scriptSleep(milliseconds)
  169 +end
5 LuaScript/Utility.lua
@@ -26,11 +26,6 @@ function generatePVTString()
26 26 return ("AMP3u" .. Utility.generateRandomString(89, 89, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-=_") .. "==")
27 27 end
28 28
29   -function sleep(milliseconds)
30   - stream_connection_impl = StreamConnectionImpl()
31   - stream_connection_impl:scriptSleep(milliseconds)
32   -end
33   -
34 29 function makeParameter(parameter_name, parameter)
35 30 do return (parameter_name .. "=" .. parameter) end
36 31 end
110 LuaScript/signal.lua
... ... @@ -0,0 +1,110 @@
  1 +--[[
  2 +signal.lua
  3 +Copyright (c) 2011 Josh Tynjala
  4 +Released under the MIT license.
  5 +
  6 +Based on as3-signals by Robert Penner
  7 +http://github.com/robertpenner/as3-signals
  8 +Copyright (c) 2009 Robert Penner
  9 +Released under the MIT license.
  10 +]]--
  11 +module(..., package.seeall)
  12 +
  13 +local function indexOf(t, value, start)
  14 + if start == nil then
  15 + start = 1
  16 + end
  17 + for i,v in ipairs(t) do
  18 + if i >= start and v == value then
  19 + return i
  20 + end
  21 + end
  22 + return nil
  23 +end
  24 +
  25 +local listenerMT = {};
  26 +
  27 +--this is used by the == comparison in indexOf
  28 +listenerMT.__eq = function (a, b)
  29 + return a.func == b.func and a.scope == b.scope
  30 +end
  31 +
  32 +local function newListener(func, scope)
  33 + local listener =
  34 + {
  35 + func = func,
  36 + scope = scope
  37 + }
  38 + setmetatable(listener, listenerMT)
  39 +
  40 + return listener
  41 +end
  42 +
  43 +function new()
  44 + local signal = {}
  45 + local listeners = {}
  46 + local oneTimeListeners = {}
  47 +
  48 + signal.numListeners = 0
  49 +
  50 + function signal:add(func, scope)
  51 + if func == nil then
  52 + error("Function passed to signal:add() must not non-nil.")
  53 + end
  54 + local listener = newListener(func, scope)
  55 + table.insert(listeners, listener)
  56 + self.numListeners = self.numListeners + 1
  57 + return listener
  58 + end
  59 +
  60 + function signal:addOnce(func, scope)
  61 + local listener = self:add(listener)
  62 + table.insert(oneTimeListeners, listener)
  63 + return listener
  64 + end
  65 +
  66 + function signal:dispatch(...)
  67 + for i,listener in ipairs(listeners) do
  68 + if listener.scope then
  69 + listener.func(listener.scope, unpack(arg))
  70 + else
  71 + listener.func(unpack(arg))
  72 + end
  73 + end
  74 +
  75 + for i,listener in ipairs(oneTimeListeners) do
  76 + self:remove(listener)
  77 + end
  78 + end
  79 +
  80 + function signal:remove(func, scope)
  81 + local listener
  82 + if type(func) == "function" then
  83 + listener = newListener(func, scope)
  84 + else
  85 + --special case used by removeAll so that we don't need to create
  86 + --a new instance of the listener
  87 + listener = func
  88 + end
  89 + local index = indexOf(listeners, listener)
  90 + if index ~= nil then
  91 + table.remove(listeners, index)
  92 + self.numListeners = self.numListeners - 1
  93 +
  94 + --check if it was a one-time listener
  95 + index = indexOf(oneTimeListeners, listener)
  96 + if index ~= nil then
  97 + table.remove(oneTimeListeners, index)
  98 + end
  99 + end
  100 +
  101 + end
  102 +
  103 + function signal:removeAll()
  104 + while #listeners > 0 do
  105 + self:remove(listeners[1])
  106 + end
  107 + end
  108 +
  109 + return signal
  110 +end
8 Project/MSVC/Win32/GooglePlusLibrary.vcxproj
@@ -62,7 +62,7 @@
62 62 <Link>
63 63 <SubSystem>Windows</SubSystem>
64 64 <GenerateDebugInformation>true</GenerateDebugInformation>
65   - <AdditionalDependencies>lua5.1.lib;GooglePlusJsonParser.lib;cppnetlib-client-connectionsd.lib;cppnetlib-urid.lib;libeay32MDd.lib;ssleay32MDd.lib;libluabind_s_mdd.lib;%(AdditionalDependencies)</AdditionalDependencies>
  65 + <AdditionalDependencies>lua5.1.lib;GooglePlusJsonParser.lib;libeay32MDd.lib;ssleay32MDd.lib;libluabind_s_mdd.lib;%(AdditionalDependencies)</AdditionalDependencies>
66 66 <AdditionalLibraryDirectories>C:\boost_1_52_0\stage\lib;C:\lua\lib;C:\OpenSSL-Win32\lib\VC\static;C:\luabind\bin\msvc-10.0\debug\link-static\threading-multi;D:\Development\GooglePlusLibrary\Src\Json\Debug;D:\Development\GooglePlusLibrary\Src\Connection\ChunkedContentParser\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
67 67 </Link>
68 68 <PostBuildEvent>
@@ -86,7 +86,7 @@
86 86 <GenerateDebugInformation>true</GenerateDebugInformation>
87 87 <EnableCOMDATFolding>true</EnableCOMDATFolding>
88 88 <OptimizeReferences>true</OptimizeReferences>
89   - <AdditionalDependencies>lua5.1.lib;GooglePlusJsonParser.lib;cppnetlib-client-connections.lib;cppnetlib-uri.lib;libeay32MD.lib;ssleay32MD.lib;libluabind_s_md.lib;%(AdditionalDependencies)</AdditionalDependencies>
  89 + <AdditionalDependencies>lua5.1.lib;GooglePlusJsonParser.lib;libeay32MD.lib;ssleay32MD.lib;libluabind_s_md.lib;%(AdditionalDependencies)</AdditionalDependencies>
90 90 <AdditionalLibraryDirectories>C:\boost_1_52_0\stage\lib;C:\lua\lib;C:\OpenSSL-Win32\lib\VC\static;C:\luabind\bin\msvc-10.0\release\link-static\threading-multi;D:\Development\GooglePlusLibrary\Src\Json\Release;D:\Development\GooglePlusLibrary\Src\Connection\ChunkedContentParser\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
91 91 </Link>
92 92 <PostBuildEvent>
@@ -140,7 +140,6 @@
140 140 <ClCompile Include="..\..\..\Src\Connection\Talkgadget\TalkgadgetConnection.cpp" />
141 141 <ClCompile Include="..\..\..\Src\Connection\Uri.cpp" />
142 142 <ClCompile Include="..\..\..\Src\Connection\WebClient\WebClient.cpp" />
143   - <ClCompile Include="..\..\..\Src\Connection\WebClient\WebClientCppNetlib.cpp" />
144 143 <ClCompile Include="..\..\..\Src\Connection\WebClient\WebClientHandler.cpp" />
145 144 <ClCompile Include="..\..\..\Src\Hangout\GroupChat.cpp" />
146 145 <ClCompile Include="..\..\..\Src\Hangout\Hangout.cpp" />
@@ -177,6 +176,7 @@
177 176 <ClCompile Include="..\..\..\Src\Stream\StreamConnectionImpl.cpp" />
178 177 <ClCompile Include="..\..\..\Src\Stream\StreamConnectionImplLua.cpp" />
179 178 <ClCompile Include="..\..\..\Src\Stream\StreamImpl.cpp" />
  179 + <ClCompile Include="..\..\..\Src\Stream\StreamObserver.cpp" />
180 180 <ClCompile Include="..\..\..\Src\Thread\ReadWriteMutex.cpp" />
181 181 <ClCompile Include="..\..\..\Src\Utility\Utility.cpp" />
182 182 <ClCompile Include="..\..\..\Src\Utility\UtilityImpl.cpp" />
@@ -261,7 +261,6 @@
261 261 <ClInclude Include="..\..\..\Src\Connection\Talkgadget\TalkgadgetConnection.hpp" />
262 262 <ClInclude Include="..\..\..\Src\Connection\Uri.hpp" />
263 263 <ClInclude Include="..\..\..\Src\Connection\WebClient\WebClient.hpp" />
264   - <ClInclude Include="..\..\..\Src\Connection\WebClient\WebClientCppNetlib.hpp" />
265 264 <ClInclude Include="..\..\..\Src\Hangout\HangoutConnection.hpp" />
266 265 <ClInclude Include="..\..\..\Src\Information\InformationContainer.hpp" />
267 266 <ClInclude Include="..\..\..\Src\Stream\Comment\CommentBase.hpp" />
@@ -276,6 +275,7 @@
276 275 <ClInclude Include="..\..\..\Src\Stream\Post\PostSetter.hpp" />
277 276 <ClInclude Include="..\..\..\Src\Stream\StreamConnection.hpp" />
278 277 <ClInclude Include="..\..\..\Src\Stream\StreamConnectionImpl.hpp" />
  278 + <ClInclude Include="..\..\..\Src\Stream\StreamObserver.hpp" />
279 279 <ClInclude Include="..\..\..\Src\Utility\LuaData.hpp" />
280 280 <ClInclude Include="..\..\..\Src\Utility\LuaScript.hpp" />
281 281 <ClInclude Include="..\..\..\Src\Utility\Utility.hpp" />
12 Project/MSVC/Win32/GooglePlusLibrary.vcxproj.filters
@@ -256,15 +256,15 @@
256 256 <ClCompile Include="..\..\..\Src\Stream\StreamImpl.cpp">
257 257 <Filter>Stream</Filter>
258 258 </ClCompile>
259   - <ClCompile Include="..\..\..\Src\Connection\WebClient\WebClientCppNetlib.cpp">
260   - <Filter>Connection\WebClient</Filter>
261   - </ClCompile>
262 259 <ClCompile Include="..\..\..\Src\Utility\UtilityImpl.cpp">
263 260 <Filter>Utility</Filter>
264 261 </ClCompile>
265 262 <ClCompile Include="..\..\..\Src\Utility\UtilityLuaImpl.cpp">
266 263 <Filter>Utility</Filter>
267 264 </ClCompile>
  265 + <ClCompile Include="..\..\..\Src\Stream\StreamObserver.cpp">
  266 + <Filter>Stream</Filter>
  267 + </ClCompile>
268 268 </ItemGroup>
269 269 <ItemGroup>
270 270 <Filter Include="Account">
@@ -657,12 +657,12 @@
657 657 <ClInclude Include="..\..\..\Include\Stream\StreamImpl.hpp">
658 658 <Filter>Stream</Filter>
659 659 </ClInclude>
660   - <ClInclude Include="..\..\..\Src\Connection\WebClient\WebClientCppNetlib.hpp">
661   - <Filter>Connection\WebClient</Filter>
662   - </ClInclude>
663 660 <ClInclude Include="..\..\..\Src\Utility\UtilityImpl.hpp">
664 661 <Filter>Utility</Filter>
665 662 </ClInclude>
  663 + <ClInclude Include="..\..\..\Src\Stream\StreamObserver.hpp">
  664 + <Filter>Stream</Filter>
  665 + </ClInclude>
666 666 </ItemGroup>
667 667 <ItemGroup>
668 668 <None Include="..\..\..\LuaScript\Constant.lua">
1  Project/osx/cppfiles.txt
@@ -87,6 +87,7 @@ Stream/StreamConnection.cpp
87 87 Stream/StreamConnectionImpl.cpp
88 88 Stream/StreamConnectionImplLua.cpp
89 89 Stream/StreamImpl.cpp
  90 +Stream/StreamObserver.cpp
90 91 Thread/ReadWriteMutex.cpp
91 92 Utility/Utility.cpp
92 93 Utility/UtilityImpl.cpp
14 Src/Connection/Connection.cpp
@@ -13,7 +13,7 @@
13 13 #include <boost/regex.hpp>
14 14 #include <boost/format.hpp>
15 15
16   -#include <luabind/luabind.hpp>
  16 +//#include <luabind/luabind.hpp>
17 17 #include <utf8.h>
18 18
19 19 namespace Gplusnasite
@@ -115,6 +115,7 @@ HttpResponse Connection::httpGet(const string& url, bool auto_redirect)
115 115 do
116 116 {
117 117 WebClient client(location);
  118 + connectEventHandler(client);
118 119 client.setUserAgent(user_agent_);
119 120 client.setCurrentMailAddress(current_mail_address_);
120 121 client.setCurrentAccountID(current_account_id_);
@@ -159,6 +160,7 @@ HttpResponse Connection::httpPost(const string& url, const map<string, string>&
159 160 HttpResponse Connection::httpPost(const string& url, const string& parameter)
160 161 {
161 162 WebClient client(url);
  163 + connectEventHandler(client);
162 164 client.setUserAgent(user_agent_);
163 165 client.setCurrentMailAddress(current_mail_address_);
164 166 client.setCurrentAccountID(current_account_id_);
@@ -174,6 +176,7 @@ HttpResponse Connection::httpPost(const string& url, const string& parameter)
174 176 HttpResponse Connection::httpPut(const string& url, ifstream& file_stream)
175 177 {
176 178 WebClient client(url);
  179 + connectEventHandler(client);
177 180 client.setUserAgent(user_agent_);
178 181 client.setCurrentMailAddress(current_mail_address_);
179 182 client.setCurrentAccountID(current_account_id_);
@@ -271,9 +274,16 @@ void Connection::bindToScript(lua_State* lua_state)
271 274 ];
272 275 }
273 276
274   -Connection::~Connection()
  277 +void Connection::connectEventHandler(WebClient& client)
275 278 {
  279 + client.onChunkedContentReceived.connect([&](const std::string& content)
  280 + {
  281 + onChunkedContentReceived(content);
  282 + });
  283 +}
276 284
  285 +Connection::~Connection()
  286 +{
277 287 }
278 288
279 289 }// namespace GooglePlusLibrary
9 Src/Connection/Connection.hpp
@@ -17,10 +17,11 @@
17 17 #endif
18 18 #endif
19 19
  20 +#include <boost/signals2.hpp>
  21 +
20 22 #include <string>
21 23 #include <map>
22 24 #include <iosfwd>
23   -#include <boost/signals2.hpp>
24 25
25 26 struct lua_State;
26 27
@@ -29,6 +30,7 @@ namespace Gplusnasite
29 30 namespace GooglePlusLibrary
30 31 {
31 32
  33 +class WebClient;
32 34 class HttpResponse;
33 35 class JsonObject;
34 36
@@ -198,9 +200,14 @@ class GOOGLEPLUSLIBRARY_API Connection
198 200
199 201 static void bindToScript(lua_State* lua_state);
200 202
  203 +protected:
  204 + void connectEventHandler(WebClient& client);
  205 +
201 206 public:
202 207 boost::signals2::signal<void(HttpResponse)> onResponseReceived;
203 208
  209 + boost::signals2::signal<void(const std::string&)> onChunkedContentReceived;
  210 +
204 211 virtual ~Connection();
205 212 private:
206 213
2  Src/Connection/HttpResponse.hpp
@@ -52,7 +52,7 @@ class GOOGLEPLUSLIBRARY_API HttpResponse
52 52 HttpResponse(const std::string& url, int status_code, const std::map<std::string, std::string>& response_header,
53 53 const std::list<Cookie>& response_cookie,
54 54 const std::string& response_body);
55   -
  55 +
56 56 public:
57 57 std::string getUrl() const;
58 58 private:
13 Src/Connection/WebClient/WebClient.hpp
@@ -18,14 +18,13 @@
18 18 #endif
19 19
20 20 //#define BOOST_ASIO_ENABLE_HANDLER_TRACKING
21   -#include <sstream>
22   -#include <fstream>
23   -#include <string>
24   -#include <list>
25   -#include <map>
26 21
27 22 #include <boost/asio.hpp>
28 23 #include <boost/asio/ssl/stream.hpp>
  24 +#include <boost/signals2.hpp>
  25 +
  26 +#include <string>
  27 +#include <map>
29 28 #include <iosfwd>
30 29
31 30 typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> asio_ssl_stream;
@@ -54,6 +53,8 @@ class GOOGLEPLUSLIBRARY_API WebClient
54 53 std::string current_account_id_;
55 54
56 55 public:
  56 + boost::signals2::signal<void(const std::string&)> onChunkedContentReceived;
  57 +
57 58 HttpResponse get();
58 59 HttpResponse post(const std::string& parameter);
59 60 HttpResponse put(std::ifstream& file_stream);
@@ -139,6 +140,7 @@ class GOOGLEPLUSLIBRARY_API WebClient
139 140 void startReadChunkedContent();
140 141 void handleReadChunkSize(const boost_error_code& error, size_t bytes_transferred);
141 142 void handleReadChunkData(const boost_error_code& error, size_t bytes_transferred);
  143 +
142 144 private:
143 145 std::shared_ptr<boost::asio::io_service> io_service_ptr_;
144 146 boost::asio::io_service& io_service_;
@@ -159,7 +161,6 @@ class GOOGLEPLUSLIBRARY_API WebClient
159 161 std::string path_;
160 162 std::string request_;
161 163
162   - //size_t content_length_;
163 164 std::string content_;
164 165 std::string content_type_;
165 166
65 Src/Connection/WebClient/WebClientHandler.cpp
@@ -4,12 +4,13 @@
4 4
5 5 #include <boost/bind.hpp>
6 6 #include <boost/algorithm/string/trim.hpp>
7   -#include <boost/lexical_cast.hpp>
8 7
9 8 #include <iostream>
10 9 #include <fstream>
11 10 #include <algorithm>
12 11
  12 +//#define DEBUG_WITH_HEXDUMP
  13 +
13 14 namespace Gplusnasite
14 15 {
15 16 namespace GooglePlusLibrary
@@ -277,7 +278,7 @@ void WebClient::handleReadHeaders(const boost_error_code& error)
277 278 cookies.push_back(cookie);
278 279 }
279 280 response_headers_.insert(make_pair(name, value));
280   - //cout << "header:" << name << "=" << value << endl;
  281 + //cout << "header:" << name << "=" << value << endl; //XXX
281 282 }
282 283
283 284 response_cookies_ = cookies;
@@ -316,9 +317,8 @@ void WebClient::startReadChunkedContent()
316 317 {
317 318 boost::asio::async_read_until(socket_, response_, "\r\n",
318 319 boost::bind(&WebClient::handleReadChunkSize, this,
319   - boost::asio::placeholders::error,
320   - boost::asio::placeholders::bytes_transferred));
321   -
  320 + boost::asio::placeholders::error,
  321 + boost::asio::placeholders::bytes_transferred));
322 322 }
323 323
324 324 static size_t hex2size_t(const std::string str)
@@ -390,6 +390,7 @@ static size_t hex2size_t(const std::string str)
390 390 return size;
391 391 }
392 392
  393 +
393 394 void WebClient::handleReadChunkSize(const boost_error_code& error, size_t bytes_transferred)
394 395 {
395 396 if (is_cancellation_pending_)
@@ -399,6 +400,14 @@ hexdump(boost::asio::buffer_cast<const char*>(response_.data()),
399 400 bytes_transferred);
400 401 #endif /* DEBUG_WITH_HEXDUMP */
401 402
  403 + //cout << "handleReadChunkSize" << endl;
  404 + //cout << "URL:" << url_ << endl;
  405 +
  406 +#if defined DEBUG_WITH_HEXDUMP
  407 + hexdump(boost::asio::buffer_cast<const char*>(response_.data()),
  408 + bytes_transferred);
  409 +#endif /* DEBUG_WITH_HEXDUMP */
  410 +
402 411 if (error) {
403 412 cout << "error on receive: " << error.message() << endl;
404 413 cancelConnect();
@@ -408,7 +417,8 @@ hexdump(boost::asio::buffer_cast<const char*>(response_.data()),
408 417 std::string response(boost::asio::buffer_cast<const char*>(response_.data()), response_.size());
409 418 std::string eol("\r\n");
410 419 std::size_t pos_eol = response.find(eol);
411   - if (std::string::npos == pos_eol) {
  420 + if (std::string::npos == pos_eol)
  421 + {
412 422 cout << " error on receive: bad chunk format." << endl;
413 423 cancelConnect();
414 424 return;
@@ -417,13 +427,18 @@ hexdump(boost::asio::buffer_cast<const char*>(response_.data()),
417 427
418 428 string chunk_size_line(boost::asio::buffer_cast<const char*>(response_.data()), line_length);
419 429 response_.consume(line_length);
  430 +
420 431 chunk_size_line.resize(chunk_size_line.length() - 2 /* drop "\r\n" */);
421   - if (0 == chunk_size_line.length()) {
  432 +
  433 + if (0 == chunk_size_line.length())
  434 + {
422 435 // no more chunk.
423 436 cancelConnect();
424 437 }
  438 +
425 439 size_t chunk_size = hex2size_t(chunk_size_line);
426   - if (0 == chunk_size) {
  440 + if (0 == chunk_size)
  441 + {
427 442 // wait next chunk.
428 443 startReadChunkedContent();
429 444 return;
@@ -440,17 +455,23 @@ hexdump(boost::asio::buffer_cast<const char*>(response_.data()),
440 455 response_,
441 456 boost::asio::transfer_exactly(size_to_need),
442 457 boost::bind(&WebClient::handleReadChunkData, this,
443   - boost::asio::placeholders::error,
444   - boost::asio::placeholders::bytes_transferred));
  458 + boost::asio::placeholders::error,
  459 + boost::asio::placeholders::bytes_transferred));
445 460 }
446 461
447 462 void WebClient::handleReadChunkData(const boost_error_code& error, size_t bytes_transferred)
448 463 {
449 464 if (is_cancellation_pending_)
  465 + {
450 466 return;
  467 + }
  468 +
  469 + //cout << "handleReadChunkData" << endl;
  470 + //cout << "URL:" << url_ << endl;
  471 +
451 472 #if defined DEBUG_WITH_HEXDUMP
452   -hexdump(boost::asio::buffer_cast<const char*>(response_.data()),
453   - response_.size());
  473 + hexdump(boost::asio::buffer_cast<const char*>(response_.data()),
  474 + response_.size());
454 475 #endif /* DEBUG_WITH_HEXDUMP */
455 476
456 477 if (error) {
@@ -459,10 +480,13 @@ hexdump(boost::asio::buffer_cast<const char*>(response_.data()),
459 480 }
460 481
461 482 std::size_t eat_size = std::min(chunk_remain_, response_.size());
462   - response_body_.append(
463   - boost::asio::buffer_cast<const char*>(response_.data()),
464   - // response_.size() - 2 /* drop trailing "\r\n" */);
465   - eat_size);
  483 +
  484 + string chunked_content(boost::asio::buffer_cast<const char*>(response_.data()), eat_size);
  485 +
  486 + onChunkedContentReceived(chunked_content);
  487 +
  488 + response_body_.append(boost::asio::buffer_cast<const char*>(response_.data()), eat_size);
  489 +
466 490 response_.consume(eat_size);
467 491 chunk_remain_ -= eat_size;
468 492
@@ -471,14 +495,15 @@ hexdump(boost::asio::buffer_cast<const char*>(response_.data()),
471 495 response_,
472 496 boost::asio::transfer_exactly(chunk_remain_),
473 497 boost::bind(&WebClient::handleReadChunkData, this,
474   - boost::asio::placeholders::error,
475   - boost::asio::placeholders::bytes_transferred));
  498 + boost::asio::placeholders::error,
  499 + boost::asio::placeholders::bytes_transferred));
476 500 return;
477 501 }
478 502
479 503 response_body_.resize(response_body_.size() - 2 /* drop trailing "\r\n" */);
480   -
481   - if (response_.size() > 0) {
  504 +
  505 + if (response_.size() > 0)
  506 + {
482 507 boost::asio::async_read(socket_, response_,
483 508 boost::asio::transfer_exactly(0),
484 509 boost::bind(&WebClient::handleReadChunkSize, this,
BIN  Src/Json/GooglePlusJsonParser.suo
Binary file not shown
8 Src/Json/GooglePlusJsonParser.vcxproj
@@ -62,14 +62,14 @@
62 62 <WarningLevel>Level3</WarningLevel>
63 63 <Optimization>Disabled</Optimization>
64 64 <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
65   - <AdditionalIncludeDirectories>C:\boost_1_51_0;C:\lua5_1_4_Win32_dll8_lib\include;C:\luabind;D:\Development\GooglePlusLibrary\Src;D:\Development\utf8_v2_3_2\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
  65 + <AdditionalIncludeDirectories>C:\boost_1_52_0;C:\lua\include;C:\luabind;D:\Development\GooglePlusLibrary\Src;D:\Development\utf8_v2_3_2\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
66 66 </ClCompile>
67 67 <Link>
68 68 <SubSystem>Windows</SubSystem>
69 69 <GenerateDebugInformation>true</GenerateDebugInformation>
70 70 </Link>
71 71 <Lib>
72   - <AdditionalLibraryDirectories>C:\boost_1_51_0\stage\lib;C:\lua5_1_4_Win32_dll8_lib;C:\luabind\bin\msvc-10.0\debug\link-static\threading-multi;D:\Development\JsonParserTest\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
  72 + <AdditionalLibraryDirectories>C:\boost_1_52_0\stage\lib;C:\lua\lib;C:\luabind\bin\msvc-10.0\debug\link-static\threading-multi;D:\Development\JsonParserTest\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
73 73 <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
74 74 </Lib>
75 75 </ItemDefinitionGroup>
@@ -82,7 +82,7 @@
82 82 <FunctionLevelLinking>true</FunctionLevelLinking>
83 83 <IntrinsicFunctions>true</IntrinsicFunctions>
84 84 <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
85   - <AdditionalIncludeDirectories>C:\boost_1_51_0;C:\lua5_1_4_Win32_dll8_lib\include;C:\luabind;D:\Development\GooglePlusLibrary\Src;D:\Development\utf8_v2_3_2\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
  85 + <AdditionalIncludeDirectories>C:\boost_1_52_0;C:\lua\include;C:\luabind;D:\Development\GooglePlusLibrary\Src;D:\Development\utf8_v2_3_2\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
86 86 </ClCompile>
87 87 <Link>
88 88 <SubSystem>Windows</SubSystem>
@@ -91,7 +91,7 @@
91 91 <OptimizeReferences>true</OptimizeReferences>
92 92 </Link>
93 93 <Lib>
94   - <AdditionalLibraryDirectories>C:\boost_1_51_0\stage\lib;C:\lua5_1_4_Win32_dll8_lib;C:\luabind\bin\msvc-10.0\release\link-static\threading-multi;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
  94 + <AdditionalLibraryDirectories>C:\boost_1_52_0\stage\lib;C:\lua\lib;C:\luabind\bin\msvc-10.0\release\link-static\threading-multi;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
95 95 <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
96 96 </Lib>
97 97 </ItemDefinitionGroup>
5 Src/Json/JsonParser.cpp
@@ -5,6 +5,10 @@
5 5
6 6 #include <boost/algorithm/string/replace.hpp>
7 7
  8 +#if defined _MSC_VER
  9 +#define LOGGING
  10 +#endif
  11 +
8 12 namespace Gplusnasite
9 13 {
10 14 namespace GooglePlusLibrary
@@ -59,6 +63,7 @@ JsonObject JsonParser::parse(const wstring& json) const
59 63 #ifdef TRACE
60 64 cout << "JsonParser:ParseFailed" << endl;
61 65 #endif
  66 +
62 67 #ifdef LOGGING
63 68 wstringstream string_stream;
64 69 string_stream << "Failed(Exception)Json";
9 Src/Stream/StreamConnection.cpp
@@ -59,15 +59,6 @@ void StreamConnection::update(const wstring& account_id)
59 59 impl_->update(account_id);
60 60 }
61 61
62   -void StreamConnection::scriptSleep(long milliseconds)
63   -{
64   - if(!impl_)
65   - {
66   - return;
67   - }
68   - impl_->scriptSleep(milliseconds);
69   -}
70   -
71 62 void StreamConnection::cancelUpdate()
72 63 {
73 64 if(!impl_)
12 Src/Stream/StreamConnection.hpp
@@ -111,18 +111,6 @@ class GOOGLEPLUSLIBRARY_API StreamConnection
111 111 public:
112 112 /*!
113 113 * @~english
114   - * @brief sleeps only the specified time(in milliseconds)
115   - * @details This function is used in the Lua script
116   - * @param milliseconds Script sleep time you want(in milliseconds)
117   - * @~japanese
118   - * @brief �w�肵������(�~���b)�����X���[�v���܂�
119   - * @details ���̊֐���Lua�X�N���v�g��Ŏg�����̂ł�
120   - * @param milliseconds �X�N���v�g��X���[�v����������(�~���b)
121   - */
122   - void scriptSleep(long milliseconds);
123   -
124   - /*!
125   - * @~english
126 114 * @brief Abort the update stream
127 115 * @details Blocking of the Update () will be released in good time this function is called
128 116 * @warning This function is implemented please do not use full for outstanding
11 Src/Stream/StreamConnectionImpl.cpp
... ... @@ -1,7 +1,5 @@
1 1 #include <Stream/StreamConnectionImpl.hpp>
2 2
3   -#include <boost/asio.hpp>
4   -
5 3 namespace Gplusnasite
6 4 {
7 5 namespace GooglePlusLibrary
@@ -43,15 +41,6 @@ void StreamConnectionImpl::waitInitializeAsync()
43 41 initialize_thread_.join();
44 42 }
45 43
46   -void StreamConnectionImpl::scriptSleep(long milliseconds)
47   -{
48   - boost::asio::io_service io_service;
49   - boost::asio::deadline_timer timer(io_service);
50   -
51   - timer.expires_from_now(boost::posix_time::milliseconds(milliseconds));
52   - timer.wait();
53   -}
54   -
55 44 void StreamConnectionImpl::cancelUpdate()
56 45 {
57 46 is_cancellation_pending_ = true;
12 Src/Stream/StreamConnectionImpl.hpp
@@ -36,13 +36,10 @@ class GOOGLEPLUSLIBRARY_API StreamConnectionImpl
36 36 StreamConnectionImpl();
37 37
38 38 void initialize(const std::wstring& account_id);
39   -
40 39 void initializeAsync(const std::wstring& account_id);
41   -
42 40 void waitInitializeAsync();
43 41
44 42 private:
45   -
46 43 void initializeAsyncThreadMethod(const std::wstring& account_id);
47 44 boost::thread initialize_thread_;
48 45
@@ -50,16 +47,17 @@ class GOOGLEPLUSLIBRARY_API StreamConnectionImpl
50 47 boost::signals2::signal<void()> onInitializeSucceed;
51 48 boost::signals2::signal<void()> onInitializeFailed;
52 49
53   -public:
  50 + void test();
54 51
  52 +public:
55 53 void update(const std::wstring& account_id);
  54 +protected:
  55 + static void chunkedContentReceieved(const std::string& account_id, const std::string& content);
  56 +
56 57 private:
57 58 boost::thread update_thread_;
58 59
59 60 public:
60   -
61   - void scriptSleep(long milliseconds);
62   -
63 61 void cancelUpdate();
64 62
65 63 bool isCanceled();
34 Src/Stream/StreamConnectionImplLua.cpp
@@ -3,11 +3,10 @@
3 3 #include <Connection/Connection.hpp>
4 4 #include <Connection/Cookie/Cookie.hpp>
5 5 #include <Connection/HttpResponse.hpp>
6   -#include <Utility/Utility.hpp>
7 6 #include <Information/InformationContainer.hpp>
8   -#include <Stream/Post/PostParser/PostParser.hpp>
9   -#include <Stream/Comment/CommentParser/CommentParser.hpp>
  7 +#include <Stream/StreamObserver.hpp>
10 8 #include <Utility/LuaScript.hpp>
  9 +#include <Utility/Utility.hpp>
11 10 #include <Json/JsonObject.hpp>
12 11
13 12 namespace Gplusnasite
@@ -25,13 +24,14 @@ void StreamConnectionImpl::initializeAsyncThreadMethod(const wstring& account_id
25 24 return;
26 25 }
27 26
28   - LuaScript<bool(string)> lua_script("LuaScript/StreamInitialize.lua", "streamInitialize", [](lua_State* lua_state)
  27 + LuaScript<bool(string)> lua_script("LuaScript/StreamInitialize.lua", "streamInitialize", [this](lua_State* lua_state)
29 28 {
30 29 Connection::bindToScript(lua_state);
31 30 HttpResponse::bindToScript(lua_state);
32 31 Utility::bindToScript(lua_state);
33 32 InformationContainer::bindToScript(lua_state);
34 33 JsonObject::bindToScript(lua_state);
  34 + bindToScript(lua_state);
35 35 });
36 36
37 37 lua_script.onLoadingScriptFailed.connect([&](string message)
@@ -72,20 +72,26 @@ void StreamConnectionImpl::initializeAsyncThreadMethod(const wstring& account_id
72 72 update_thread_ = boost::move(update_thread);
73 73 }
74 74
  75 +void StreamConnectionImpl::test()
  76 +{
  77 + cout << "test" << endl;
  78 +}
  79 +
75 80 void StreamConnectionImpl::update(const wstring& account_id)
76 81 {
77   - LuaScript<bool(string)> lua_script("LuaScript/StreamLoopUpdate.lua", "streamLoopUpdate", [this](lua_State* lua_state)
  82 + //std::function<void(void)> func = std::bind(&StreamConnectionImpl::test, this);
  83 +
  84 + LuaScript<bool(string)> lua_script("LuaScript/StreamLoopUpdate.lua", "streamLoopUpdate", [&](lua_State* lua_state)
78 85 {
79 86 Connection::bindToScript(lua_state);
80 87 HttpResponse::bindToScript(lua_state);
81 88 Utility::bindToScript(lua_state);
82 89 InformationContainer::bindToScript(lua_state);
83   - PostParser::bindToScript(lua_state);
84   - CommentParser::bindToScript(lua_state);
85 90 JsonObject::bindToScript(lua_state);
  91 + StreamObserver::bindToScript(lua_state);
86 92 bindToScript(lua_state);
87 93 });
88   -
  94 +
89 95 while(!is_cancellation_pending_)
90 96 {
91 97 boost::this_thread::disable_interruption di;
@@ -100,6 +106,11 @@ void StreamConnectionImpl::update(const wstring& account_id)
100 106 }
101 107 }
102 108
  109 +void StreamConnectionImpl::chunkedContentReceieved(const string& account_id, const string& content)
  110 +{
  111 + int a = 3;
  112 +}
  113 +
103 114 void StreamConnectionImpl::bindToScript(lua_State* lua_state)
104 115 {
105 116 module(lua_state)
@@ -107,7 +118,12 @@ void StreamConnectionImpl::bindToScript(lua_State* lua_state)
107 118 class_<StreamConnectionImpl>("StreamConnectionImpl")
108 119 .def(constructor<>())
109 120 .def("update", &StreamConnectionImpl::update)
110   - .def("scriptSleep", &StreamConnectionImpl::scriptSleep)
  121 + .def("test", &StreamConnectionImpl::test)
  122 +
  123 + .scope
  124 + [
  125 + def("chunkedContentReceieved", &StreamConnectionImpl::chunkedContentReceieved)
  126 + ]
111 127 ];
112 128 }
113 129
122 Src/Stream/StreamObserver.cpp
... ... @@ -0,0 +1,122 @@
  1 +#include <Stream/StreamObserver.hpp>
  2 +#include <Connection/Connection.hpp>
  3 +#include <Connection/Cookie/Cookie.hpp>
  4 +#include <Connection/HttpResponse.hpp>
  5 +#include <Information/InformationContainer.hpp>
  6 +#include <Stream/Post/PostParser/PostParser.hpp>
  7 +#include <Stream/Comment/CommentParser/CommentParser.hpp>
  8 +#include <Utility/LuaScript.hpp>
  9 +#include <Utility/Utility.hpp>
  10 +#include <Json/JsonObject.hpp>
  11 +
  12 +#include <boost/asio.hpp>
  13 +#include <boost/spirit/include/qi.hpp>
  14 +#include <boost/spirit/include/phoenix.hpp>
  15 +
  16 +namespace Gplusnasite
  17 +{
  18 +namespace GooglePlusLibrary
  19 +{
  20 +
  21 +using namespace std;
  22 +using namespace ::luabind;
  23 +
  24 +namespace qi = boost::spirit::qi;
  25 +namespace phoenix = boost::phoenix;
  26 +
  27 +StreamObserver::StreamObserver()
  28 +{
  29 +}
  30 +
  31 +HttpResponse StreamObserver::get(const string& account_id, const string& url)
  32 +{
  33 + LuaScript<bool(string, string)> lua_script("LuaScript/streamObserver.lua", "streamObserverUpdate", [&](lua_State* lua_state)
  34 + {
  35 + Connection::bindToScript(lua_state);
  36 + InformationContainer::bindToScript(lua_state);
  37 + PostParser::bindToScript(lua_state);
  38 + CommentParser::bindToScript(lua_state);
  39 + JsonObject::bindToScript(lua_state);
  40 + Utility::bindToScript(lua_state);
  41 + bindToScript(lua_state);
  42 + });
  43 +
  44 + Connection connection;
  45 + connection.setCurrentAccountID(account_id);
  46 +
  47 + int chunked_json_size = 0;
  48 + string chunked_json;
  49 +
  50 + connection.onChunkedContentReceived.connect([&](const std::string& content)
  51 + {
  52 + int position = content.find("\n");
  53 + if(position > 0)
  54 + {
  55 + ++position;
  56 +
  57 + string json_size_string = content.substr(0, position);
  58 +
  59 + int json_size = 0;
  60 +
  61 + if(qi::parse(json_size_string.cbegin(), json_size_string.cend(), qi::int_[phoenix::ref(json_size) = qi::_1] >> (qi::lit("\r\n") | qi::lit("\n"))))
  62 + {
  63 + if(json_size > 0)
  64 + {
  65 + chunked_json_size = json_size;
  66 + chunked_json = content;
  67 + }
  68 + }
  69 + else if(chunked_json_size > 0)
  70 + {
  71 + chunked_json += content;
  72 + }
  73 + }
  74 + else
  75 + {
  76 + if(chunked_json_size > 0)
  77 + {
  78 + chunked_json += content;
  79 + }
  80 + }
  81 +
  82 + if(chunked_json_size > 0)
  83 + {
  84 + int size = chunked_json.size();
  85 + if(chunked_json_size <= size)
  86 + {
  87 + auto result = lua_script(account_id, chunked_json);
  88 + }
  89 + }
  90 +
  91 +
  92 + //add(account_id, content);
  93 + });
  94 + return connection.httpGet(url, false);
  95 +}
  96 +
  97 +void StreamObserver::scriptSleep(long milliseconds)
  98 +{
  99 + boost::asio::io_service io_service;
  100 + boost::asio::deadline_timer timer(io_service);
  101 +
  102 + timer.expires_from_now(boost::posix_time::milliseconds(milliseconds));
  103 + timer.wait();
  104 +}
  105 +
  106 +void StreamObserver::bindToScript(lua_State* lua_state)
  107 +{
  108 + module(lua_state)
  109 + [
  110 + class_<StreamObserver>("StreamObserver")
  111 + .def(constructor<>())
  112 + .def("get", &StreamObserver::get)
  113 + .def("scriptSleep", &StreamObserver::scriptSleep)
  114 + ];
  115 +}
  116 +
  117 +StreamObserver::~StreamObserver()
  118 +{
  119 +}
  120 +
  121 +}// namespace GooglePlusLibrary
  122 +}// namespace Gplusnasite
46 Src/Stream/StreamObserver.hpp
... ... @@ -0,0 +1,46 @@
  1 +#pragma once
  2 +
  3 +#ifdef _MSC_VER
  4 +#ifdef GOOGLEPLUSLIBRARY_EXPORTS
  5 +#define GOOGLEPLUSLIBRARY_API __declspec(dllexport)
  6 +#else
  7 +#define GOOGLEPLUSLIBRARY_API __declspec(dllimport)
  8 +#endif
  9 +#else
  10 +#define GOOGLEPLUSLIBRARY_API
  11 +#endif
  12 +
  13 +#ifdef GOOGLEPLUSLIBRARY_NO_WARNINGS
  14 +#ifdef _MSC_VER
  15 +#pragma warning (disable:4251)
  16 +#endif
  17 +#endif
  18 +
  19 +#include <string>
  20 +
  21 +struct lua_State;
  22 +
  23 +namespace Gplusnasite
  24 +{
  25 +namespace GooglePlusLibrary
  26 +{
  27 +
  28 +class HttpResponse;
  29 +
  30 +class GOOGLEPLUSLIBRARY_API StreamObserver
  31 +{
  32 +public:
  33 + StreamObserver();
  34 +
  35 +public:
  36 + HttpResponse get(const std::string& account_id, const std::string& url);
  37 +
  38 + void scriptSleep(long milliseconds);
  39 +
  40 + static void bindToScript(lua_State* lua_state);
  41 +
  42 + virtual ~StreamObserver();
  43 +};
  44 +
  45 +}// namespace GooglePlusLibrary
  46 +}// namespace Gplusnasite

No commit comments for this range

Something went wrong with that request. Please try again.