-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.cpp
145 lines (133 loc) · 2.93 KB
/
Test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "Test.h"
void Test::DummyWrite(int seqno, FILE* of)
{
Message msg;// = new Message();
msg.MesgType = 'A';
msg.Price = 23.23;
msg.SeqNo = seqno;
msg.Side = 'B';
strcpy(msg.Ticker, "ABC");
msg.Size = 2000;
fwrite(&msg, Globals::MessageLen, 1, of);
}
void Test::FileWrite(int seq)
{
FILE* of;
of = fopen("MessageFiles/InFile1.txt", "wb");
if (of == NULL) {
fprintf(stderr, "\nError to open the file.May be MeesageFiles directory not exist.\n");
exit(1);
}
Message msg;// = new Message();
msg.MesgType = 'A';
msg.Price = 23.23;
msg.SeqNo = 3;
msg.Side = 'B';
strcpy(msg.Ticker, "ABC");
msg.Size = 2000;
fwrite(&msg, Globals::MessageLen, 1, of);
Message msg2;// = new Message();
msg2.MesgType = 'B';
msg2.Price = 24.23;
msg2.SeqNo = 4;
msg2.Side = 'S';
strcpy(msg2.Ticker, "XYZ");
msg2.Size = 3000;
//int len = sizeof(Message);
fwrite(&msg2, Globals::MessageLen, 1, of);
DummyWrite(12, of);
DummyWrite(9, of);
DummyWrite(1, of);
DummyWrite(2, of);
DummyWrite(2, of);
if (fwrite != 0)
printf("contents to file written successfully !\n");
else
printf("error writing file !\n");
// close file
fclose(of);
}
void Test::FileWrite2(int seq)
{
FILE* of;
of = fopen("MessageFiles/InFile2.txt", "wb");
if (of == NULL) {
fprintf(stderr, "\nError to open the file\n");
exit(1);
}
Message msg;// = new Message();
msg.MesgType = 'A';
msg.Price = 23.23;
msg.SeqNo = 2;
msg.Side = 'B';
strcpy(msg.Ticker, "ABC");
msg.Size = 2000;
fwrite(&msg, Globals::MessageLen, 1, of);
Message msg2;// = new Message();
msg2.MesgType = 'B';
msg2.Price = 24.23;
msg2.SeqNo = 5;
msg2.Side = 'S';
strcpy(msg2.Ticker, "XYZ");
msg2.Size = 3000;
//int len = sizeof(Message);
fwrite(&msg2, Globals::MessageLen, 1, of);
DummyWrite(6, of);
DummyWrite(8, of);
DummyWrite(7, of);
DummyWrite(10, of);
DummyWrite(11, of);
if (fwrite != 0)
printf("contents to file written successfully !\n");
else
printf("error writing file !\n");
// close file
fclose(of);
}
void FileRead()
{
//cout << "File Reading Starts";
struct stat sb;
char* linkname;
ssize_t r;
/*string slist = path + "/" + dirlist[i];
cout << "Current processing file " << slist.c_str();*/
//Files Read Thread
FILE* inf;
struct Message inp;
inf = fopen("MessageFiles/Out.txt", "rb");
if (inf == NULL) {
fprintf(stderr, "\nError to open the file\n");
exit(1);
}
fseek(inf, 0, SEEK_SET);
while (!feof(inf))//
{
int readcount = fread(&inp, Globals::MessageLen, 1, inf);
printf("SeqNo:", inp.SeqNo);
//if (false)//
//{
//ProcessMesg(inp, false);
/*}
else
{*/
//Inserts in to queue
//ReadQueue.push(inp);
//}
//printf("roll_no = %d name = %s\n", inp.roll_no, inp.name);
}
fclose(inf);
}
void Test::Execute()
{
if (true)
{
FileRead();
}
else
{
FileWrite(0);
FileWrite2(0);
}
}
//};