• R/O
  • SSH
  • HTTPS

cadencii: コミット


コミットメタ情報

リビジョン1636 (tree)
日時2011-06-05 04:06:45
作者kbinani

ログメッセージ

[vConnect/trunk/stand2.0]

変更サマリ

差分

--- vConnect/trunk/stand2.0/vcnctd/Connection.cpp (revision 1635)
+++ vConnect/trunk/stand2.0/vcnctd/Connection.cpp (nonexistent)
@@ -1,74 +0,0 @@
1-/*
2- * Connection.cpp
3- *
4- * Copyright (C) 2011 kbinani.
5- */
6-
7-#include "Connection.h"
8-
9-namespace vcnctd
10-{
11- Socket Connection::get( int number )
12- {
13- if( number <= 0 )
14- {
15- return mSockets[0];
16- }
17- else
18- {
19- map<int, Socket>::iterator itr = mMap.find( number );
20- if( itr != mMap.end() )
21- {
22- int index = mMap[number];
23- return mSockets[index];
24- }
25- else
26- {
27- return NULL;
28- }
29- }
30- }
31-
32- void Connection::initSockets( Config *config )
33- {
34- //int s[SOCK_MAX + 1]; /* array of socket descriptors */
35- int max = 0; /* max num of used socket */
36- int n = 0;
37- socklen_t len;
38- fd_set readfds;
39- int clilen; /* client length */
40- struct sockaddr_in saddr; /* サーバ側(自分)のアドレス情報 */
41- struct sockaddr_in caddr; /* クライアント側のアドレス情報を入れるところ */
42- char str[1024]; /* string buffer */
43- int i, j; /* loop counter */
44- int msglen;
45-
46- /*
47- * ソケットを作る。
48- * このソケットはINETドメインでストリーム型(コネクション型) 。
49- */
50- if( (mSockets[0] = socket( AF_INET, SOCK_STREAM, 0 )) == -1 )
51- {
52- perror( "socket" );
53- exit( 1 );
54- }
55-
56- /*
57- * saddrの中身を0にしておかないと、bind()でエラーが起こることがある
58- */
59- memset( (char *)&saddr, 0, sizeof( saddr ) );
60-
61- /* ソケットに名前をつける bind() */
62- saddr.sin_family = AF_INET;
63- saddr.sin_addr.s_addr = INADDR_ANY;
64- saddr.sin_port = htons( config->getPort() ); /* 定数PORTは#defineしたもの */
65-
66- if( (bind( mSockets[0], (struct sockaddr *)&saddr, sizeof( saddr ) )) == -1 )
67- {
68- perror( "bind" );
69- exit( 1 );
70- }
71-
72- }
73-
74-}
--- vConnect/trunk/stand2.0/vcnctd/Connection.h (revision 1635)
+++ vConnect/trunk/stand2.0/vcnctd/Connection.h (nonexistent)
@@ -1,71 +0,0 @@
1-/*
2- * Connection.h
3- *
4- * Copyright (C) 2011 kbinani.
5- */
6-#ifndef __Connection_h__
7-#define __Connection_h__
8-
9-#ifdef __WIN32__
10- #include <winsock2.h>
11- typedef int socklen_t;
12-#else
13- #include <netinet/in.h>
14- #include <sys/socket.h>
15- #include <sys/types.h>
16-#endif
17-#include <sys/time.h> /* selectシステムコール */
18-#include <map>
19-
20-#include "Config.h"
21-
22-using namespace std;
23-
24-namespace vcnctd
25-{
26-
27- typedef int Socket;
28-
29- /// <summary>
30- /// ソケット接続を管理します.
31- /// </summary>
32- class Connection
33- {
34- public: // public method
35-
36- /// <summary>
37- /// 第number番目に接続したクライアントとのソケット接続を取得します.
38- /// </summary>
39- /// <param name="number">クライアントとの接続番号</param>
40- /// <returns>ソケット接続</returns>
41- Socket get( int number );
42-
43- /// <summary>
44- /// ソケットを用意します.
45- /// </summary>
46- void initSockets( Config *config );
47-
48- public: // public static field
49-
50- /// <summary>
51- /// 許可する同時最大接続数.
52- /// </summary>
53- static const int MAX_CONS = 128;
54-
55- private:
56-
57- /// <summary>
58- /// ソケット接続のリスト.
59- /// </summary>
60- Socket mSockets[MAX_CONS];
61-
62- /// <summary>
63- /// 接続番号とソケットリストのインデックスを紐付けるマップ.
64- /// </summary>
65- map<int, int> mMap;
66-
67- };
68-
69-}
70-
71-#endif
--- vConnect/trunk/stand2.0/vcnctd/Server.cpp (revision 1635)
+++ vConnect/trunk/stand2.0/vcnctd/Server.cpp (revision 1636)
@@ -12,7 +12,6 @@
1212 {
1313 this->synth = new Synth();
1414 this->config = new Config();
15- this->cons = new Connection();
1615 }
1716
1817 Server::~Server()
@@ -28,121 +27,146 @@
2827 UtauDB::dbClear();
2928 }
3029
31- void Server::startListening()
30+ int Server::startListening()
3231 {
33- // ソケット接続を初期化.
34- this->cons->initSockets( this->config );
32+ const int SOCK_MAX = 128;
33+
34+ // ソケット接続のリスト
35+ Socket s[SOCK_MAX + 1];
36+ for( int i = 0; i < SOCK_MAX + 1; i++ )
37+ {
38+ s[i] = -1;
39+ }
40+
41+ // ソケット作る
42+ if( (s[0] = socket( AF_INET, SOCK_STREAM, 0 )) == -1 )
43+ {
44+ // エラーなので死ぬ
45+ printf( "error; create first socket\n" );
46+ return 0;
47+ }
3548
36- /* 接続されるのを待つ listen() */
37- /* 第2引数の値を大きくする */
38- if( (listen( this->cons->get( 0 ), MAX_SOCKETS )) == -1 )
49+ // サーバーのアドレス情報
50+ struct sockaddr_in server_addr;
51+ memset( (char *)&server_addr, 0, sizeof( server_addr ) );
52+ server_addr.sin_family = AF_INET;
53+ server_addr.sin_addr.s_addr = INADDR_ANY;
54+ server_addr.sin_port = htons( this->config->getPort() );
55+
56+ // ソケットとアドレスを紐付け
57+ if( (bind( s[0], (struct sockaddr *)&server_addr, sizeof( server_addr ) )) == -1 )
3958 {
40- perror( "listen" );
41- exit( 1 );
42- }
43- max = 1; /* s[0] is ready */
59+ // 紐付けに失敗したので死ぬ
60+ printf( "error; bind first socket\n" );
61+ return 0;
62+ }
4463
45- /* メインループ */
64+ // サーバーのソケットを接続待ち
65+ if( (listen( s[0], SOCK_MAX )) == -1 )
66+ {
67+ // 待受開始に失敗したので死ぬ
68+ printf( "error; listen first socket\n" );
69+ return 0;
70+ }
71+
72+ // 受信メッセージ用の文字列
73+ char str[1024];
74+
75+ // メインループ.無限ループ
4676 while( 1 )
4777 {
48- FD_ZERO( &readfds ); /* fdsの初期化 */
49- printf( "max: %d\n", max );
50- /*
51- * すでにクライアントと接続されているソケットのビットを
52- * セットしてselect()の検査対象にする。
53- */
54- for( i = 0; i < max; i++ )
78+ fd_set readfds;
79+ FD_ZERO( &readfds );
80+
81+ // 接続済みのクライアントのビットを立てる
82+ for( int i = 0; i < SOCK_MAX + 1; i++ )
5583 {
56- if( mSockets[i] != UNUSED )
57- {
58- FD_SET( mSockets[i], &readfds );
59- }
84+ if( s[i] <= 0 ) continue;
85+ FD_SET( s[i], &readfds );
6086 }
61- /*
62- * メッセージが到着しているソケットがないか調べる
63- */
87+
88+ // メッセージの到着をチェック
89+ int n;
6490 if( (n = select( FD_SETSIZE, &readfds, NULL, NULL, NULL )) == -1 )
6591 {
66- perror( "select" );
67- exit( 1 );
92+ printf( "error; select failed\n" );
93+ return 0;
6894 }
69- printf( "select returns: %d\n", n );
70- /*
71- * 1~maxのソケットに届くのは、すでに接続されているクライアントからの
72- * メッセージである。
73- * もしメッセージがあれば、接続されているすべてのクライアントに送る。
74- */
75- for( i = 1; i < max; i++ )
95+
96+ // 接続済みソケットからのメッセージをチェック
97+ for( int i = 1; i < SOCK_MAX + 1; i++ )
7698 {
77- if( mSockets[i] != UNUSED )
99+ // 接続済み?
100+ if( s[i] <= 0 ) continue;
101+ // メッセージ到着している?
102+ if( !FD_ISSET( s[i], &readfds ) ) continue;
103+
104+ strcpy( str, "" );
105+ int msg_length = read( s[i], str, sizeof( str ) );
106+ if( msg_length < 0 )
78107 {
79- if( FD_ISSET( mSockets[i], &readfds ) )
80- {
81- /*
82- * mSockets[i]のビットが立っていれば、mSockets[i]にメッセージが到着している
83- */
84- printf( "s[%d] ready for reading\n", i );
85- if( (msglen = read( mSockets[i], str, sizeof( str ) )) == -1 )
86- {
87- /* 受信失敗 */
88- perror("read");
89- }
90- else if ( msglen != 0 )
91- {
92- /* メッセージの受信に成功 */
93- printf( "client[%d]: %s", i, str );
94- //Modification(str,msglen); /* 作業 */
95- /* 接続されているクライアントすべてにメッセージを送る */
96- for( j = 1; j < max; j++ )
97- {
98- if( mSockets[j] != UNUSED )
99- {
100- write( mSockets[j], str, strlen( str ) );
101- }
102- }
103- }
104- else
105- {
106- printf( "client[%d]: connection closed.\n", i );
107- close( mSockets[i] );
108- mSockets[i] = UNUSED;
109- }
110- }
108+ // 受信に失敗
109+ printf( "warning; read failed from #%d\n", i );
111110 }
112- }
113- /*
114- * 新たな接続要求があった場合は、s[0]のビットが立つ。
115- * 以下では新たな接続の受け付けを行う。
116- */
117- if( FD_ISSET( mSockets[0], &readfds ) != 0 )
111+ else if( msg_length > 0 )
112+ {
113+ // 受信に成功
114+ string s_str = str;
115+ int indx = s_str.find( "\n" );
116+ if( indx > 0 ) s_str = s_str.substr( 0, indx );
117+ printf( "info; #%d said \"%s\"\n", i, s_str.c_str() );
118+ char msg[] = "[OK]";
119+ write( s[i], (char *)msg, strlen( msg ) );
120+ }
121+ else
122+ {
123+ // 接続が切られた
124+ printf( "info; %d disconnected\n", i );
125+ close( s[i] );
126+ s[i] = 0;
127+ }
128+ }
129+
130+ // 新しい接続がないかな
131+ if( FD_ISSET( s[0], &readfds ) != 0 )
118132 {
119- printf( "Accept New one.\n" );
120- /* 接続を確立する accept() */
121- len = sizeof( caddr );
122- mSockets[max] =
123- accept( mSockets[0], (struct sockaddr *)&caddr, &len );
124- printf( "%d = accept()\n", mSockets[max] );
125- if( mSockets[max] == -1 )
133+ printf( "info; new connection\n" );
134+
135+ struct sockaddr_in client_addr;
136+ socklen_t len = sizeof( client_addr );
137+
138+ // どれがあいてるかな
139+ int index = -1;
140+ for( int i = 1; i < SOCK_MAX + 1; i++ )
126141 {
127- perror( NULL );
128- exit( 1 );
142+ if( s[i] <= 0 )
143+ {
144+ index = i;
145+ break;
146+ }
129147 }
130- if( max < MAX_SOCKETS )
148+ if( index < 0 )
131149 {
132- printf( "client accepted(%d).\n", max );
133- max++;
150+ // 最大接続数をオーバーしてる
151+ printf( "warning: server too busy\n" );
134152 }
135153 else
136154 {
137- printf( "refuse connection.\n" );
138- strcpy( str, "Server is too busy.\n" );
139- write( mSockets[max], str, strlen( str ) );
140- close( mSockets[max] );
155+ s[index] = accept( s[0], (struct sockaddr *)&client_addr, &len );
156+ if( s[index] == -1 )
157+ {
158+ printf( "error; accept failed\n" );
159+ return 0;
160+ }
161+ else
162+ {
163+ printf( "info; #%d connection accepted\n", index );
164+ }
141165 }
142166 }
143167 }
144168 }
145-
169+
146170 void Server::analyze()
147171 {
148172 runtimeOptions opts;
--- vConnect/trunk/stand2.0/vcnctd/Server.h (revision 1635)
+++ vConnect/trunk/stand2.0/vcnctd/Server.h (revision 1636)
@@ -6,6 +6,10 @@
66 #ifndef __Server_h__
77 #define __Server_h__
88
9+#include <netinet/in.h>
10+#include <sys/socket.h>
11+#include <sys/types.h>
12+#include <sys/time.h>
913 #include <fcntl.h>
1014 #include <stdio.h>
1115 #include <string.h>
@@ -15,8 +19,8 @@
1519 #define MAX_SOCKETS 5 /* 最大ソケット数をここで決めた (最大32)*/
1620 #define UNUSED (-1)
1721
22+#include "../stand/vsqMetaText/Socket.h"
1823 #include "Config.h"
19-#include "Connection.h"
2024 #include "vcnctd.h"
2125
2226 using namespace vcnctd;
@@ -44,7 +48,7 @@
4448 /// <summary>
4549 /// ポートのLISTENを開始します.
4650 /// </summary>
47- void startListening();
51+ int startListening();
4852
4953 /// <summary>
5054 /// 未解析の音源について,解析を行います.
@@ -53,13 +57,8 @@
5357
5458
5559 public:
56-
60+
5761 /// <summary>
58- /// ソケット接続を管理するインスタンス.
59- /// </summary>
60- Connection *cons;
61-
62- /// <summary>
6362 /// 合成器のインスタンスです.
6463 /// </summary>
6564 Synth *synth;
@@ -77,6 +76,7 @@
7776 /// </summary>
7877 vector<CorpusManager *> mCorpusManagers;
7978
79+ int mMax;
8080 /// <summary>
8181 /// ソケットのリスト
8282 /// </summary>
--- vConnect/trunk/stand2.0/vcnctd/Makefile (revision 1635)
+++ vConnect/trunk/stand2.0/vcnctd/Makefile (revision 1636)
@@ -1,9 +1,9 @@
11 SRC=vcnctd.cpp \
2- Connection.cpp \
32 Server.cpp \
43 Config.cpp \
54 ConfDB.cpp \
65 daemon.c \
6+ ../stand/vsqMetaText/TextReader.cpp \
77 ../stand/corpusManager.cpp \
88 ../stand/matching.cpp \
99 ../stand/mb_text.cpp \
@@ -33,10 +33,10 @@
3333 ../stand/world/synthesis_v4.cpp
3434
3535 HDR=Server.h \
36- Connection.h \
3736 Config.h \
3837 daemon.h \
3938 ConfDB.h \
39+ ../stand/vsqMetaText/TextReader.h \
4040 ../stand/mb_text.h \
4141 ../stand/vConnect.h \
4242 ../stand/standData.h \
--- vConnect/trunk/stand2.0/stand/vsqMetaText/vsqFileEx.cpp (revision 1635)
+++ vConnect/trunk/stand2.0/stand/vsqMetaText/vsqFileEx.cpp (revision 1636)
@@ -26,6 +26,12 @@
2626 objectMap.insert( make_pair( temp, (vsqBase *)&voiceDataBase ) );
2727 }
2828
29+bool vsqFileEx::read( Socket socket, runtimeOptions options )
30+{
31+ MB_FILE *fp = mb_fopen( (int)socket, options.encodingVsqText.c_str() );
32+ return readCore( fp );
33+}
34+
2935 bool vsqFileEx::read( string_t file_name, runtimeOptions options )
3036 {
3137 #ifdef _DEBUG
@@ -44,75 +50,74 @@
4450 cout << "vsqFileEx::readVsqFile; (fp==NULL)=" << (fp == NULL ? "true" : "false") << endl;
4551 #endif
4652
47- if( fp )
53+ return readCore( fp );
54+}
55+
56+bool vsqFileEx::readCore( MB_FILE *fp )
57+{
58+ if( !fp ) return false;
59+
60+ string_t temp, search, left, right;
61+ map_t<string_t, vsqBase *>::iterator i;
62+
63+ while( mb_fgets( temp, fp ) )
4864 {
49- string_t temp, search, left, right;
50- map_t<string_t, vsqBase *>::iterator i;
51-
52- while( mb_fgets( temp, fp ) )
53- {
5465 #ifdef _DEBUG
55- string s;
56- mb_conv( temp, s );
57- cout << "vsqFileEx::readVsqFile; temp=" << s << endl;
66+ string s;
67+ mb_conv( temp, s );
68+ cout << "vsqFileEx::readVsqFile; temp=" << s << endl;
5869 #endif
59- if( temp.find( _T("[") ) == 0 )
70+ if( temp.find( _T("[") ) == 0 )
71+ {
72+ search = temp;
73+ continue;
74+ }
75+ string_t::size_type indx_equal = temp.find( _T("=") );
76+ if( indx_equal == string_t::npos )
77+ {
78+ left = temp;
79+ right = _T("");
80+ }
81+ else
82+ {
83+ left = temp.substr( 0, indx_equal );
84+ right = temp.substr( indx_equal + 1 );
85+ }
86+ i = objectMap.find( search );
87+ if( i != objectMap.end() )
88+ {
89+ if( i->second )
6090 {
61- search = temp;
62- continue;
63- }
64- string_t::size_type indx_equal = temp.find( _T("=") );
65- if( indx_equal == string_t::npos )
66- {
67- left = temp;
68- right = _T("");
69- }
70- else
71- {
72- left = temp.substr( 0, indx_equal );
73- right = temp.substr( indx_equal + 1 );
74- }
75- i = objectMap.find( search );
76- if( i != objectMap.end() )
77- {
78- if( i->second )
91+ if( search.compare( _T("[EventList]") ) == 0 )
7992 {
80- if( search.compare( _T("[EventList]") ) == 0 )
93+ string_t::size_type indx_comma = right.find( _T(",") );
94+ while( indx_comma != string_t::npos )
8195 {
82- string_t::size_type indx_comma = right.find( _T(",") );
83- while( indx_comma != string_t::npos )
84- {
85- // コンマが見つからなくなるまでループ
86- string_t tright = right.substr( 0, indx_comma );
87- i->second->setParameter( left, tright );
88- right = right.substr( indx_comma + 1 );
89- indx_comma = right.find( _T(",") );
90- }
96+ // コンマが見つからなくなるまでループ
97+ string_t tright = right.substr( 0, indx_comma );
98+ i->second->setParameter( left, tright );
99+ right = right.substr( indx_comma + 1 );
100+ indx_comma = right.find( _T(",") );
91101 }
92- i->second->setParameter( left, right );
93102 }
103+ i->second->setParameter( left, right );
94104 }
95- else
96- {
97- string message;
98- string t_search;
99- mb_conv( search, t_search );
100- message = "vsqFileEx::readVsqFile; not found: " + t_search;
101- outputError( message.c_str() );
102- }
103105 }
104- mb_fclose( fp );
106+ else
107+ {
108+ string message;
109+ string t_search;
110+ mb_conv( search, t_search );
111+ message = "vsqFileEx::readVsqFile; not found: " + t_search;
112+ outputError( message.c_str() );
113+ }
114+ }
115+ mb_fclose( fp );
105116
106- // utau音源が無ければ合成しようがないので false.
107- int size = UtauDB::dbSize();
108- result = (size > 0);
109- }
110-#ifdef _DEBUG
111- cout << "type any key to continue...";
112- int i;
113- scanf( "%d", &i );
114-#endif
115- return result;
117+ // utau音源が無ければ合成しようがないので false.
118+ int size = UtauDB::dbSize();
119+
120+ return (size > 0);
116121 }
117122
118123 double vsqFileEx::getEndSec()
--- vConnect/trunk/stand2.0/stand/vsqMetaText/TextReader.cpp (nonexistent)
+++ vConnect/trunk/stand2.0/stand/vsqMetaText/TextReader.cpp (revision 1636)
@@ -0,0 +1,66 @@
1+/**
2+ * TextReader.cpp
3+ *
4+ * Copyright (C) 2011 kbinani.
5+ */
6+#include "TextReader.h"
7+
8+TextReader::TextReader( MB_FILE *fp )
9+{
10+ this->mFile = fp;
11+ this->mSocket = 0;
12+}
13+
14+TextReader::TextReader( Socket socket )
15+{
16+ this->mFile = 0;
17+ this->mSocket = socket;
18+}
19+
20+TextReader::~TextReader()
21+{
22+ this->mFile = 0;
23+ this->mSocket = 0;
24+}
25+
26+int TextReader::getNextLine( string &buffer )
27+{
28+ buffer = "";
29+ if( 0 == mFile ) return -1;
30+ if( 0 == mSocket ) return -1;
31+ if( mFile )
32+ {
33+ if( mb_fgets( buffer, mFile ) )
34+ {
35+ return 0;
36+ }
37+ else
38+ {
39+ return -1;
40+ }
41+ }
42+ else
43+ {
44+ }
45+}
46+
47+int TextReader::getNextLine( wstring &buffer )
48+{
49+ buffer = L"";
50+ if( 0 == mFile ) return -1;
51+ if( 0 == mSocket ) return -1;
52+ if( mFile )
53+ {
54+ if( mb_fgets( buffer, mFile ) )
55+ {
56+ return 0;
57+ }
58+ else
59+ {
60+ return -1;
61+ }
62+ }
63+ else
64+ {
65+ }
66+}
--- vConnect/trunk/stand2.0/stand/vsqMetaText/vsqFileEx.h (revision 1635)
+++ vConnect/trunk/stand2.0/stand/vsqMetaText/vsqFileEx.h (revision 1636)
@@ -11,6 +11,7 @@
1111 #include "vsqTempo.h"
1212 #include "vsqPhonemeDB.h"
1313 #include "../runtimeOptions.h"
14+#include "Socket.h"
1415
1516 /// <summary>
1617 /// VSQメタテキストが表現するシーケンスを取り扱うクラスです.
@@ -24,7 +25,7 @@
2425 vsqFileEx();
2526
2627 /// <summary>
27- /// VSQのメタテキストを読み込みます.
28+ /// ファイルからVSQのメタテキストを読み込みます.
2829 /// </summary>
2930 /// <param name="file_name">読み込むメタテキストファイルのパス.</param>
3031 /// <param name="options">読み込み時の設定値.</param>
@@ -32,6 +33,14 @@
3233 bool read( string_t file_name, runtimeOptions options );
3334
3435 /// <summary>
36+ /// ソケットからVSQのメタテキストを読み込みます.
37+ /// </summary>
38+ /// <param name="socket">読み込むソケット.</param>
39+ /// <param name="options">読み込み時の設定値.</param>
40+ /// <returns>読み込みに成功した場合true,それ以外はfalseを返します.</returns>
41+ bool read( Socket socket, runtimeOptions options );
42+
43+ /// <summary>
3544 /// シーケンスの演奏長さを取得します.単位は秒です.
3645 /// </summary>
3746 /// <returns>シーケンスの演奏長さ.</returns>
@@ -62,6 +71,14 @@
6271 protected:
6372
6473 private:
74+
75+ /// <summary>
76+ /// VSQのメタテキストを読み込みます.
77+ /// </summary>
78+ /// <param name="fp">読み込むストリーム.</param>
79+ /// <returns>読み込みに成功した場合true,それ以外はfalseを返します.</returns>
80+ bool readCore( MB_FILE *fp );
81+
6582 vsqPhonemeDB voiceDataBase;
6683 };
6784
--- vConnect/trunk/stand2.0/stand/vsqMetaText/TextReader.h (nonexistent)
+++ vConnect/trunk/stand2.0/stand/vsqMetaText/TextReader.h (revision 1636)
@@ -0,0 +1,69 @@
1+/**
2+ * TextReader.h
3+ *
4+ * Copyright (C) 2011 kbinani.
5+ */
6+#ifndef __TextReader_h__
7+#define __TextReader_h__
8+
9+#include "../mb_text.h"
10+#include "Socket.h";
11+
12+/// <summary>
13+/// ファイルまたはウェブソケットから1行ずつデータを読み込む機能を提供します.
14+/// </summary>
15+class TextReader
16+{
17+public:
18+
19+ /// <summary>
20+ /// コンストラクタ.ファイルから読み込みます.
21+ /// </summary>
22+ /// <param name="fp">読み込むファイルのポインタ</param>
23+ TextReader( MB_FILE *fp );
24+
25+ /// <summary>
26+ /// コンストラクタ.ウェブソケットから読み込みます.
27+ /// </summary>
28+ /// <param name="socket">読み込むソケット接続</param>
29+ TextReader( Socket socket );
30+
31+ /// <summary>
32+ /// デストラクタ.ファイルやソケットのclose処理は行いません.
33+ /// </summary>
34+ ~TextReader();
35+
36+ /// <summary>
37+ /// 次の行を取得します.
38+ /// </summary>
39+ /// <param name="buffer">行データの格納先</param>
40+ /// <returns>読み込みに失敗した場合0,それ以外は0でない値を返します.</returns>
41+ int getNextLine( wstring &buffer );
42+
43+ /// <summary>
44+ /// 次の行を取得します.
45+ /// </summary>
46+ /// <param name="buffer">行データの格納先</param>
47+ /// <returns>読み込みに失敗した場合0,それ以外は0でない値を返します.</returns>
48+ int getNextLine( string &buffer );
49+
50+private:
51+
52+ TextReader();
53+
54+
55+private:
56+
57+ /// <summary>
58+ /// ファイルのポインタ.
59+ /// </summary>
60+ MB_FILE *mFile;
61+
62+ /// <summary>
63+ /// ソケット接続
64+ /// </summary>
65+ Socket mSocket;
66+
67+};
68+
69+#endif
--- vConnect/trunk/stand2.0/stand/vsqMetaText/Socket.h (nonexistent)
+++ vConnect/trunk/stand2.0/stand/vsqMetaText/Socket.h (revision 1636)
@@ -0,0 +1,11 @@
1+/**
2+ * Socket.h
3+ *
4+ * Copyright (C) 2011 kbinani.
5+ */
6+#ifndef __Socket_h__
7+#define __Socket_h__
8+
9+typedef int Socket;
10+
11+#endif
--- vConnect/trunk/stand2.0/stand/mb_text.h (revision 1635)
+++ vConnect/trunk/stand2.0/stand/mb_text.h (revision 1636)
@@ -95,6 +95,9 @@
9595 MB_CODEPAGE_DESCRIPTER descripter_for_char;
9696 FILE *file;
9797 int unit_len;
98+ int socket;
99+ // シークして戻る操作を行った時の,バッファとして保持しておく文字
100+ char *charbuf;
98101 } MB_FILE;
99102
100103 /**
@@ -137,11 +140,18 @@
137140 */
138141 MB_FILE *mb_fopen( wstring file_name, const char *codepage );
139142
143+/// <summary>
144+/// 指定したコードページを使って,ソケットを読み込む
145+/// </summary>
146+MB_FILE *mb_fopen( int socket, const char *codepage );
147+
140148 /**
141149 * ファイルを閉じる
142150 */
143151 int mb_fclose( MB_FILE *fp );
144152
153+
154+
145155 /**
146156 * 内部関数
147157 * マルチバイト文字列が、指定したコードの制御文字を表すかどうかを調べます
--- vConnect/trunk/stand2.0/stand/utauVoiceDB/UtauDB.cpp (revision 1635)
+++ vConnect/trunk/stand2.0/stand/utauVoiceDB/UtauDB.cpp (revision 1636)
@@ -37,7 +37,9 @@
3737 {
3838 for( unsigned int i = 0; i < UtauDB::mDBs.size(); i++ )
3939 {
40- SAFE_DELETE( UtauDB::mDBs[i] );
40+ UtauDB *db = UtauDB::mDBs[i];
41+ UtauDB::mDBs[i] = NULL;
42+ if( db ) delete db;
4143 }
4244 UtauDB::mDBs.clear();
4345 }
@@ -54,29 +56,29 @@
5456 }
5557 }
5658
59+// TODO: 読み込みが成功したとき0以外の値,失敗したとき0を返すように変更したい.
5760 int UtauDB::read( string_t path_oto_ini, const char *codepage )
5861 {
5962 int result = 2;
6063 MB_FILE *fp;
61- //char buf[LINEBUFF_LEN];
6264 string_t temp;
6365 int index;
6466 #ifdef _DEBUG
6567 string s2;
6668 mb_conv( fileName, s2 );
67- cout << "utauVoiceDataBase::readUtauVoiceDataBase; before normalize; path_oto_ini=" << s2 << endl;
69+ cout << "UtauDB::read; before normalize; path_oto_ini=" << s2 << endl;
6870 #endif
6971 normalize_path_separator( path_oto_ini );
7072 #ifdef _DEBUG
7173 string s;
7274 mb_conv( fileName, s );
73- cout << "utauVoiceDataBase::readUtauVoiceDataBase; after normalize; path_oto_ini=" << s << endl;
75+ cout << "UtauDB::read; after normalize; path_oto_ini=" << s << endl;
7476 #endif
7577
7678 fp = mb_fopen( path_oto_ini, codepage );
7779
7880 #ifdef _DEBUG
79- cout << "utauVoiceDataBase::readUtauVoiceDataBase; (fp==NULL)=" << (fp == NULL ? "true" : "false") << endl;
81+ cout << "UtauDB::read; (fp==NULL)=" << (fp == NULL ? "true" : "false") << endl;
8082 #endif
8183 if( fp )
8284 {
@@ -85,11 +87,11 @@
8587 while( mb_fgets( temp, fp ) )
8688 {
8789 #ifdef _DEBUG
88- string ts;
89- mb_conv( temp, ts );
90- //cout << "utauVoiceDataBase::readUtauVoiceDataBase; temp=" << ts << endl;
90+ string t_temp;
91+ mb_conv( temp, t_temp );
92+ cout << "UtauDB::read; t_temp=" << t_temp << endl;
9193 #endif
92- utauParameters* current = new utauParameters;
94+ utauParameters *current = new utauParameters;
9395 if( current )
9496 {
9597 if( ( index = temp.find( _T(".wav") ) ) == string_t::npos )
@@ -111,7 +113,8 @@
111113 else
112114 {
113115 current->lyric = temp.substr( temp.find( _T("=") ) + 1 );
114- current->lyric = current->lyric.substr( 0, current->lyric.find( _T(",") ) );
116+ current->lyric =
117+ current->lyric.substr( 0, current->lyric.find( _T(",") ) );
115118 }
116119
117120 string t;
@@ -160,7 +163,7 @@
160163
161164 int UtauDB::getParams( utauParameters &parameters, string_t search )
162165 {
163- int result = 0;
166+ int result = 0;
164167 map_t<string_t, utauParameters *>::iterator i = mSettingMap.find( search );
165168 if( i != mSettingMap.end() )
166169 {
--- vConnect/trunk/stand2.0/stand/utauVoiceDB/UtauDB.h (revision 1635)
+++ vConnect/trunk/stand2.0/stand/utauVoiceDB/UtauDB.h (revision 1636)
@@ -25,6 +25,7 @@
2525 /// </summary>
2626 /// <param name="path_oto_ini">oto.iniファイルのパス.</param>
2727 /// <param name="codepage">oto.iniファイルのテキスト・エンコーディング.</param>
28+ /// <returns>
2829 int read( string_t fileName, const char *codepage );
2930
3031 /// <summary>
@@ -48,8 +49,16 @@
4849 /// <returns>音素の数が0の場合trueを,そうでない場合はfalseを返します.</returns>
4950 bool empty();
5051
52+ /// <summary>
53+ /// 音素とパラメータの紐付けを格納したマップの反復子の先頭を返します.
54+ /// </summary>
55+ /// <returns>反復子の先頭.</returns>
5156 map_t<string_t, utauParameters *>::iterator begin();
52-
57+
58+ /// <summary>
59+ /// 音素とパラメータの紐付けを格納したマップの反復子の末尾を返します.
60+ /// </summary>
61+ /// <returns>反復子の末尾.</returns>
5362 map_t<string_t, utauParameters *>::iterator end();
5463
5564 public: // public static method
@@ -86,8 +95,14 @@
8695 /// </summary>
8796 string_t mDBPath;
8897
98+ /// <summary>
99+ /// 音素と音素のパラメータの紐付けを格納するマップ.
100+ /// </summary>
89101 map_t<string_t, utauParameters *> mSettingMap;
90102
103+ /// <summary>
104+ /// 音素のパラメータを格納したインスタンスのリスト.
105+ /// </summary>
91106 list<utauParameters *> mSettingList;
92107
93108
--- vConnect/trunk/stand2.0/stand/mb_text.cpp (revision 1635)
+++ vConnect/trunk/stand2.0/stand/mb_text.cpp (revision 1636)
@@ -271,37 +271,20 @@
271271 }
272272 }
273273
274-/**
275- * 指定したコードページを使って、読込み専用のテキストファイルを開く。
276- * MB_FILEから1行ずつ読み込むのは多重定義されたmb_fgetsを使うが、
277- * mb_fgets( wstring &line, MB_FILE *fp )のほうは指定したコードページで、
278- * mb_fgets( string &line, MB_FILE *fp )のほうはコードページを無視して読み込む。
279- *
280- * @param file_name ファイルの名前
281- * @param codepage コードページ
282- * @returns ファイル記述子
283- */
284-MB_FILE *mb_fopen( const char *file_name, const char *codepage ){
285- mb_init();
286- MB_FILE *fp = (MB_FILE *)malloc( sizeof( MB_FILE ) );
287-#ifdef __GNUC__
288- fp->file = fopen( file_name, "rb" );
289-#else
290- fopen_s( &(fp->file), file_name, "rb" );
291-#endif
292- if( !(fp->file) ){
293-#ifdef _DEBUG
294- cout << "::mb_fopen; fopen failed; file_name=" << file_name << endl;
295-#endif
296- free( fp );
297- return NULL;
298- }
274+/// <summary>
275+/// マルチバイト変換用のデスクリプタの初期化を行います.
276+/// </summary>
277+/// <param name="fp">初期化を行う対象となるファイルポインタ</param>
278+/// <param name="codepage">コードページの名前</param>
279+void mb_init_descriptor( MB_FILE *fp, const char *codepage )
280+{
299281 fp->unit_len = mb_unitlen_from_charset_name( codepage );
300282 if( fp->unit_len < 1 ){
301283 fp->unit_len = 1;
302284 }
285+ fp->charbuf = (char *)malloc( fp->unit_len * sizeof( char ) );
303286 #ifdef _DEBUG
304- cout << "::mb_fopen; fp->unit_len=" << fp->unit_len << endl;
287+ cout << "::mb_init_descriptor; fp->unit_len=" << fp->unit_len << endl;
305288 #endif
306289 #ifdef MB_USE_ICONV
307290 fp->descripter_for_wchar = iconv_open( mb_charset_wchar.c_str(), codepage );
@@ -309,19 +292,19 @@
309292 #else // MB_USE_ICONV
310293 fp->descripter_for_wchar = MB_INVALID;
311294 if( strcmp( codepage, "UTF-8" ) == 0 ||
312- strcmp( codepage, "UTF8" ) == 0 ){
295+ strcmp( codepage, "UTF8" ) == 0 ){
313296 fp->descripter_for_wchar = CP_UTF8;
314297 }else if( strcmp( codepage, "UTF-7" ) == 0 ||
315- strcmp( codepage, "UTF7" ) == 0 ){
298+ strcmp( codepage, "UTF7" ) == 0 ){
316299 fp->descripter_for_wchar = CP_UTF7;
317300 }else if( strcmp( codepage, "SJIS" ) == 0 ||
318- strcmp( codepage, "Shift_JIS" ) == 0 ){
301+ strcmp( codepage, "Shift_JIS" ) == 0 ){
319302 fp->descripter_for_wchar = 932;
320303 }else if( strcmp( codepage, "JIS" ) == 0 ||
321- strcmp( codepage, "ISO-2022-JP" ) == 0 ){
304+ strcmp( codepage, "ISO-2022-JP" ) == 0 ){
322305 fp->descripter_for_wchar = 50220;
323306 }else if( strcmp( codepage, "UTF-16" ) == 0 ||
324- strcmp( codepage, "UTF16" ) == 0 ){
307+ strcmp( codepage, "UTF16" ) == 0 ){
325308 fp->descripter_for_wchar = 1200;
326309 }else{
327310 fp->descripter_for_wchar = CP_ACP;
@@ -331,7 +314,50 @@
331314 }
332315 fp->descripter_for_char = fp->descripter_for_wchar;
333316 #endif // MB_USE_ICONV
317+}
334318
319+/// <summary>
320+/// 指定したコードページを使って,ソケットを読み込む
321+/// </summary>
322+MB_FILE *mb_fopen( int socket, const char *codepage )
323+{
324+ mb_init();
325+ MB_FILE *fp = (MB_FILE *)malloc( sizeof( MB_FILE ) );
326+ fp->file = 0;
327+ fp->socket = socket;
328+
329+ mb_init_descriptor( fp, codepage );
330+}
331+
332+/**
333+ * 指定したコードページを使って、読込み専用のテキストファイルを開く。
334+ * MB_FILEから1行ずつ読み込むのは多重定義されたmb_fgetsを使うが、
335+ * mb_fgets( wstring &line, MB_FILE *fp )のほうは指定したコードページで、
336+ * mb_fgets( string &line, MB_FILE *fp )のほうはコードページを無視して読み込む。
337+ *
338+ * @param file_name ファイルの名前
339+ * @param codepage コードページ
340+ * @returns ファイル記述子
341+ */
342+MB_FILE *mb_fopen( const char *file_name, const char *codepage ){
343+ mb_init();
344+ MB_FILE *fp = (MB_FILE *)malloc( sizeof( MB_FILE ) );
345+ fp->socket = 0;
346+#ifdef __GNUC__
347+ fp->file = fopen( file_name, "rb" );
348+#else
349+ fopen_s( &(fp->file), file_name, "rb" );
350+#endif
351+ if( !(fp->file) ){
352+#ifdef _DEBUG
353+ cout << "::mb_fopen; fopen failed; file_name=" << file_name << endl;
354+#endif
355+ free( fp );
356+ return NULL;
357+ }
358+
359+ mb_init_descriptor( fp, codepage );
360+
335361 // BOMがある場合は読み飛ばす
336362 unsigned int codepage_number = mb_codepage_from_charset_name( codepage );
337363 if( codepage_number == 1208 || codepage_number == 1209 ){
@@ -412,6 +438,12 @@
412438 if( fp->file ){
413439 ret = fclose( fp->file );
414440 }
441+
442+ if( fp->charbuf )
443+ {
444+ free( fp->charbuf );
445+ }
446+
415447 free( fp );
416448 return ret;
417449 }
@@ -513,40 +545,77 @@
513545 return mb_code_check( buf, len, 0x0A );
514546 }
515547
548+void mb_push_charbuf( MB_FILE *file, char *chars )
549+{
550+ for( int i = 0; i < file->unit_len; i++ )
551+ {
552+ // やばい
553+ file->charbuf[i] = chars[i];
554+ }
555+}
556+
516557 /**
517558 * ファイルから指定されたバイト数を読み込みます。
518559 * 読込の途中でEOFになった場合true、それ以外はfalseを返します
519560 */
520-int mb_fread( char *buf, int len, FILE *fp ){
561+int mb_fread( char *buf, int len, MB_FILE *src ){
521562 int ret = 0;
563+
564+ if( src->file )
565+ {
566+ FILE *fp = src->file;
522567 #ifdef _DEBUG
523- //cout << "::mb_fread; len=" << len << ";\"";
568+ //cout << "::mb_fread; len=" << len << ";\"";
524569 #endif
525- memset( buf, 0, len * sizeof( char ) );
526- for( int i = 0; i < len; i++ ){
527- int c = fgetc( fp );
528- if( c == EOF ){
529- return ret;
570+ memset( buf, 0, len * sizeof( char ) );
571+ int i = 0;
572+ if( src->charbuf[0] != EOF )
573+ {
574+ for( ;i < src->unit_len; i++ )
575+ {
576+ buf[i] = src->charbuf[i];
577+ src->charbuf[i] = EOF;
578+ }
579+ i = src->unit_len;
530580 }
531- buf[i] = (char)c;
532- ret++;
581+ for( ; i < len; i++ ){
582+ int c = fgetc( fp );
583+ if( c == EOF ){
584+ return ret;
585+ }
586+ buf[i] = (char)c;
587+ ret++;
533588 #ifdef _DEBUG
534- //cout << "c=" << c << ";";
535- //char pch[2];
536- //pch[0] = (char)c;
537- //pch[1] = 0;
538- //string s( pch );
539- //cout << s;
589+ //cout << "c=" << c << ";";
590+ //char pch[2];
591+ //pch[0] = (char)c;
592+ //pch[1] = 0;
593+ //string s( pch );
594+ //cout << s;
540595 #endif
541- }
596+ }
542597 #ifdef _DEBUG
543- //cout << "\"" << endl;
598+ //cout << "\"" << endl;
544599 #endif
600+ }
601+ else if( src->socket )
602+ {
603+ int socket = src->socket;
604+ int read_length = read( socket, buf, len );
605+ if( read_length < len )
606+ {
607+ ret = 1;
608+ }
609+ else
610+ {
611+ ret = 0;
612+ }
613+ }
545614 return ret;
546615 }
547616
548617 bool mb_fgets_core( char *buf, int buflen, MB_FILE *file ){
549- FILE *fp = file->file;
618+ //FILE *fp = file->file;
550619 int unit_buflen = file->unit_len;
551620 int unit_bufbytes = sizeof( char ) * unit_buflen;
552621 char *unit_buf = (char *)malloc( unit_bufbytes );
@@ -560,7 +629,7 @@
560629 int j;
561630
562631 // 1文字分読み込む
563- int len = mb_fread( unit_buf, unit_buflen, fp );
632+ int len = mb_fread( unit_buf, unit_buflen, file );
564633
565634 if( len != unit_buflen ){
566635 // EOFまで読んだ場合
@@ -579,13 +648,14 @@
579648 }else if( mb_is_cr( unit_buf, unit_buflen ) ){
580649 // 読んだのがCRだった場合
581650 // 次の文字がLFかどうかを調べる
582- len = mb_fread( unit_buf, unit_buflen, fp );
651+ len = mb_fread( unit_buf, unit_buflen, file );
583652 if( len == unit_buflen ){
584653 if( mb_is_lf( unit_buf, unit_buflen ) ){
585654 // LFのようだ
586655 }else{
587656 // LFでないので、ファイルポインタを戻す
588- fseek( fp, -unit_bufbytes, SEEK_CUR );
657+ mb_push_charbuf( file, unit_buf );
658+ //fseek( fp, -unit_bufbytes, SEEK_CUR );
589659 }
590660 }
591661 break;
@@ -592,7 +662,7 @@
592662 }else if( mb_is_lf( unit_buf, unit_buflen ) ){
593663 // 読んだのがLFだった場合
594664 // 次の文字がCRかどうかを調べる
595- len = mb_fread( unit_buf, unit_buflen, fp );
665+ len = mb_fread( unit_buf, unit_buflen, file );
596666 if( len == unit_buflen ){
597667 if( mb_is_cr( unit_buf, unit_buflen ) ){
598668 // CRのようだ
@@ -599,7 +669,8 @@
599669 // LF-CRという改行方法があるかどうかは知らないけれどサポートしとこう
600670 }else{
601671 // CRでないので、ファイルポインタを戻す
602- fseek( fp, -unit_bufbytes, SEEK_CUR );
672+ mb_push_charbuf( file, unit_buf );
673+ //fseek( fp, -unit_bufbytes, SEEK_CUR );
603674 }
604675 }
605676 break;
--- vConnect/trunk/stand2.0/stand/corpusManager.cpp (revision 1635)
+++ vConnect/trunk/stand2.0/stand/corpusManager.cpp (revision 1636)
@@ -21,7 +21,9 @@
2121 {
2222 string_t lyric = itr->first;
2323 this->getStandData( lyric, options );
24- cout << "corpusManager::analyze; lyric=" << lyric << endl;
24+ string str_lyric;
25+ mb_conv( lyric, str_lyric );
26+ cout << "corpusManager::analyze; lyric=" << str_lyric << endl;
2527 }
2628 }
2729
--- vConnect/trunk/stand2.0/Makefile (revision 1635)
+++ vConnect/trunk/stand2.0/Makefile (revision 1636)
@@ -2,11 +2,12 @@
22 ./stand/vConnect.cpp ./stand/vowelTable.cpp \
33 ./stand/mb_text.cpp ./stand/matching.cpp \
44 \
5- ./stand/utauVoiceDB/utauVoiceDataBase.cpp ./stand/utauVoiceDB/utauFreq.cpp \
5+ ./stand/utauVoiceDB/UtauDB.cpp ./stand/utauVoiceDB/utauFreq.cpp \
66 \
77 ./stand/vsqMetaText/vsqBase.cpp ./stand/vsqMetaText/vsqBPList.cpp \
88 ./stand/vsqMetaText/vsqEventEx.cpp ./stand/vsqMetaText/vsqEventList.cpp \
99 ./stand/vsqMetaText/vsqFileEx.cpp ./stand/vsqMetaText/vsqHandle.cpp \
10+ ./stand/vsqMetaText/TextReader.cpp \
1011 ./stand/vsqMetaText/vsqTempo.cpp \
1112 \
1213 ./stand/waveFileEx/waveFileEx.cpp \
旧リポジトリブラウザで表示