CppUmlClass 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/start.rb ADDED
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH << File.dirname(File.expand_path(__FILE__))
4
+
5
+ require "socket"
6
+ require "rack"
7
+ require "daemons"
8
+ require "fileutils"
9
+ require "kconv"
10
+ require "json"
11
+ require "facter"
12
+
13
+ # ログ出力
14
+ module Output
15
+ def self.console_and_file(output_file, stdout = true)
16
+ begin
17
+ defout = File.new(output_file, "a+")
18
+ rescue
19
+ puts $!
20
+ puts $@
21
+ return nil
22
+ end
23
+ class << defout
24
+ alias_method :write_org, :write
25
+
26
+ def initialize(stdout)
27
+ @stdout = false
28
+ end
29
+
30
+ attr_accessor :stdout
31
+
32
+ def puts(str)
33
+ STDOUT.write(str.to_s + "\n") if @stdout
34
+ self.write_org(str.to_s + "\n")
35
+ self.flush
36
+ end
37
+
38
+ def write(str)
39
+ STDOUT.write(str) if @stdout
40
+ self.write_org(str)
41
+ self.flush
42
+ end
43
+ end
44
+ $stdout = defout
45
+ $stdout.stdout = stdout
46
+ end
47
+ end
48
+
49
+ # ディレクトリ移動
50
+ dir = File.dirname(File.expand_path(__FILE__))
51
+ FileUtils.cd dir
52
+
53
+ # ディレクトリ作成
54
+ pp ARGV
55
+ if ARGV[0] == "test"
56
+ $home_dir = "./"
57
+ ARGV = []
58
+ else
59
+ $home_dir = ENV["HOME"] + "/" + dir.split("/")[-1].gsub(/-[0-9\.-]+/,"") + "/"
60
+ end
61
+ puts "home_dir=#{$home_dir}"
62
+ FileUtils.mkdir_p("#{$home_dir}/logs")
63
+ FileUtils.mkdir_p("#{$home_dir}/history")
64
+ Output.console_and_file("#{$home_dir}/logs/app.log", true)
65
+
66
+ # 空きポートを取得
67
+ def get_unused_port
68
+ s = TCPServer.open(0)
69
+ port = s.addr[1]
70
+ s.close
71
+ return port
72
+ end
73
+
74
+ # 空きポートを取得
75
+ port = get_unused_port
76
+ puts "port=#{port}"
77
+
78
+ # config.ruの編集
79
+ buf = File.binread("config.ru").toutf8
80
+ buf.gsub!(/port [0-9]+/, "port #{port}")
81
+ File.binwrite("config.ru", buf)
82
+
83
+ # main.jsの編集
84
+ buf = File.binread("js/main.js").toutf8
85
+ buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
86
+ File.binwrite("js/main.js", buf)
87
+
88
+ # index.htaの編集
89
+ buf = File.binread("html/index.html").toutf8
90
+ buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
91
+ File.binwrite("html/index.html", buf)
92
+
93
+ begin
94
+ Thread.start {
95
+ puts "wait start web server"
96
+ while true
97
+ begin
98
+ s = TCPSocket.open("localhost", port)
99
+ s.close
100
+ break
101
+ rescue
102
+ puts $!
103
+ sleep 0.1
104
+ end
105
+ end
106
+
107
+ puts "start browser"
108
+ json_file = "#{$home_dir}/config/browser.json"
109
+ json = JSON.parse(File.read json_file)
110
+ puts json
111
+ kernel = Facter.value(:kernel)
112
+ if kernel == "windows"
113
+ browser = json["chrome_win"]
114
+ elsif kernel == "Linux"
115
+ browser = json["chrome_linux"]
116
+ else
117
+ browser = json["chrome_win"]
118
+ end
119
+ browser += " -app=http://localhost:#{port}"
120
+ puts browser
121
+ system browser
122
+ }
123
+
124
+ # start web server
125
+ Rack::Server.start
126
+ rescue
127
+ puts $!
128
+ puts $@
129
+ exit
130
+ end
data/lib/wsserver.rb ADDED
@@ -0,0 +1,145 @@
1
+ require "./server_app_base"
2
+ require "json"
3
+ require "cgi"
4
+ require "thread"
5
+
6
+ def config_json_hash(json)
7
+ config = {}
8
+ json["setting_list"].each do |j|
9
+ config[j["name"]] = j["value"]
10
+ end
11
+ return config
12
+ end
13
+
14
+ $ws_exit_thread = nil
15
+
16
+ class WsServer < Sinatra::Base
17
+ def initialize
18
+ super
19
+ @ws_list = []
20
+ @ws_lock = Mutex.new
21
+ end
22
+
23
+ def ws_send(str)
24
+ @ws_lock.synchronize do
25
+ if @ws_list[0] != nil
26
+ @ws_list[0].send(str)
27
+ end
28
+ end
29
+ end
30
+
31
+ json_config = nil
32
+ exec_thread = nil
33
+ get "" do
34
+ if !request.websocket?
35
+ "no supported"
36
+ else
37
+ request.websocket do |ws|
38
+ ws.onopen do
39
+ puts "ws.open"
40
+ @ws_lock.synchronize do
41
+ @ws_list << ws
42
+ $app.set_ws(ws)
43
+ pp "ws=#{ws}"
44
+ end
45
+ ws_send("startup:#{$startup_file}")
46
+ puts "ws_exit_thread=#{$ws_exit_thread}"
47
+ if $ws_exit_thread != nil
48
+ puts "ws_exit_thread kill"
49
+ Thread.kill $ws_exit_thread
50
+ end
51
+ end
52
+ ws.onmessage do |msg|
53
+ puts msg
54
+ json = JSON.parse(File.read("#{$home_dir}/config/setting.json"))
55
+ json_config = config_json_hash(json)
56
+ $app.set_config(json_config)
57
+ if msg =~ /^exec:/
58
+ if exec_thread == nil
59
+ argv = msg.gsub(/^exec:/, "")
60
+ exec_thread = Thread.new {
61
+ begin
62
+ $app.start(argv.split(",")) do |out|
63
+ ws_send(out)
64
+ end
65
+ ws_send("app_end:normal")
66
+ rescue
67
+ puts $!
68
+ puts $@
69
+ puts "app_end:err"
70
+ ws_send("app_end:error")
71
+ ensure
72
+ puts "exit thread"
73
+ exec_thread = nil
74
+ end
75
+ }
76
+ else
77
+ puts "app_end:err"
78
+ ws_send("app_end:error")
79
+ end
80
+ end
81
+ if msg =~ /^stop/
82
+ if exec_thread
83
+ Thread.kill exec_thread
84
+ ws_send("app_end:stop")
85
+ $app.stop
86
+ end
87
+ end
88
+ if msg =~ /^suspend/
89
+ if exec_thread
90
+ $app.suspend
91
+ end
92
+ end
93
+ if msg =~ /^resume/
94
+ if exec_thread
95
+ $app.resume
96
+ end
97
+ end
98
+ if msg =~ /^setting:/
99
+ json_string = msg.gsub(/^setting:/, "")
100
+ begin
101
+ json = JSON.parse(json_string)
102
+ File.open("#{$home_dir}/config/setting.json", "w") do |w|
103
+ w.puts JSON.pretty_generate(json)
104
+ end
105
+ json_config = config_json_hash(json)
106
+ $app.set_config(json_config)
107
+ rescue
108
+ # jsonファイルではない
109
+ ws_send("app_end:error")
110
+ end
111
+ end
112
+ if msg =~ /^openfile:/
113
+ file = msg.gsub(/^openfile:/, "")
114
+ Thread.new {
115
+ system "#{json_config["editor"]} #{CGI.unescapeHTML(file)}"
116
+ }
117
+ end
118
+
119
+ # アプリケーション終了
120
+ if msg == "exit"
121
+ #halt
122
+ exit
123
+ end
124
+ end
125
+
126
+ # close websocket
127
+ ws.onclose do
128
+ puts "websocket closed"
129
+ @ws_lock.synchronize do
130
+ @ws_list.delete(ws)
131
+ end
132
+ puts @ws_list.size
133
+ if @ws_list.size == 0
134
+ $ws_exit_thread = Thread.start {
135
+ sleep 1
136
+ #halt
137
+ exit
138
+ }
139
+ puts "ws_exit_thread=#{$ws_exit_thread}"
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,4 @@
1
+ module CppUmlClass
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: CppUmlClass
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Masataka Kuwayama
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: browser_app_base
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ description: Create a C++ UML class diagram.
28
+ email:
29
+ - masataka.kuwayama@gmail.com
30
+ executables:
31
+ - start_cpp_uml_class.rb
32
+ - start_cpp_uml_class.rbw
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - CHANGELOG.md
37
+ - CODE_OF_CONDUCT.md
38
+ - CppUmlClass.gemspec
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE
42
+ - LICENSE.txt
43
+ - README.md
44
+ - Rakefile
45
+ - bin/console
46
+ - bin/setup
47
+ - exe/start_cpp_uml_class.rb
48
+ - exe/start_cpp_uml_class.rbw
49
+ - lib/.clang-format
50
+ - lib/CppUmlClass.rb
51
+ - lib/CppUmlClass/version.rb
52
+ - lib/app_load.rb
53
+ - lib/check_word.rb
54
+ - lib/config.ru
55
+ - lib/config/browser.json
56
+ - lib/config/setting.json
57
+ - lib/cpp_uml_class.rb
58
+ - lib/create_uml_class.rb
59
+ - lib/css/index.css
60
+ - lib/html/index.html
61
+ - lib/html/test.html
62
+ - lib/js/main.js
63
+ - lib/my_app_sample.rb
64
+ - lib/server.rb
65
+ - lib/server_app_base.rb
66
+ - lib/start.rb
67
+ - lib/wsserver.rb
68
+ - sig/CppUmlClass.rbs
69
+ homepage: https://github.com/kuwayama1971/CppUmlClass
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ allowed_push_host: https://rubygems.org
74
+ homepage_uri: https://github.com/kuwayama1971/CppUmlClass
75
+ source_code_uri: https://github.com/kuwayama1971/CppUmlClass
76
+ changelog_uri: https://github.com/kuwayama1971/CppUmlClass
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 3.0.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.4.20
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Create a C++ UML class diagram.
96
+ test_files: []