This repository was archived by the owner on Oct 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.cpp
More file actions
937 lines (784 loc) · 32.5 KB
/
message.cpp
File metadata and controls
937 lines (784 loc) · 32.5 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
/*
* Copyright (c) 2019 Riccardo Zaccone, Ksenia Del Conte Akimova, Alice Morano, Martina Bellissimo
*
* This file is part of Symposium.
* Symposium is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Symposium is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Symposium. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* File: message.cpp
* Project: Symposium
* Authors:
* Riccardo Zaccone <riccardo.zaccone at studenti.polito.it>
* Ksenia Del Conte Akimova <s256669 at studenti.polito.it>
* Alice Morano <s259158 at studenti.polito.it>
* Martina Bellissimo <s257307 at studenti.polito.it>
*
* Created on 16 Giugno 2019, 12.39
*/
#include <string>
#include "filesystem.h"
#include "message.h"
#include "SymServer.h"
#include "SymClient.h"
#include "resourceType.h"
#include <boost/serialization/access.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/map.hpp>
using namespace Symposium;
uint_positive_cnt message::msgCounter;
message::message(uint_positive_cnt::type msgId){
if(msgId==0)
{
this->msgId=msgCounter;
msgCounter++;
}
else
this->msgId=msgId;
}
template<class Archive>
void message::serialize(Archive &ar, const unsigned int)
{
ar & msgId & action;
}
uint_positive_cnt::type message::getMsgId() const {
return msgId;
}
msgType message::getAction() const {
return action;
}
bool message::operator==(const message &rhs) const {
return msgId == rhs.msgId &&
action == rhs.action;
}
bool message::operator!=(const message &rhs) const {
return !(rhs == *this);
}
bool message::isFinalMex() const {
return action==msgType::logout || action==msgType::removeUser;
}
clientMessage::clientMessage(msgType action, const std::pair<std::string, std::string> &actionOwner, uint_positive_cnt::type msgId)
: message(msgId), actionOwner(actionOwner) {
if(action!=msgType::login && action!=msgType::removeUser && action!=msgType::logout)
throw messageException(messageException::action, UnpackFileLineFunction());
this->action=action;
}
clientMessage::clientMessage(const std::pair<std::string, std::string> &actionOwner, uint_positive_cnt::type msgId)
: message(msgId), actionOwner(actionOwner) {
}
template<class Archive>
void clientMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::message>(*this);
ar & actionOwner;
}
const std::pair<std::string, std::string> &clientMessage::getActionOwner() const {
return actionOwner;
}
void clientMessage::invokeMethod(SymServer &server) {
switch(action)
{
case msgType::login:{
user us= server.login(actionOwner.first, actionOwner.second, msgId);
break;
}
case msgType::removeUser:{
server.removeUser(actionOwner.first, actionOwner.second, msgId);
break;
}
case msgType::logout:{
server.logout(actionOwner.first, msgId);
break;
}
default:
break;
}
}
void clientMessage::completeAction(SymClient &client, msgOutcome serverResult) {
if(serverResult==msgOutcome::failure)
throw messageException(messageException::notSucc, UnpackFileLineFunction());
if(action==msgType::logout)
{
client.logout(true);
}
if(action==msgType::removeUser)
{
client.removeUser(true);
}
}
bool clientMessage::operator==(const clientMessage &rhs) const {
return static_cast<const message &>(*this) == static_cast<const message &>(rhs) &&
actionOwner == rhs.actionOwner;
}
bool clientMessage::operator!=(const clientMessage &rhs) const {
return !(rhs == *this);
}
clientMessage & clientMessage::clearAuthParam() {
actionOwner.first.clear();
actionOwner.second.clear();
return *this;
}
BOOST_CLASS_EXPORT(Symposium::clientMessage)
askResMessage::askResMessage(msgType action, const std::pair<std::string, std::string> &actionOwner,
const std::string &path,
const std::string &name, const std::string &resourceId, privilege accessMode, uint_positive_cnt::type msgId)
: message(msgId), clientMessage( actionOwner, msgId), path(path), name(name),
resourceId(resourceId), accessMode(accessMode) {
if(action!=msgType::createRes && action!= msgType::openRes && action!=msgType::openNewRes&& action!=msgType::changeResName
&& action!=msgType::createNewDir&& action!=msgType::removeRes)
throw messageException(messageException::action, UnpackFileLineFunction());
this->action=action;
}
template<class Archive>
void askResMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::clientMessage>(*this);
ar & path & name & resourceId & accessMode;
}
void askResMessage::invokeMethod(SymServer &server) {
switch(action)
{
case msgType::createRes:{
server.createNewSource(getActionOwner().first, path, name, msgId);
break;
}
case msgType::openRes:{
server.openSource(getActionOwner().first, path, name, accessMode, msgId);
break;
}
case msgType::openNewRes:{
server.openNewSource(getActionOwner().first, resourceId, path, name, accessMode, msgId);
break;
}
case msgType::changeResName:{
server.renameResource(getActionOwner().first, path, name, resourceId, msgId);
break;
}
case msgType::createNewDir:{
server.createNewDir(getActionOwner().first, path, name, msgId);
break;
}
case msgType::removeRes:{
server.removeResource(getActionOwner().first, path, name, msgId);
break;
}
default:
break;
}
}
bool askResMessage::operator==(const askResMessage &rhs) const {
return static_cast<const clientMessage &>(*this) == static_cast<const clientMessage &>(rhs) &&
path == rhs.path &&
name == rhs.name &&
resourceId == rhs.resourceId;
}
bool askResMessage::operator!=(const askResMessage &rhs) const {
return !(rhs == *this);
}
const std::string &askResMessage::getPath() const {
return path;
}
const std::string &askResMessage::getName() const {
return name;
}
const std::string &askResMessage::getResourceId() const {
return resourceId;
}
void askResMessage::completeAction(SymClient &client, msgOutcome serverResult) {
if(serverResult==msgOutcome::failure)
throw messageException(messageException::notSucc, UnpackFileLineFunction());
switch(action)
{
case msgType::changeResName:{
client.renameResource(path, name, resourceId, true);
break;
}
case msgType::removeRes:{
client.removeResource(path, name, true);
break;
}
default:
break;
}
}
BOOST_CLASS_EXPORT(Symposium::askResMessage)
signUpMessage::signUpMessage(msgType action, const std::pair<std::string, std::string> &actionOwner,
const user &newUser,
uint_positive_cnt::type msgId)
: message(msgId), clientMessage(actionOwner, msgId), newUser(newUser) {
if(action!=msgType::registration)
throw messageException(messageException::action, UnpackFileLineFunction());
this->action=action;
}
template<class Archive>
void signUpMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::clientMessage>(*this);
ar & newUser;
}
void signUpMessage::invokeMethod(SymServer &ss) {
ss.addUser(newUser, msgId);
}
const user &signUpMessage::getNewUser() const {
return newUser;
}
bool signUpMessage::operator==(const signUpMessage &rhs) const {
return static_cast<const Symposium::clientMessage &>(*this) == static_cast<const Symposium::clientMessage &>(rhs) &&
newUser == rhs.newUser;
}
bool signUpMessage::operator!=(const signUpMessage &rhs) const {
return !(rhs == *this);
}
BOOST_CLASS_EXPORT(Symposium::signUpMessage)
serverMessage::serverMessage(msgType action, msgOutcome result, uint_positive_cnt::type msgId) : message(msgId), result(result) {
this->action=action;
}
serverMessage::serverMessage(msgOutcome result, uint_positive_cnt::type msgId) : message(msgId), result(result) {
}
template<class Archive>
void serverMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::message>(*this);
ar & result & errDescr;
}
void serverMessage::invokeMethod(SymClient &client) {
auto mex=client.retrieveRelatedMessage(*this);
mex->completeAction(client, result);
}
bool serverMessage::isRelatedTo(const clientMessage &other) const {
return other.getMsgId() == this->msgId && other.getAction() == this->action;
}
msgOutcome serverMessage::getResult() const {
return result;
}
bool serverMessage::operator==(const serverMessage &rhs) const {
return static_cast<const Symposium::message &>(*this) == static_cast<const Symposium::message &>(rhs) &&
result == rhs.result;
}
bool serverMessage::operator!=(const serverMessage &rhs) const {
return !(rhs == *this);
}
const std::string &serverMessage::getErrDescr() const {
return errDescr;
}
void serverMessage::setErrDescr(const std::string &errDescr) {
serverMessage::errDescr = errDescr;
}
BOOST_CLASS_EXPORT(Symposium::serverMessage)
loginMessage::loginMessage(msgType action, msgOutcome result, const user &loggedUser, uint_positive_cnt::type msgId)
: message(msgId), serverMessage(result, msgId), loggedUser(loggedUser) {
if(action!=msgType::login && action!=msgType::registration)
throw messageException(messageException::action, UnpackFileLineFunction());
this->action=action;
}
template<class Archive>
void loginMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::serverMessage>(*this);
document::doLightSerializing([&](){
ar & loggedUser;
});
}
void loginMessage::invokeMethod(SymClient &client) {
auto msg= client.retrieveRelatedMessage(*this);
if(action==msgType::login)
client.logIn(loggedUser);
else
client.signUp(loggedUser);
}
bool loginMessage::operator==(const loginMessage &rhs) const {
return static_cast<const Symposium::serverMessage &>(*this) == static_cast<const Symposium::serverMessage &>(rhs) &&
loggedUser == rhs.loggedUser;
}
bool loginMessage::operator!=(const loginMessage &rhs) const {
return !(rhs == *this);
}
BOOST_CLASS_EXPORT(Symposium::loginMessage)
mapMessage::mapMessage(msgType action, msgOutcome result, const std::map<uint_positive_cnt::type, user> &siteIdToUser, uint_positive_cnt::type msgId)
: message(msgId), serverMessage(result, msgId), siteIdToUser(siteIdToUser) {
if(action!=msgType::mapChangesToUser)
throw messageException(messageException::action, UnpackFileLineFunction());
this->action=action;
}
template<class Archive>
void mapMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::serverMessage>(*this);
ar & siteIdToUser;
}
void mapMessage::invokeMethod(SymClient &client) {
auto msg= client.retrieveRelatedMessage(*this);
std::shared_ptr<updateDocMessage> mex2=std::dynamic_pointer_cast<updateDocMessage>(msg);
client.setUserColors(mex2->getResourceId(), siteIdToUser);
}
bool mapMessage::operator==(const mapMessage &rhs) const {
return static_cast<const Symposium::serverMessage &>(*this) == static_cast<const Symposium::serverMessage &>(rhs) &&
siteIdToUser == rhs.siteIdToUser;
}
bool mapMessage::operator!=(const mapMessage &rhs) const {
return !(rhs == *this);
}
BOOST_CLASS_EXPORT(Symposium::mapMessage)
sendResMessage::sendResMessage(msgType action, msgOutcome result, std::shared_ptr<filesystem> resource, uint_positive_cnt::type symId, uint_positive_cnt::type msgId)
: message(msgId), serverMessage(result, msgId), resource{resource} {
if(action!=msgType::createRes && action!=msgType::createNewDir && action!=msgType::openNewRes
&& action!=msgType::openRes)
throw messageException(messageException::action, UnpackFileLineFunction());
this->action=action;
if(symId!=0)
this->symId=symId;
}
template<class Archive>
void sendResMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
user::hideAuthParams([&](){
ar & boost::serialization::base_object<Symposium::serverMessage>(*this);
ar & symId & resource;
});
}
void sendResMessage::invokeMethod(SymClient &client) {
auto mex=client.retrieveRelatedMessage(*this);
std::shared_ptr <askResMessage> mex2=std::dynamic_pointer_cast<askResMessage>(mex);
switch(mex->getAction())
{
case msgType::createRes:{
std::shared_ptr <file> f= std::dynamic_pointer_cast<file>(resource);
client.createNewSource(mex2->getPath(), mex2->getName(), resource->getId(), f);
break;
}
case msgType::openRes:{
resourceType type=resource->resType();
if(type==resourceType::file)
{
std::shared_ptr <file> f= std::dynamic_pointer_cast<file>(resource);
client.openSource(mex2->getPath(), mex2->getName(), f,
resource->getUserPrivilege(mex2->getActionOwner().first));
}
break;
}
case msgType::openNewRes:{
resourceType type=resource->resType();
if(type==resourceType::file)
{
std::shared_ptr <file> f= std::dynamic_pointer_cast<file>(resource);
client.openNewSource(mex2->getResourceId(), resource->getUserPrivilege(mex2->getActionOwner().first),
mex2->getPath(), mex2->getName(), symId, f);
}
break;
}
case msgType::createNewDir:{
client.createNewDir(mex2->getPath(), mex2->getName(), resource->getId());
break;
}
default:
break;
}
}
BOOST_CLASS_EXPORT(Symposium::sendResMessage)
privMessage::privMessage(msgType action, const std::pair<std::string, std::string> &actionOwner, msgOutcome result,
const std::string &resourceId, const std::string &targetUser, privilege newPrivilege,
uint_positive_cnt::type msgId)
: message(msgId), clientMessage(actionOwner, msgId),
serverMessage(result, msgId), resourceId(resourceId), targetUser(targetUser), newPrivilege(newPrivilege) {
if(action!=msgType::changePrivileges)
throw messageException(messageException::action, UnpackFileLineFunction());
this->action=action;
}
template<class Archive>
void privMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::clientMessage>(*this);
ar & boost::serialization::base_object<Symposium::serverMessage>(*this);
ar & resourceId & targetUser & newPrivilege;
}
void privMessage::invokeMethod(SymServer &server) {
std::string path, id;
std::tie(path, id)=directory::separate(resourceId);
std::string completePath="./"+path;
server.editPrivilege(getActionOwner().first, targetUser, completePath, id, newPrivilege, msgId);
}
void privMessage::invokeMethod(SymClient &client) {
std::string path, id;
std::tie(path, id)=directory::separate(resourceId);
std::string completePath="./"+path;
client.editPrivilege(targetUser,completePath,id,newPrivilege,false);
}
void privMessage::completeAction(SymClient &client, msgOutcome serverResult) {
std::string path, id;
std::tie(path, id)=directory::separate(resourceId);
std::string completePath="./"+path;
if(serverResult==msgOutcome::success){
client.editPrivilege(targetUser,completePath,id,newPrivilege, true);
}
else
throw messageException(messageException::notSucc, UnpackFileLineFunction());
}
bool privMessage::operator==(const privMessage &rhs) const {
return static_cast<const Symposium::clientMessage &>(*this) == static_cast<const Symposium::clientMessage &>(rhs) &&
static_cast<const Symposium::serverMessage &>(*this) == static_cast<const Symposium::serverMessage &>(rhs) &&
resourceId == rhs.resourceId &&
targetUser == rhs.targetUser &&
newPrivilege == rhs.newPrivilege;
}
bool privMessage::operator!=(const privMessage &rhs) const {
return !(rhs == *this);
}
BOOST_CLASS_EXPORT(Symposium::privMessage)
symbolMessage::symbolMessage(msgType action, const std::pair<std::string, std::string> &actionOwner, msgOutcome result,
uint_positive_cnt::type siteId,
uint_positive_cnt::type resourceId, const symbol &sym, uint_positive_cnt::type msgId)
: message(msgId), clientMessage(actionOwner, msgId),
serverMessage(result, msgId), siteId(siteId), resourceId(resourceId), sym(sym) {
if(action!=msgType::insertSymbol && action!=msgType::removeSymbol)
throw messageException(messageException::action, UnpackFileLineFunction());
this->action=action;
}
template<class Archive>
void symbolMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::clientMessage>(*this);
ar & boost::serialization::base_object<Symposium::serverMessage>(*this);
ar & siteId & resourceId & sym;
}
uint_positive_cnt::type symbolMessage::getSiteId() const {
return siteId;
}
const symbol &symbolMessage::getSym() const {
return sym;
}
void symbolMessage::invokeMethod(SymServer &server) {
switch(action)
{
case msgType::insertSymbol:{
server.remoteInsert(getActionOwner().first,resourceId,*this);
break;
}
case msgType::removeSymbol:{
server.remoteRemove(getActionOwner().first,resourceId,*this);
break;
}
default:
break;
}
}
void symbolMessage::invokeMethod(SymClient &client) {
switch(action)
{
case msgType::insertSymbol:{
client.remoteInsert(siteId, resourceId, sym);
break;
}
case msgType::removeSymbol:{
client.remoteRemove(siteId, resourceId, sym);
break;
}
default:
break;
}
}
symbolMessage & symbolMessage::verifySym() {
sym.setVerified();
return *this;
}
void symbolMessage::completeAction(SymClient &client, msgOutcome serverResult) {
if(serverResult==msgOutcome::success){
if(action==msgType::insertSymbol)
client.verifySymbol(resourceId,sym);
}
else{
if(action==msgType::insertSymbol)
client.remoteRemove(siteId, resourceId, sym);
else if(action==msgType::removeSymbol)
client.remoteInsert(siteId, resourceId, sym);
else
throw messageException(messageException::notSucc, UnpackFileLineFunction());
}
}
bool symbolMessage::operator==(const symbolMessage &rhs) const {
return static_cast<const Symposium::clientMessage &>(*this) == static_cast<const Symposium::clientMessage &>(rhs) &&
static_cast<const Symposium::serverMessage &>(*this) == static_cast<const Symposium::serverMessage &>(rhs) &&
siteId == rhs.siteId &&
resourceId == rhs.resourceId &&
sym == rhs.sym;
}
bool symbolMessage::operator!=(const symbolMessage &rhs) const {
return !(rhs == *this);
}
BOOST_CLASS_EXPORT(Symposium::symbolMessage)
uriMessage::uriMessage(msgType action, const std::pair<std::string, std::string> &actionOwner, msgOutcome result,
const std::string &path, const std::string &name, const uri &sharingPrefs, uint_positive_cnt::type msgId)
: message(msgId), clientMessage(actionOwner, msgId),
serverMessage(result, msgId), sharingPrefs(sharingPrefs) {
if(action!=msgType::shareRes)
throw messageException(messageException::action, UnpackFileLineFunction());
this->action=action;
this->path=path;
this->name=name;
}
template<class Archive>
void uriMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::clientMessage>(*this);
ar & boost::serialization::base_object<Symposium::serverMessage>(*this);
ar & path & name & sharingPrefs;
}
const uri &uriMessage::getSharingPrefs() const {
return sharingPrefs;
}
void uriMessage::invokeMethod(SymServer &server) {
server.shareResource(getActionOwner().first, path, name, sharingPrefs, msgId);
}
void uriMessage::invokeMethod(SymClient &client) {
client.shareResource(getActionOwner().first, path, name, sharingPrefs, false);
}
void uriMessage::completeAction(SymClient &client, msgOutcome serverResult) {
if(serverResult==msgOutcome::success)
client.shareResource(getActionOwner().first, path, name, sharingPrefs, true);
else
throw messageException(messageException::notSucc, UnpackFileLineFunction());
}
bool uriMessage::operator==(const uriMessage &rhs) const {
return static_cast<const Symposium::clientMessage &>(*this) == static_cast<const Symposium::clientMessage &>(rhs) &&
static_cast<const Symposium::serverMessage &>(*this) == static_cast<const Symposium::serverMessage &>(rhs) &&
path == rhs.path &&
name == rhs.name &&
sharingPrefs == rhs.sharingPrefs;
}
bool uriMessage::operator!=(const uriMessage &rhs) const {
return !(rhs == *this);
}
BOOST_CLASS_EXPORT(Symposium::uriMessage)
updateActiveMessage::updateActiveMessage(msgType action, msgOutcome result, const user &newUser, uint_positive_cnt::type resourceId,
privilege priv,
uint_positive_cnt::type msgId)
: message(msgId), serverMessage(result, msgId),
newUser(newUser), resourceId(resourceId), userPrivilege(priv) {
this->action=action;
if(action!=msgType::addActiveUser && action!=msgType::removeActiveUser)
throw messageException(messageException::action, UnpackFileLineFunction());
}
template<class Archive>
void updateActiveMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::serverMessage>(*this);
// just to be sure that no document's content is serialized.
// newUser.home should be null in this kind of message
document::doLightSerializing([&](){
ar & newUser & resourceId & userPrivilege;
});
}
int updateActiveMessage::getResourceId() const {
return resourceId;
}
privilege updateActiveMessage::getUserPrivilege() const {
return userPrivilege;
}
void updateActiveMessage::invokeMethod(SymClient &client) {
switch(action)
{
case msgType::addActiveUser:{
client.addActiveUser(resourceId,newUser,userPrivilege);
break;
}
case msgType::removeActiveUser:{
client.removeActiveUser(resourceId,newUser);
break;
}
default:
break;
}
}
bool updateActiveMessage::operator==(const updateActiveMessage &rhs) const {
return static_cast<const Symposium::serverMessage &>(*this) == static_cast<const Symposium::serverMessage &>(rhs) &&
newUser == rhs.newUser &&
resourceId == rhs.resourceId &&
userPrivilege == rhs.userPrivilege;
}
bool updateActiveMessage::operator!=(const updateActiveMessage &rhs) const {
return !(rhs == *this);
}
BOOST_CLASS_EXPORT(Symposium::updateActiveMessage)
updateDocMessage::updateDocMessage(msgType action, const std::pair<std::string, std::string> &actionOwner,
uint_positive_cnt::type resourceId, uint_positive_cnt::type msgId)
: message(msgId), clientMessage(actionOwner, msgId),
resourceId(resourceId) {
if(action!=msgType::mapChangesToUser && action!=msgType::closeRes)
throw messageException(messageException::action, UnpackFileLineFunction());
this->action=action;
}
template<class Archive>
void updateDocMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::clientMessage>(*this);
ar & resourceId;
}
uint_positive_cnt::type updateDocMessage::getResourceId() const {
return resourceId;
}
void updateDocMessage::invokeMethod(SymServer &server) {
switch(action)
{
case msgType::closeRes:{
server.closeSource(getActionOwner().first, resourceId, msgId);
break;
}
case msgType::mapChangesToUser:{
server.mapSiteIdToUser(getActionOwner().first, resourceId, msgId);
break;
}
default:
break;
}
}
bool updateDocMessage::operator==(const updateDocMessage &rhs) const {
return static_cast<const Symposium::clientMessage &>(*this) == static_cast<const Symposium::clientMessage &>(rhs) &&
resourceId == rhs.resourceId;
}
bool updateDocMessage::operator!=(const updateDocMessage &rhs) const {
return !(rhs == *this);
}
BOOST_CLASS_EXPORT(Symposium::updateDocMessage)
userDataMessage::userDataMessage(msgType action, const std::pair<std::string, std::string> &actionOwner,
msgOutcome result,
const user &newUserData, uint_positive_cnt::type msgId)
: message(msgId), clientMessage(actionOwner, msgId),
serverMessage(action, result, msgId), newUserData(newUserData) {
if(action!=msgType::changeUserData && action !=msgType::changeUserPwd)
throw messageException(messageException::action, UnpackFileLineFunction());
}
template<class Archive>
void userDataMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::clientMessage>(*this);
ar & boost::serialization::base_object<Symposium::serverMessage>(*this);
ar & newUserData;
}
void userDataMessage::invokeMethod(SymServer &server) {
server.editUser(getActionOwner().first, newUserData, msgId);
}
void userDataMessage::invokeMethod(SymClient &client) {
client.editUser(newUserData, false);
}
void userDataMessage::completeAction(SymClient &client, msgOutcome serverResult) {
if(serverResult==msgOutcome::failure)
throw messageException(messageException::notSucc, UnpackFileLineFunction());
client.editUser(newUserData, true);
}
bool userDataMessage::operator==(const userDataMessage &rhs) const {
return static_cast<const Symposium::clientMessage &>(*this) == static_cast<const Symposium::clientMessage &>(rhs) &&
static_cast<const Symposium::serverMessage &>(*this) == static_cast<const Symposium::serverMessage &>(rhs) &&
newUserData == rhs.newUserData;
}
bool userDataMessage::operator!=(const userDataMessage &rhs) const {
return !(rhs == *this);
}
BOOST_CLASS_EXPORT(Symposium::userDataMessage)
cursorMessage::cursorMessage(msgType action, const std::pair<std::string, std::string> &actionOwner, msgOutcome result,
uint_positive_cnt::type siteId,
uint_positive_cnt::type resourceId, unsigned int row, unsigned int col, uint_positive_cnt::type msgId) : message(msgId), clientMessage(actionOwner, msgId),
serverMessage(result, msgId), siteId(siteId),
resourceId(resourceId), row(row), col(col){
if(action!=msgType::updateCursor)
throw messageException(messageException::action, UnpackFileLineFunction());
this->action=action;
}
template<class Archive>
void cursorMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::clientMessage>(*this);
ar & boost::serialization::base_object<Symposium::serverMessage>(*this);
ar & siteId & resourceId & row & col;
}
void cursorMessage::invokeMethod(SymServer &server) {
server.updateCursorPos(getActionOwner().first, resourceId, *this);
}
void cursorMessage::invokeMethod(SymClient &client) {
client.updateCursorPos(siteId, resourceId, row, col);
}
bool cursorMessage::operator==(const cursorMessage &rhs) const {
return static_cast<const Symposium::clientMessage &>(*this) == static_cast<const Symposium::clientMessage &>(rhs) &&
static_cast<const Symposium::serverMessage &>(*this) == static_cast<const Symposium::serverMessage &>(rhs) &&
siteId == rhs.siteId &&
resourceId == rhs.resourceId &&
row == rhs.row &&
col == rhs.col;
}
bool cursorMessage::operator!=(const cursorMessage &rhs) const {
return !(rhs == *this);
}
unsigned int cursorMessage::getRow() const {
return row;
}
unsigned int cursorMessage::getCol() const {
return col;
}
BOOST_CLASS_EXPORT(Symposium::cursorMessage)
editLineStyleMessage::editLineStyleMessage(msgType action, const std::pair<std::string, std::string> &actionOwner,
msgOutcome result, const std::pair<alignType, unsigned int>& oldLineStyle,
const std::pair<alignType, unsigned int>& newLineStyle, uint_positive_cnt::type docId,
unsigned row, uint_positive_cnt::type msgId) :
message(msgId), clientMessage(actionOwner, msgId),
serverMessage(result, msgId), oldLineStyle(oldLineStyle), newLineStyle(newLineStyle),
row(row), docId(docId)
{
if(action!=msgType::editLineStyle)
throw messageException(messageException::action, UnpackFileLineFunction());
this->action=action;
}
template<class Archive>
void editLineStyleMessage::serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::clientMessage>(*this);
ar & boost::serialization::base_object<Symposium::serverMessage>(*this);
ar & oldLineStyle & newLineStyle & row & docId & row;
}
BOOST_CLASS_EXPORT(Symposium::editLineStyleMessage)
void editLineStyleMessage::invokeMethod(SymServer &server) {
server.editLineStyle(getActionOwner().first, docId, newLineStyle, row, *this);
}
void editLineStyleMessage::invokeMethod(SymClient &client) {
client.remoteEditLineStyle(docId, newLineStyle, row);
}
void editLineStyleMessage::completeAction(SymClient &client, msgOutcome serverResult) {
if(serverResult==msgOutcome::failure)
client.remoteEditLineStyle(docId, oldLineStyle, row);
}
bool editLineStyleMessage::operator==(const editLineStyleMessage &rhs) const {
return static_cast<const Symposium::clientMessage &>(*this) == static_cast<const Symposium::clientMessage &>(rhs) &&
static_cast<const Symposium::serverMessage &>(*this) == static_cast<const Symposium::serverMessage &>(rhs) &&
oldLineStyle == rhs.oldLineStyle &&
newLineStyle == rhs.newLineStyle &&
docId == rhs.docId &&
row == rhs.row;
}
bool editLineStyleMessage::operator!=(const editLineStyleMessage &rhs) const {
return !(rhs == *this);
}