aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Native/Tango.Emulations.Native/PMR/Connection/ConnectRequest.pb-c.c
blob: 127b22ef3a4c820f7f9d89cd76a97e399040a78f (plain)
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
/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
/* Generated from: ConnectRequest.proto */

/* Do not generate deprecated warnings for self */
#ifndef PROTOBUF_C__NO_DEPRECATED
#define PROTOBUF_C__NO_DEPRECATED
#endif

#include "ConnectRequest.pb-c.h"
void   connect_request__init
                     (ConnectRequest         *message)
{
  static const ConnectRequest init_value = CONNECT_REQUEST__INIT;
  *message = init_value;
}
size_t connect_request__get_packed_size
                     (const ConnectRequest *message)
{
  assert(message->base.descriptor == &connect_request__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t connect_request__pack
                     (const ConnectRequest *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &connect_request__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t connect_request__pack_to_buffer
                     (const ConnectRequest *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &connect_request__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
ConnectRequest *
       connect_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (ConnectRequest *)
     protobuf_c_message_unpack (&connect_request__descriptor,
                                allocator, len, data);
}
void   connect_request__free_unpacked
                     (ConnectRequest *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &connect_request__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
static const ProtobufCFieldDescriptor connect_request__field_descriptors[1] =
{
  {
    "Password",
    1,
    PROTOBUF_C_LABEL_OPTIONAL,
    PROTOBUF_C_TYPE_STRING,
    0,   /* quantifier_offset */
    offsetof(ConnectRequest, password),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned connect_request__field_indices_by_name[] = {
  0,   /* field[0] = Password */
};
static const ProtobufCIntRange connect_request__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 1 }
};
const ProtobufCMessageDescriptor connect_request__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "ConnectRequest",
  "ConnectRequest",
  "ConnectRequest",
  "",
  sizeof(ConnectRequest),
  1,
  connect_request__field_descriptors,
  connect_request__field_indices_by_name,
  1,  connect_request__number_ranges,
  (ProtobufCMessageInit) connect_request__init,
  NULL,NULL,NULL    /* reserved[123] */
};
e Object _currentVM; private String _lastFullPath; private bool _preventHistory; private bool _navigating_back; private Stack<String> _navigationHistory; /// <summary> /// Gets the current view model. /// </summary> public StudioViewModel CurrentVM { get { return _currentVM as StudioViewModel; } } private IStudioModule _currentModule; /// <summary> /// Gets or sets the current module. /// </summary> public IStudioModule CurrentModule { get { return _currentModule; } private set { _currentModule = value; RaisePropertyChangedAuto(); } } /// <summary> /// Navigates to the previous view. /// </summary> public RelayCommand NavigateBackCommand { get; private set; } /// <summary> /// Navigates to the specified full path in command parameter. /// </summary> public RelayCommand<String> NavigateToCommand { get; private set; } /// <summary> /// Initializes a new instance of the <see cref="DefaultNavigationManager"/> class. /// </summary> /// <param name="moduleLoader">The module loader.</param> public DefaultNavigationManager(IStudioModuleLoader moduleLoader, IDispatcherProvider dispatcherProvider) { _navigationHistory = new Stack<String>(); _moduleLoader = moduleLoader; NavigateToCommand = new RelayCommand<string>(async (x) => await NavigateTo(x)); NavigateBackCommand = new RelayCommand(async () => await NavigateBack()); _dispatcherProvider = dispatcherProvider; } /// <summary> /// Navigates to the specified PPC view. /// </summary> /// <param name="view">The view.</param> public Task<bool> NavigateTo(NavigationView view, bool pushToHistory = true) { LogManager.Log($"Navigating to: {view.ToString()}..."); _dispatcherProvider.Invoke(() => { MainWindow.Instance.NavigationControl.NavigateTo(view.ToString()); }); return Task.FromResult(true); } /// <summary> /// Navigates to the specified PPC view with the specified receive object. /// </summary> /// <param name="view">The view.</param> /// <param name="obj"></param> /// <param name="pushToHistory"></param> /// <returns></returns> public Task<bool> NavigateWithObject<TPass>(NavigationView view, TPass obj, bool pushToHistory = true) { LogManager.Log($"Navigating to: {view.ToString()}, with object {typeof(TPass).Name}..."); MainWindow.Instance.NavigationControl.NavigateTo(view.ToString()); INavigationObjectReceiver<TPass> receiver = MainWindow.Instance.NavigationControl.Elements.FirstOrDefault(x => (x.GetType().Name == view.ToString() || NavigationControl.GetNavigationName(x) == view.ToString()) && x.DataContext is INavigationObjectReceiver<TPass>).DataContext as INavigationObjectReceiver<TPass>; if (receiver != null) { receiver.OnNavigatedToWithObject(obj); } return Task.FromResult(true); } /// <summary> /// Navigates to the specified module. /// </summary> /// <typeparam name="T"></typeparam> public Task<bool> NavigateTo<T>(bool pushToHistory = true) where T : IStudioModule { return NavigateTo(typeof(T)); } /// <summary> /// Navigates to the specified module using the view path (e.g MainView.JobsView). /// </summary> /// <typeparam name="T"></typeparam> /// <param name="viewPath">The view path.</param> public Task<bool> NavigateTo<T>(string viewPath, bool pushToHistory = true) where T : IStudioModule { return NavigateTo<T>(pushToHistory, viewPath.Split('.')); } /// <summary> /// Navigates to the specified module using the view path (e.g MainView,JobsView). /// This method makes it easy to do stuff like NavigateTo(nameof(MainView),nameof(JobsView)); /// </summary> /// <typeparam name="T"></typeparam> /// <param name="viewPath">The view path.</param> public Task<bool> NavigateTo<T>(bool pushToHistory = true, params String[] viewPath) where T : IStudioModule { return NavigateTo(typeof(T), pushToHistory, viewPath); } /// <summary> /// Navigates to the specified module and view by full path (e.g Jobs.JobsView). /// </summary> /// <param name="fullPath">The full path.</param> public async Task<bool> NavigateTo(String fullPath, bool pushToHistory = true) { String[] path = fullPath.Split('.'); var module = _moduleLoader.UserModules.SingleOrDefault(x => x.GetType().Name == path[0] || x.Name == path[0]); if (path.Length == 1 && path[0] == CurrentModule.Name) return true; LogManager.Log($"Navigating to: {fullPath}..."); var fromVM = _currentVM; if (_currentVM != null && _currentVM is INavigationBlocker) { if (_navigating_back) { if (!await (_currentVM as INavigationBlocker).OnNavigateBackRequest()) { return false; } } else { if (!await (_currentVM as INavigationBlocker).OnNavigateOutRequest()) { return false; } } } if (pushToHistory && _lastFullPath != null && !_preventHistory) { _navigationHistory.Push(_lastFullPath); RaisePropertyChanged(nameof(CanNavigateBack)); } _lastFullPath = fullPath; MainWindow.Instance.NavigationControl.NavigateTo(NavigationView.MainView.ToString()); var navigationControl = MachineStudio.UI.Views.MainView.Instance.NavigationControl; CurrentModule = module; var moduleView = navigationControl.NavigateTo(module.Name); _currentVM = moduleView.DataContext; if (path.Length > 1) { var moduleNavigation = moduleView.FindChildOffline<NavigationControl>(); moduleNavigation.RegisterForLoadedOrNow(async (x, e) => { foreach (var view in path.Skip(1)) { await Task.Delay(100); var v = moduleNavigation.NavigateTo(view); if (v != null) { _currentVM = v.DataContext; if (view != path.Last()) { moduleNavigation = v.FindChildOffline<NavigationControl>(); } } else { throw LogManager.Log(new ArgumentNullException("Could not navigate to " + fullPath)); } } NavigationCycleCompleted?.Invoke(fromVM, _currentVM); }); } return true; } /// <summary> /// Navigates for result. /// </summary> /// <typeparam name="TModule">The type of the module.</typeparam> /// <typeparam name="TView">The type of the view.</typeparam> /// <typeparam name="TResult">The type of the result.</typeparam> /// <typeparam name="TObject">The type of the object.</typeparam> /// <param name="obj">The object.</param> /// <param name="pushToHistory">if set to <c>true</c> [push to history].</param> /// <returns></returns> public Task<TResult> NavigateForResult<TModule, TView, TResult, TObject>(TObject obj, bool pushToHistory = true) where TModule : IStudioModule { TaskCompletionSource<TResult> source = new TaskCompletionSource<TResult>(); var fromVM = _currentVM; Object toVM = null; Action<Object, Object> handler = null; handler = (from, to) => { if (toVM == null) { toVM = to; if (toVM is INavigationResultProvider<TResult, TObject>) { (toVM as INavigationResultProvider<TResult, TObject>).OnNavigationObjectReceived(obj); } } else { if (to == fromVM && from == toVM) { if (from is INavigationResultProvider<TResult, TObject>) { source.SetResult((from as INavigationResultProvider<TResult, TObject>).GetNavigationResult()); } } NavigationCycleCompleted -= handler; } }; NavigationCycleCompleted += handler; NavigateTo<TModule>(typeof(TView).Name, pushToHistory); return source.Task; } /// <summary> /// Navigates to the specified module and view with the specified object. /// </summary> /// <typeparam name="TModule">The type of the module.</typeparam> /// <typeparam name="TView">The type of the view.</typeparam> /// <typeparam name="TPass">The type of the pass.</typeparam> /// <param name="obj">The object.</param> /// <param name="pushToHistory">if set to <c>true</c> [push to history].</param> /// <returns></returns> public Task<bool> NavigateWithObject<TModule, TView, TPass>(TPass obj, bool pushToHistory = true) where TModule : IStudioModule { TaskCompletionSource<bool> source = new TaskCompletionSource<bool>(); Action<Object, Object> handler = null; handler = (from, to) => { if (to is INavigationObjectReceiver<TPass>) { (to as INavigationObjectReceiver<TPass>).OnNavigatedToWithObject(obj); } NavigationCycleCompleted -= handler; }; NavigationCycleCompleted += handler; NavigateTo<TModule>(typeof(TView).Name, pushToHistory); return source.Task; } private Task<bool> NavigateTo(Type moduleType, bool pushToHistory = true, params String[] viewPath) { if (viewPath != null && viewPath.Length > 0) { return NavigateTo(moduleType.Name + "." + String.Join(".", viewPath), pushToHistory); } else { return NavigateTo(moduleType.Name, pushToHistory); } } /// <summary> /// Gets a value indicating whether the navigation system is able to navigate to the previous view. /// </summary> public bool CanNavigateBack { get { return _navigationHistory.Count > 0; } } /// <summary> /// Navigates to the previous view if <see cref="P:Tango.PPC.Common.Navigation.INavigationManager.CanNavigateBack" /> is true. /// </summary> public async Task<bool> NavigateBack() { LogManager.Log("Navigating back..."); _navigating_back = true; String first = _navigationHistory.Pop(); _preventHistory = true; if (await NavigateTo(first)) { RaisePropertyChanged(nameof(CanNavigateBack)); _preventHistory = false; _navigating_back = false; return true; } else { _navigationHistory.Push(first); _preventHistory = false; _navigating_back = false; RaisePropertyChanged(nameof(CanNavigateBack)); return false; } } /// <summary> /// Clears the navigation back history. /// </summary> public void ClearHistory() { LogManager.Log("Navigation history cleared."); _navigationHistory.Clear(); RaisePropertyChanged(nameof(CanNavigateBack)); } /// <summary> /// Clears the navigation back history except the specified view type. /// </summary> /// <typeparam name="T"></typeparam> public void ClearHistoryExcept<T>() { LogManager.Log($"Navigation history cleared except for {typeof(T).Name}."); var history_list = _navigationHistory.ToList(); history_list = history_list.Where(x => x.Contains(typeof(T).Name)).Distinct().ToList(); _navigationHistory.Clear(); foreach (var item in history_list) { _navigationHistory.Push(item); } RaisePropertyChanged(nameof(CanNavigateBack)); } public void NavigateToModule<T>() where T : IStudioModule { var loader = TangoIOC.Default.GetInstance<IStudioModuleLoader>(); var module = loader.UserModules.SingleOrDefault(x => x.GetType() == typeof(T)); if (module != null) { TangoIOC.Default.GetInstance<ViewModels.MainViewVM>().StartModule(module); } } } }